JWT integration - 401 Unauthorized response code":124,"message":"Invalid access token

#1

Hello. I’m trying to set up a simple API Integration to be able to fetch statistics over meetings.

Since I’m doing this from another system, I’m using the JWT approach. But for some reason, the generated token can’t be used. I have no intention of publishing my app. Since this is just so I can automatically fetch the report data from this endpoint. So I can read, minutes in conference calls, and number of meetings from each user.

This is the error code I get when I run my code.
{"code":124,"message":"Invalid access token."}

I use PHP and here is the code I use to fetch the token.

use Firebase\JWT\JWT;

public function getToken() {
  $key = '{MyKey}';
  $secret = '{MySecret}';
  $token = array(
    "iss" => $key,
    "exp" => time() + 60
  );
  return JWT::encode($token, $secret);
}

I then have a function to fetch the userdata like this.

public function getUserData($from, $to) {
	$token = $this->getToken();
	$url = "https://api.zoom.us/v2/report/users?from={$from}&page_number=1&page_size=30&to={$to}&type=active";
	$client = new Client();
    try {
      $response = $client->request('GET', $url, [
        'headers' => [
	      'Authorization' => 'Bearer ' . $token,
	      'Accept'     => 'application/json',
	    ]
      ]);
    } catch (ClientException $e) {
      $response = $e->getResponse();
      $responseBodyAsString = $response->getBody()->getContents();
       return response(['success' => false, 'message' => $responseBodyAsString], 404);
    }
    return json_decode($response->getBody());
}

I don’t know if there is something I need to do in my App settings to make this work.
So how do I make this work?

0 Likes

#2

Hi,

Are you able to run the cURL command in your terminal or Postman?

If yes, can you please send the cURL command?

0 Likes

#3

I solved this. I had the wrong app settings so created a new app with this settings. Now it works.

0 Likes