# Xn

## Create an API user and application

You will need an API user and an application in Xn. Reach out to your Xn rep. on how to do this.

## Connecting in Middle

### Create an API Key entry

You will need to enter the information from the new application that was just created as an API key entry in Middle. More information on Middle API Keys [can be found in this article](https://docs.middle.app/middle-docs/middle-accounts/credential-storage).

Follow these steps to set up a new API key for Xn in Middle:

1. Go to **Apps** in Middle
2. Go to the [Xn Leisure Hub](https://abcfitness.middle.app/app/4/) app
3. Click **API Keys** in the left-hand menu
4. Click to **Add API key**
5. Name the key and add whatever description you'd like
6. An API application will need to be created for each of your Xn customers. Because of this, you'll probably want to leave **Is default?** toggled off.
7. For the **Payload** you will need to get the following information from the Xn app that was created and enter it in JSON format (see below)
8. Toggle on **Use allowed accounts?**
9. Under **Allowed Accounts** search for the customer's account in Middle and select it
10. Click **Save**

```json
{
    "client_id": "info_goes_here",
    "client_secret": "info_goes_here",
    "username": "info_goes_here",
    "password": "info_goes_here",
    "redirect_url": "info_goes_here"
}
```

### Connecting Xn

1. Go to the customer account you are trying to authenticate and add a new Xn Leisure Hub app connection
2. Name the connection after the customer
3. Leave **\[Debug Display Only] Timestamp** blank
4. Click **Save**
5. Enter the API user credentials created in Xn
6. Click **Submit**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.middle.app/middle-docs/guides/app-reference/xn.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
