Issues translating token refresh request from API Docs to Node.js/Javascript

I’m currently attempting to have my token refresh whenever I boot up my chatbot. I’m able to get an access token and a refresh token when first using the code, but when I restart the bot to see if it will automatically updated, it doesn’t seem to be working. I believe the issue to be somewhere within my request call, most likely the options here for the refresh request:

let optsAuth = {
url: “” +
refreshToken + “&client_id=” + clientID + “&client_secret=” + clientSecret,
method: “POST”

Here is the getAuthToken() method:

function getAuthToken(optsAutho) {
request(optsAutho, function(err, response, body) {
try {
response = JSON.parse(body);
authToken = response.access_token;
refreshToken = response.refresh_token;
} catch (err) {

I’m not too comfortable with making calls to the API quite yet, but I’ve been able to squeeze by with pretty much everything I’ve needed, but this.

curl -X POST
    &refresh_token=<your refresh token>
    &client_id=<your client ID>
    &client_secret=<your client secret>

This is the refresh request given in the docs for the New API, but I’m unsure as to how that would translate into Node.js/Javascript. I’ve been using the request module to make all the calls to the API, and just grouping all the…parameters, I guess you’d call them, (the clientID and refreshtoken, etc.) into the url while keeping the same formatting from the code shown in the docs, except for the new lines of course.

This has worked for all of the my other requests, even getting the access token and refresh token. After some testing, it seems I’m receiving a “404 page not found” back when making the refresh request instead of the JSON object with the new tokens. This is why I believe it to be something with my request and not actually on Twitch’s end.

Any help with this would be greatly appreciated. If you need any further information, please feel free to ask.

Thank you for your time!

Remove --data-urlencode from the URL, in the example from the docs that is part of the curl request options, not part of the URL which is why you’re getting a 404 error

That worked wonders! Thank you very much for the quick reply!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.