Description
I am trying to create a meeting using C# / RestSharp, but I keep receiving an ‘Unauthorized’ response, with content of ‘"{“code”:124,“message”:“Invalid access token.”}"’. However, if I run the same code to retrieve a list of users, the response comes back without any problems?!
Error
Unauthorized, Code 124, Message “Invalid Access Token”
Which App Type (OAuth / Chatbot / JWT / Webhook)?
JWT
Which Endpoint/s?
Create Meeting
How To Reproduce (If applicable)
Steps to reproduce the behavior:
This doesn’t work:
var tokenHandler = new JwtSecurityTokenHandler();
DateTime expiry = DateTime.UtcNow.AddMinutes(5);
string apiSecret = “API_SECRET”;
string apiKey = “API_KEY”;
int ts = (int)(expiry - new DateTime(1970, 1, 1)).TotalSeconds;
var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(apiSecret));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var header = new JwtHeader(credentials);
var payload = new JwtPayload
{
{ “iss”, apiKey},
{ “exp”, ts },
};
var securityToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(securityToken);
RestClient client = new RestClient();
client.BaseUrl = new Uri(“http://api.zoom.us/v2/users/me/meetings”);
RestRequest request = new RestRequest(Method.POST);
request.AddHeader(“content-type”, “application/json”);
request.AddHeader(“authorization”, String.Format(“Bearer {0}”, tokenString));
var data = “{“topic”: “Test Meeting”,“type”: 2,“start_time”: “2020-12-11T10:00”,“duration”: 60,“timezone”: “Europe/London”,“password”: “abcd”,“agenda”: “Testing Meeting”}”;
request.AddParameter(“application/json”, data, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
This does:
var tokenHandler = new JwtSecurityTokenHandler();
DateTime expiry = DateTime.UtcNow.AddMinutes(5);
string apiSecret = “API_SECRET”;
string apiKey = “API_KEY”;
int ts = (int)(expiry - new DateTime(1970, 1, 1)).TotalSeconds;
var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(apiSecret));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var header = new JwtHeader(credentials);
var payload = new JwtPayload
{
{ “iss”, apiKey},
{ “exp”, ts },
};
var securityToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(securityToken);
RestClient client = new RestClient();
client.BaseUrl = new Uri(“https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1”);
RestRequest request = new RestRequest(Method.GET);
request.AddHeader(“content-type”, “application/json”);
request.AddHeader(“authorization”, String.Format(“Bearer {0}”, tokenString));
IRestResponse response = client.Execute(request);