# Xero Connection Configuration

When you first enter Client Management Settings, you will be prompted with the following error message, which states that there are no credentials named ‘Maica\_Xero’

<figure><img src="/files/IPTtTv3sKkhIGO8b3Ar7" alt=""><figcaption><p>Error Message</p></figcaption></figure>

At the bottom of the page, you will see an ‘Edit’ button. Click on this, followed by ‘Add New Connection’, which is under the Active Connections subheading. After you press this button, you will be taken to the Named Credentials page.

## Named Credentials&#x20;

You must now create a credential.&#x20;

| Field                   | Value                                                                                                                          |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| Label                   | Maica Xero                                                                                                                     |
| Name                    | Maica\_Xero                                                                                                                    |
| URL                     | [https://api.xero.com](<https://api.xero.com. >)                                                                               |
| Identity Type           | Named Principal                                                                                                                |
| Authentication Protocol | OAuth 2.0                                                                                                                      |
| Authentication Provider | [See Salesforce Auth Provider](#salesforce-auth-provider)                                                                      |
| Scope                   | `offline_access openid profile email accounting.transactions accounting.contacts accounting.journals.read accounting.settings` |

You can untick the checkbox titled 'Start Authentication Flow on Save' and you can save, once all the fields above are completed. After you have saved, return to Client Management Settings. You should now see the following error message

<figure><img src="/files/ku7SoDY6NMsXPBMKqOC4" alt=""><figcaption><p>Second Error Message</p></figcaption></figure>

## Updating Client Management Settings

In Client Management Settings, click Edit and enable Xero Management in the top-right corner. Then, select the following options.&#x20;

<figure><img src="/files/g3L9zWwyJkS75JP1y0fz" alt=""><figcaption><p>Updated Client Management Settings</p></figcaption></figure>

Note: You may need to activate Xero Invoice Sync Flow, and Webhooks will not be available unless you have already created and activated the site.

## Salesforce Auth Provider

Next, we need to create the Authentication Provider. In the top left of the screen, you will see a Quick Find search option. Search ‘auth’ and select the Auth. Providers option. Make sure you right click and open link in new tab, so you do not lose your current page.

<figure><img src="/files/CyvCo0E41rCM7T01LVxY" alt=""><figcaption><p>Quick Find</p></figcaption></figure>

A `Salesforce Auth Provider` to set up the technical connection to the `Xero` financial system, as shown below:

<figure><img src="/files/lYyw8jo2M42JSvvN6Upf" alt=""><figcaption><p>Salesforce Auth Provider</p></figcaption></figure>

The following values apply when configuring the `Salesforce Auth Provider`:

<table><thead><tr><th width="308">Field</th><th width="451">Value</th></tr></thead><tbody><tr><td>Auth Provider Id</td><td>Salesforce generated</td></tr><tr><td>Provider Type</td><td><code>Open ID Connect</code></td></tr><tr><td>Name</td><td><code>Xero</code></td></tr><tr><td>URL Suffix</td><td><code>Xero</code></td></tr><tr><td>Consumer Key</td><td><a href="#get-values-from-your-xero-instance">Get from your Xero Instance</a></td></tr><tr><td>Consumer Secret</td><td><a href="#get-values-from-your-xero-instance">Get from your Xero Instance</a></td></tr><tr><td>Authorize Endpoint URL</td><td><a href="https://login.xero.com/identity/connect/authorize">https://login.xero.com/identity/connect/authorize</a></td></tr><tr><td>Token Endpoint URL</td><td><a href="https://dentity.xero.com/connect/loken">https://identity.xero.com/connect/token</a></td></tr><tr><td>Use Proof Key for Code Exchange</td><td>Ticked</td></tr><tr><td>Default Scope</td><td><code>offline_access openid profile email accounting transactions accounting. contacts accountingjournals.read accounting.settings</code></td></tr><tr><td>Send Access Token in Header</td><td>Ticked</td></tr><tr><td>Include Consumer Secret in...</td><td>Ticked</td></tr><tr><td>Test-Only Initialization URL</td><td><a href="#get-values-from-your-xero-instance">Get from your Xero Instance</a></td></tr><tr><td>OAuth-Only Initialization URL</td><td><a href="#get-values-from-your-xero-instance">Get from your Xero Instance</a></td></tr><tr><td>Callback URL</td><td><a href="#get-values-from-your-xero-instance">Get from your Xero Instance</a></td></tr><tr><td>Single Logon URL</td><td><a href="#get-values-from-your-xero-instance">Get from your Xero Instance</a></td></tr></tbody></table>

### Get Values from your Xero Instance

In order to complete `Salesforce Auth Provider` configuration, you need to log into your Xero instance to retrieve the values marked above. These can be found within the following sections:

#### Consumer Key and Consumer Secret

To access the consumer key and consumer secret, you will need to log into [developer.xero.com](https://developer.xero.com) using your credentials and follow the below steps:

* [ ] [Create a Xero Web App](#creating-a-xero-web-app) (only do this once)
* [ ] Open your App and click on `Configuration` on the left-hand side
* [ ] Generate the `Client Key` and `Client Secret`
* [ ] Copy and Paste this into your `Salesforce Auth Provider`

<figure><img src="/files/f3SmNm8UhcBT4Z2rgpJs" alt=""><figcaption><p>Xero App Details</p></figcaption></figure>

Now, you can return to [Named Credentials](#named-credentials) and select your newly created Authentication Provider.

#### Initialization URLs

## Creating a Xero Web App

First, login to Xero using the link <https://login.xero.com/>. Next, you need to go to App Management in the developer website, which can be found using the link <https://developer.xero.com/app/manage>. The account should be the same one that you have used to login previously.&#x20;

Create a new app, with Company URL <https://api.xero.com/api.xro/2.0/>. The redirect URL can be [configured later](#configuring-the-redirect-url), but for now use a dummy URL such as <http://localhost:8000>.

<figure><img src="/files/jsiGZp0dfNnLrhTkOfLC" alt="" width="299"><figcaption><p>Creating an App</p></figcaption></figure>

Now, you can go to Configuration and copy the Client ID and Client Secret, which are the Consumer Key and Consumer Secret respectively.

## Creating a Site

Go to the Sites section in Setup. You can find this using the Quick Find in the top-left corner. Now, create a new site. Note: you may need to check the following box to accept the terms and conditions

<figure><img src="/files/2RASK9KBJOeBVqnVWW6T" alt=""><figcaption><p>Checkbox to Accept Terms and Conditions</p></figcaption></figure>

The following values apply when configuring the `site.`

| Field                 | Value                |
| --------------------- | -------------------- |
| Site Label            | Webhooks             |
| Site Name             | Webhooks             |
| Site Contact          | *Generic*            |
| Default Record Owner  | *Generic*            |
| Active Site Home Page | ParticipantStatement |

<figure><img src="/files/PSC443Vvi74omIbGGSU6" alt=""><figcaption><p>Creating a Site</p></figcaption></figure>

After saving, ensure that you activate the site. Now, return to [Client Management Settings](#updating-client-management-settings).

## Configuring the Redirect URL

The Redirect URL is the Callback URL from the Auth. Provider, as shown below.

<figure><img src="/files/gRvhRuylevfbRftzL786" alt=""><figcaption><p>Callback URL, which is required for the Redirect URL</p></figcaption></figure>

## Enabling Authentication Flow

Return to your Named Credential and edit. Now, you can select the 'Start Authentication Flow on Save' box and click Save. You should be redirected to Xero, where you will be prompted with the following screen.

<figure><img src="/files/EtWY9irMAAP9hWerm7dA" alt=""><figcaption><p>Xero Prompt</p></figcaption></figure>

Allow access. You will be brought back to the Named Crediential and will notice that the Authentication Status is now Authenticated. Now, in Client Management Settings, we can setup Webhooks.

## Configuring Webhooks

Your Client Management Settings page should look like this

<figure><img src="/files/j7onxk98bnMt1oGoHA5p" alt=""><figcaption><p>Client Management Settings</p></figcaption></figure>

Edit, and enable Xero Management. Select the Tenant 'Active' checkbox. Finally, make sure Webhooks is selected as Notifications Endpoint (Site) and Xero Invoice Sync Flow is selected for Syncronisation, as shown in the photo above.

Now, we need to populate the Webhooks Key and set up the URL. This is done from the Xero site.

<figure><img src="/files/3cdLKL4wW7JfmJN694fN" alt=""><figcaption><p>Webhooks Key and URL</p></figcaption></figure>

Go to your App, then under Webhooks, complete the options as shown below. The URL comes from the URL under Webhooks in Client Management Settings, which is shown above.

<figure><img src="/files/juYs8cdPUt7JxHqRgc6S" alt=""><figcaption><p>Webhooks Settings in App</p></figcaption></figure>

When you save, you will be given a Webhooks key which can be copy and pasted into Client Management Settings. Now, you can save the settings and you should be prompted with the following message.

<figure><img src="/files/BOLWVEvy5PHpu5QBOCYI" alt=""><figcaption><p>Success Prompt</p></figcaption></figure>

## Site Settings

Now, double check the following settings in Salesforce. First, go to Sites and click on the Site Label Webhooks. This will take you to a page where you will see a button named Public Access Settings. Now, click on Apex Class Access, edit and ensure that `maica.vertic_RestService` is enabled. Then, search for REST in the Find Settings searchbar and select Apex Rest Services. Make sure that the checkbox `Apex REST Services` is enabled.

<figure><img src="/files/uzL4h6bnDZkfloKiRHxB" alt=""><figcaption><p>Rest Service</p></figcaption></figure>

<figure><img src="/files/CSTeO5QQ5S0fZTISHjtl" alt=""><figcaption><p>Apex REST Services</p></figcaption></figure>

Back in Xero, click the following button after you have saved the settings in Salesforce.&#x20;

<figure><img src="/files/8xkiRKDY6HyQWbEp05Gk" alt=""><figcaption><p>Intent to Receive Buttom in Xero</p></figcaption></figure>

<figure><img src="/files/g859jpsL0P7cEq1zA0K0" alt=""><figcaption><p>Sucessful Intent to Receive</p></figcaption></figure>

## Invoices

Go to [https://go.xero.com](https://go.xero.com/), which will take you to a dashboard. Under Business - Invoices, you will see the invoices.&#x20;

In the top right, you will see an option to Sync with Xero. Note: it may be in the drop down menu

<figure><img src="/files/K3mg4IC0gJc1ZMmpg7DK" alt=""><figcaption><p>Sync Confirmation Message</p></figcaption></figure>

Please click confirm to initiate the Sync

<figure><img src="/files/Rb2I7SsPStfpbDkzX8tB" alt=""><figcaption><p>Sync Success Message</p></figcaption></figure>

In case of any errors, refer to [Xero Sync](/maica-billing-processes/xero-synchronisation.md) article within this knowledge base.


---

# 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://kb.maica.com.au/maica-billing-processes/xero-connection-configuration.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.
