Xero 401 "Unauthorized" after the access token expires
Updated
A Xero request returns HTTP 401 Unauthorized after the access token’s expiry. Check which token the app puts in the request.
A Xero request returns HTTP 401 Unauthorized after the access token’s expiry. Check which token the app puts in the request.
| What we checked | Where |
|---|---|
| Xero Accounting API 401 response | developer.xero.com |
| Xero access token lifetime, claims and request headers | developer.xero.com |
| Report of checking expiry in the Xero OAuth SDK | stackoverflow.com |
Check it yourself
- Check the
expclaim on the access token used for the failed call. Xero access tokens are valid for up to 30 minutes. - If the token had expired, use the stored refresh token to get a new token set. Save both returned tokens and send the new access token in the
Authorization: Bearerheader. - If the app has no refresh token, check whether authorization included
offline_access. To obtain a refresh token for background sync, request that scope when the user authorizes the app again.
Still failing?
Send the endpoint, the HTTP response and the token expiry time to money@iftodo.ai for a free first look. Leave out the token and authorization header.
Weekly sync checks for €29 a month
For one Shopify or Square to QuickBooks workflow, we check weekly exports for missing or duplicate records and email you when we find a mismatch. We run a sample first to see whether the two exports have matching references.
Ask for a sample check. We agree how to share exports before starting billing. Cancel by email before your next renewal.