Getting 401 error

this code is running fine locally but not in production, showing 401 error

var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
var now = DateTime.UtcNow;
var apiSecret = “**************************”;
byte symmetricKey = Encoding.ASCII.GetBytes(apiSecret);

        var tokenDescriptor = new SecurityTokenDescriptor
        {
            Issuer = "*****************",
            Expires = now.AddSeconds(300),
            SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
        };

        var token = tokenHandler.CreateToken(tokenDescriptor);
        var tokenString = tokenHandler.WriteToken(token);

        var client = new RestClient("https://api.zoom.us/v2/users/rahulchaudhary.sce@gmail.com/meetings");
        var request = new RestRequest(Method.POST);
        request.RequestFormat = DataFormat.Json;
        request.AddJsonBody(new { topic = "Meeting with Rahul", duration = "10", start_time = "2021-04-20T05:00:00", type = "2" });

        request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
        IRestResponse restResponse = client.Execute(request);
        HttpStatusCode statusCode = restResponse.StatusCode;
        int numericStatusCode = (int)statusCode;
        var jObject = JObject.Parse(restResponse.Content);

Hi @rahulchaudhary.sce,

What is the exact 401 error you’re getting? Is this an invalid access token error, or something else?

Let me know when you have a chance—thanks!
Will

hello,
Thanks for your replay sir. Now the problem have been resolved.

Glad to hear it @rahulchaudhary.sce :slight_smile:

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