Skip to content

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 checkedWhere
Xero Accounting API 401 responsedeveloper.xero.com
Xero access token lifetime, claims and request headersdeveloper.xero.com
Report of checking expiry in the Xero OAuth SDKstackoverflow.com

Check it yourself

  • Check the exp claim 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: Bearer header.
  • 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.