Refresh Creator's Access Token - I'm failing

Dear Team,
I’m failing to update my creators access token as per Step 7 - Keeping up to date via Node.js. I always get a

status: '405',
title: 'Method Not Allowed' 

as response.

This is the code:

var CLIENT_ID = '<clientid>'
var CLIENT_SECRET = '<secret>'
token = '<actual CREATORS TOKEN>' 
refresh_Token ='<refresh token>' //


url = 'https://www.patreon.com/api/oauth2/token'
options = {
    method: 'POST',
  headers:
   { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
     'User-Agent': 'my bot' },
  body:
   `client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&refresh_token=${refresh_Token}&grant_type=refresh_token`,
   params:
   { client_id: CLIENT_ID,
     client_secret: CLIENT_SECRET,
     refresh_token: refresh_Token,
     grant_type: 'refresh_token'},
  credentials: 'include',
  compress: false 
}
request.get(url, options, function (e, r, body) {
(...)
}

Any idea?
I tried to use the normal client token process for this, but I guess it has to look differently for the creators token, but I’m not sure…

Thanks!
Meffesino

OK. i figured it out by myself. First of all, I had done
request.get while the mothod was (correctly) stated as “post”.

secondly, the body has to be created a bit differently.

here you go:

var CLIENT_ID = '<ID>'

var CLIENT_SECRET = '<SECRET>'

var token = '<Token- NOT NEEDED FOR REFRESH TOKEN>' 

var refresh_Token =<REFRESH TOKEN>' //

var form = {
    grant_type: 'refresh_token',
    client_id: CLIENT_ID,
    client_secret: CLIENT_SECRET,
    refresh_token: refresh_Token
}

var formData = querystring.stringify(form);
var contentLength = formData.length;

request({
    headers: {
      'Content-Length': contentLength,
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    uri: 'https://www.patreon.com/api/oauth2/token',
    body: formData,
    method: 'POST'
  }, function (err, res, body) {
console.log(body)  
});
3 Likes