A Postman collection for authenticating to the XPM API using OAuth 2.0.
In order to use the Xero Practice Manager API you'll need to pass a self assessment against the Security standard for Xero API Consumers and have your use case approved by our team. Drop us a line at [email protected] to get started.
Once you've passed the assessment and had the scope applied to your app follow these steps to quickly get up and running with the XPM API and Postman:
Click the button below and select the Desktop version of Postman (Chrome extension doesn't support environment variables). This will also install the Collection and Environment we'll be using.
Alternatively, you can download the XPM OAuth2.0.postman_collection and OAuth 2.0.postman_environment JSON files above and import them via the Import button in the top left of the Postman Workplace sceen.
2. Create an OAuth2 app at https://developer.xero.com/myapps
Go to the Xero developer portal and create an OAuth2 app.
If you haven't already signed up for a xero account you can do so here.
Use the following values:
- App Name - your choice, but can't contain the word 'Xero'
- Company or application URL - this needs to be an https address, but isn't used.
- OAuth 2.0 redirect URI - also needs to be https but won’t be used in postman
Then:
- Click Create App
- Click Generate a secret
- Keep the page open
Copy the Client id, Client secret and OAuth 2.0 redirect URI from the My Apps screen into the environment variables in Postman. To add these details to the Environment, make sure you have the OAuth 2.0 Environment selected, click the eye button, then edit.
Our Developer Center lists the available scopes here. For getting started you will need at least:
offline_access practicemanager
In addition, to make further test calls we would also suggest adding:
openid profile email
Add the scopes required to the scopes
environment variable.
Go to your staff list in Xero Practice Manager and click on your user name. Scroll to the very bottom of the second page and toggle on "Connect third-party add-ons"
- Double-click on the GET Get Started request under the Xero OAuth 2.0 Collection
- Select the Authorization tab
- Select "Request URL" in the "Add authorization data to" dropdown menu
- Click Get New Access Token
- Add the Variable names surrounded by {{}} from your Environment into the fields, as shown in the screenshot below
- Add https://login.xero.com/identity/connect/authorize to the Auth URL field
- Add https://identity.xero.com/connect/token to the Access Token Field
- Click Request Token
At this stage you will be prompted to log in to Xero.
You'll be taken through to the account Select window. Select the account you want to connect to. If you want to connect to more than one account, you can repeat the steps above and select another account.
If you've included the openid profile email
scopes, you'll also be asked to access your basic profile information.
If you see a message saying you have no Xero Practice Manager accounts go back and complete step 5. "Ensure you have API Access privileges". If you do not have a Xero Practice Manager account reach out to [email protected]
Once complete you'll be passed back to Postman.
We now have the last remaining tokens needed to access the Xero API. These need to be set to the Environment Variables, to do this:
- Highlight the Access Token
- Right-click on it
- Select Set: OAuth 2.0 > access_token
Follow the same process for the Refresh Token.
- Double-click on the GET Connections request
- Click Send
- Like we did for the Access and Refresh Tokens, highlight the tenantId from the response, right click and select Set > OAuth 2.0 > xero-tenant-id
Congrats! You're now authenticated and can start making API calls. Your access token will last for 12mins, after which time you'll need to refresh the token.
- Double-click to load the GET Client List request
- Ensure No Auth is set on the Authorization tab
- Click Send
- Double-click to load the POST Refresh token request
- Ensure No Auth is set on the Authorization tab
- Click Send
- We use the built in OAuth 2.0 support to get the token, however we then set this as an environment variable. So we don't need to use this support when making the normal API calls.