Skip to content
Advertisement

How to configure API key & API secret in Laravel?

I have been working on a Laravel project that provides online education to students. I wanted to use Zoom services of video conferencing so that the teacher can connect with their students through video conference. Following the API reference documentation, I have registered an app with Zoom. I got an API key and API secret along with an access token by following the documentation.

I am sending subsequent requests to post/fetch data from Zoom, but I have been getting an error message like this:

Client error: `POST https://api.zoom.us/v2/accounts` resulted in a `400 Bad Request` response: {"code":200,"message":"Invalid api key or secret."}  

I am sending API key and API secret in header but still getting the same error. Probably I am doing something wrong with the requesting process or may be something else, I don’t know. I have searched on internet how to integrate Zoom with Laravel app but couldn’t find any helpful information.

Can anybody please help me to figure out what I am doing wrong? Can someone provide me some helpful resources about Zoom API integration with Laravel?

class AccountsController extends Controller
{
    public function createAccount(Request $request) {

        $client_id = env('CLIENT_ID');
        $client_secret = env('CLIENT_SECRET');

        $content = "grant_type=client_credentials&client_id=$client_id&client_secret=$client_secret";
        $token_url="https://zoom.us/oauth/token";

        $curl = curl_init();

        curl_setopt_array($curl, array(

            CURLOPT_URL => $token_url,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $content
        ));

        $data = curl_exec($curl);
        curl_close($curl);
        $result = json_decode($data);

        $access_token = $result->access_token;
        $client = new GuzzleHttpClient();

        $api_key = env('API_KEY');
        $api_secret = env('API_SECRET');

        $response = $client->request('POST', 'https://api.zoom.us/v2/accounts', [
            'headers' => [
                'apikey' => $api_key,
                'apisecret' => $api_secret,
                'Accept' => 'application/json',
                'Content-Type' => 'application/json',
                'Authorization'     => 'Bearer '. $access_token
            ],
            'form_params' => [
                'first_name' => $request->first_name,
                'last_name' => $request->last_name,
                'email' => $request->email,
                'password' => $request->password,
            ],
        ]);
        $response = $response->getBody()->getContents();
        dd($response);
    }
}

This is the json response against this API call:

{
  "id": "string",
  "owner_id": "string",
  "owner_email": "string",
  "created_at": "string"
}

Advertisement

Answer

I noticed you are trying to use: grant_type=client_credentials to get an access_token. The grant_type=client_credentials is only for getting Chatbot tokens.

To call the Zoom APIs via the OAuth App Type you must use: grant_type=code to get an access_token.

OR

For server to server integration, you can use a JWT App Type to call the Zoom APIs.

More details on Zoom App Types here.

(Asker moved to Zoom Developer Forum: https://devforum.zoom.us/t/invalid-api-key-or-secret-error)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement