Getting a valid token with 200status but when trying to create a meeting im getting invalid access token

Format Your New Topic as Follows:

API Endpoint(s) and/or Zoom API Event(s)
https://api.zoom.us/v2/users/me/meetings

Description
I configured a server-to-server oauth app awith these scopes “meeting:read:admin meeting:write:admin etc” and i am trying to create a meeting.

Error?
each time i try to execute a service in my spingboot project to create a meeting through this POST endpoint
https://api.zoom.us/v2/users/me/meetings”, i get this error :
401 Unauthorized: “{“code”:124,”message”:”Invalid access token.”}"
I am calling the service only once, not using multiple instances of my project or multiple thread .
Debugging
When debugging, i see that i am retrieving a token, and when i try to use that token and use it in postman instead of continuing the service pocess in the debug mode, i get invalid access token too.
But if i generate the access token using Postman, the token allows me to create the meeting ( even tho im using same credentials)

So the issue is probably in this code ?

  private void generateAccessToken() {

    //the uri for generating an Access token
    URI uri = UriComponentsBuilder
        .fromUriString(OAUTH_API_URL)
        .queryParam("grant_type", "client_credentials")
        .queryParam("account_id", ACCOUNT_ID)
        .build()
        .toUri();

    //Setting basic auth credentials & Media type in header
    HttpHeaders headers = new HttpHeaders();
    headers.setBasicAuth(CLIENT_ID, CLIENT_SECRET);
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    HttpEntity<?> requestEntity = new HttpEntity<>(headers);

    //Calling the endpoint
    ResponseEntity<AccessTokenResponse> responseEntity = restTemplate.exchange(
        uri,
        HttpMethod.POST,
        requestEntity,
        AccessTokenResponse.class);
    
    
    if (responseEntity.getStatusCode() == HttpStatus.OK) {
      AccessTokenResponse accessTokenResponse = responseEntity.getBody();
      if (accessTokenResponse != null) {
        this.accessToken = accessTokenResponse.getAccessToken();
        this.accessTokenExpiry = LocalDateTime
            .now()
            .plusSeconds(accessTokenResponse.getExpiresIn());
      }
    }
  }

  @Getter
  private static class AccessTokenResponse {

    @JsonProperty("access_token")
    private String accessToken;

    @JsonProperty("expires_in")
    private int expiresIn;
  }

Possibly related to this? Jwt authentication starts return 401 at 2023-06-09 13:00 UTC+9 - API and Webhooks / Authentication - Zoom Developer Forum

Hi @haithem.nasri.pro
Thanks for reaching out to us!
It looks like you are passing the wrong grant_type in your request to generate the access_token.
If you are using a Server to Server Oauth app, you should be passing grant_type=account_credentials in your request instead of client_credentials.

could you please double check that form me ant let me know if that helped!
cheers,
Elisa

1 Like

hi
Thanks for your reply, and yes you are right i have just checked that today morning!
Seems like this is your typical friday afternoon malfunction haha

Thanks again

Happy to hear its working now! @haithem.nasri.pro
Let us know if there is anything else we could to to support you
Cheers,
Elisa

1 Like