A Postman collection for authenticating to the Xero API.
Follow these steps to quickly get up and running with the Xero API and Postman with the PKCE Grant Type:
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.
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:
You'll then be taken to your App's Details page. Keep this page open, and start up Postman.
Copy the following details into the Params tab of the GET Authorisation Call:
openid profile email offline_access accounting.transactions
The main difference between an Authorisation Grant Type and the PKCE Grant, is that the PKCE Grant does not have Client Secret. It instead uses a Code Verifier and Code Challenge. As you can’t currently generate these codes easily in Postman at the moment, you can use the following online tool to generate them for you: https://tonyxu-io.github.io/pkce-generator/
Just like the Params Tab of GET Authorisation Call, we now need to add the Following Details to your Environment:
Now that you have added all the variables to both the Environment and Params Tab, double click and copy the URL that Postman has generated for you out of the URL Call field and paste it into your browser.
You’ll then be directed to the Xero Login Screen. If you hit an Error 500 at this stage, towards the bottom of the error page, an error message will display, showing what is causing the error. Login with a User account with either an active Demo Company, or Xero Organisation (this Organisation can be a Trial).
Good | Bad |
---|---|
Once logged in you’ll be able to select an Organisation and shown what your app will access within this selected Organisation. If you are happy with this, click Allow Access.
Once you have clicked Allow Access, you’ll be redirected back to the website you’re using as your Redirect URI. In the URL of this website, you’ll be given a code. Copy this Code out of your Browser, from the first character after “code=”, upto the &. Then paste this into the Code field in the Body Tab of the POST Token Call. Add this code to the Code Field. If this is the first time you've done this you'll be replacing this text:
Returned in the authorization step
Once you have added the Code to the POST Token Call, click the Send Button to receive your Access and Refresh Token. You’ll also be given an ID Token if you’ve included the OpenID scopes (openid, profile and email) however we will not be using this Token in this Tutorial.
Once you’ve received your tokens, Set your Access Token to your Environment:
Once this has been done, do the same for the Refresh Token
Select the Connections Call from your Collections on the Left and Send the Call. You’ll then be returned the Connection ID (named ID), Tenant ID, Tenant Type, Created and Updated Dates of your Tenants. If you've connected Multiple Organisations, you'll receive multiple Tenant IDs.
Like we did for the Access and Refresh Tokens, we now need to set the Tenant ID.
Once this has been done you can start making calls! We'd suggest trying out the Invoice Get Call included with the Collection. If you'd like to try out other endpoints, remember you may need to also add a new Scope to access it. If you do this, add the new Scope at step 3 and start the process again from there.
Happy API'ing!