We are experiencing a strange behavior while refreshing Access token in the OAuth API calls
Here is the workflow
Send API call to create meeting using POST /users/{userId}/meetings
If access token is expired, we get status code as 401.
Send post call to refresh access token as described in this article https://marketplace.zoom.us/docs/guides/auth/oauth/#refreshing-an-access-token
We receive status code of 200 and response in HTML format instead of JSON.
We require JSON response 100% of the time. This issue is not happening when we are getting the first access token after using the Publishing URL https://marketplace.zoom.us/docs/guides/auth/oauth/#getting-an-access-token . This occurs only when refreshing the access token after receiving status 401. We are using the exact same header in both scenarios.
Here is the header:
'Content-type' => 'application/json',
'Accept' => 'application/json, application/xml'
'Authorization' => 'Basic Client_ID:Client_Secret'
Any insights will be helpful.
Thanks
Update:
HTTP request of refreshing access token below
Blob headerValue = Blob.valueOf('Client_ID:Client_Secret');
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
String endpointBuild = 'https://zoom.us/oauth/token?refresh_token=' + refreshToken + '&grant_type=refresh_token';
HttpRequest request = new HttpRequest();
request.setMethod('POST');
request.setEndpoint(endpointBuild);
request.setHeader('Content-type', 'application/json');
request.setHeader('Accept', 'application/json, application/xml);
request.setHeader('Authorization', 'Basic ' + authorizationHeader);
HttpResponse httpResponse = new Http().send(request);
@zoom.dev1 , Hope you will be fine. You are using which request package to call Zoom REST API e.g axios, HTTPClient etc.
We are using Salesforce HTTP class. Solution is built solely on Salesforce
Yes absolutely. It is as below
request.setHeader('Content-type', 'application/json');
request.setHeader('Accept', 'application/json, application/xml);
request.setHeader('Authorization', 'Basic' + Client_ID:Client_Secret);
These headers are working correctly when we use them for initial access token. It only occurs when we are refreshing the access token
How you are refreshing token by passing in query parameteres?
@zoom.dev1 , Are you encoding client_id:client_secret base64 string.
As here is the NodeJS sample
const refresh_token=async (refresh_token)=>
{
var data = qs.stringify({
refresh_token: refresh_token,
grant_type: 'refresh_token',
redirect_uri: process.env.ZOOM_OAUTH_REDIRECT_URI
});
var config = {
method: 'post',
url: 'https://zoom.us/oauth/token',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + Buffer.from(`${process.env.ZOOM_CLIENT_ID}:${process.env.ZOOM_CLIENT_SECRET}`).toString('base64')
},
data: data
};
var result = await axios(config)
.then(function (response) {
return response;
})
.catch(function (error) {
return error;
});
return result;
}
gauravdev
(Gaurav)
January 5, 2023, 12:43pm
8
I am using Server to server oauth app, i have a php code by using guzzlehttp client i am able to get the access code but i am geeting a error html and also this error
300
Unsupported Content Type
when i user this end point https://api.zoom.us/v2/users/me/meetings
the body is like this
{
“topic”: “Testing-02”,
“type”: “2”,
“start_time”: “2023-01-06”,
“duration”: “60”,
“timezone”: “Asia/kolkata”,
“password”: “123”,
“agenda”: “Testing for zoom meeting”,
"settings: {
‘host_video’: “true”,
‘join_before_host’: “true”,
‘mute_upon_entry’: “true”,
‘participant_video’: “true”,
‘breakout_room’: {
‘enable’ : “true”
}
}
}
@freelancer.nak
I have updated my post above as well with this code
Blob headerValue = Blob.valueOf('Client_ID:Client_Secret');
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
String endpointBuild = 'https://zoom.us/oauth/token?refresh_token=' + refreshToken + '&grant_type=refresh_token';
HttpRequest request = new HttpRequest();
request.setMethod('POST');
request.setEndpoint(endpointBuild);
request.setHeader('Content-type', 'application/json');
request.setHeader('Accept', 'application/json, application/xml);
request.setHeader('Authorization', 'Basic ' + authorizationHeader);
HttpResponse httpResponse = new Http().send(request);
We are receiving the refreshed Access Token; however, that response is coming in as HTML format instead of JSON format
Thank you for the replies
Please use this header → "Content-type": "application/x-www-form-urlencoded"