Using JWT with nodejs fetch

I have a simple app that can successfully use the API with a JWT token. When I try to use nodejs fetch I have problems. I get a 403 error. The code is below. I must be setting up my headers incorrectly. The token value has been working, just not with fetch. I’m running on localhost:3000. The error returned in the catch is "TypeError: Failed to fetch {stack: ‘TypeError: Failed to fetch’, message: ‘Failed to fetch’}
"

async function meetingsGet(email, startDate, endDate) {

var url = https://api.zoom.us/v2/users/${email}/meetings?type=past&page_size=300;
var bearer = 'Bearer ’ + token;
email = encodeURIComponent(encodeURIComponent(email))
fetch(url, {
method: ‘GET’,
headers: {
‘Authorization’: bearer,
‘User-Agent’: ‘Zoom-api-Jwt-Request’,
‘Content-Type’: ‘application/json’
}
}).then(responseJson => {
var items = JSON.parse(responseJson._bodyInit);
console.log(“fetched”, responseJson);
})
.catch(error => console.log(error));
}

Just curious, have you tried removing the user-agent and content-type headers, since they are not required?

Other than that, I don’t see any reason as to why the code would not be working. Could you post an example of a completed request object? Have you tried this on a production server, rather than localhost?

Thanks,
Alex

1 Like

Thanks for taking a look. Here is the debug output for the request in Chrome. I checked the jwt token and it looks correct.

Request URL:

https://api.zoom.us/v2/users/rachel.gossett%40sultan.k12.wa.us/meetings?type=past&page_size=300

Referrer Policy: no-referrer-when-downgrade

Request Headers

accept:application/json
authorization: Bearer
content-type: application/json
Referer: http://localhost:3000/reports/gbezoomsummary
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36

I need to create a production server yet. I’m hoping it’s possible to debug using localhost in some way.

Major brain fart. Since I had api calls working on a node server with a JWT I assumed I could do the same from within a React application. I need to look at the Web SDK. Too long out of the programming saddle!!

I’m glad @alexmayo could help, @mobitinker! :slight_smile:

Best,
Will

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