So basically I'm trying to refresh my access token for access to the xero API on a google sheets spreadsheet. I want to be able to continue using the API without having to re-authorize every 30 minutes. Below is the fetch request I have set up to do this so far. I've tried many different approaches to achieve this but every one is met with an "unsupported_grant_type"
error. I'm using this library for managing the xero API. I'm not sure if it is correctly storing the refresh token and how to get the refresh token if it is? Any suggestions on how to get my API to refresh automatically?
function reAuthoriseXero() {
var driveService = getDriveService();
var res = UrlFetchApp.fetch('https://identity.xero.com/connect/token', {
method: 'POST',
muteHttpExceptions: true,
headers: {
ContentType: "application/x-www-form-urlencoded",
authorization: "Basic " + Utilities.base64Encode(CLIENT_ID + ":" + CLIENT_SECRET),
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
refresh_token: REFRESH_TOKEN,
grant_type: 'refresh_token'
}
})
console.log(res.getContentText());
}