Create Meeting API returns GET request - Guzzle / PHP

Description
the create meeting POST route returns fine in CURL, however, in guzzle it redirects to the GET request.

Error
None showed, as redirected.

Which App Type (OAuth / Chatbot / JWT / Webhook)?
JWT

Which Endpoint/s?

How To Reproduce (If applicable)
Steps to reproduce the behavior:

        //TODO: Cannot get the Guzzle Version to work with POST requests.
        // try {
        //     $url = 'users/' . request()->route()->parameter('userId') . '/meetings';
        //     $response = $this->client->request('POST', $url, [
        //     'headers' => $this->headers,
        //     'body' => json_encode([
        //         'topic' => 'Hello',
        //         'type' => 2,
        //         'schedule_for' => 'QTk1g81ES_-8FMCOV9Q7bg',
        //         'start_time' => '2020-05-31T12:00:00Z',
        //         'duration' => 30
        //     ]),
        // ]);
        // }
        // catch (\GuzzleHttp\Exception\ClientException $e) {
        //     $response = $e->getResponse();
        // }
        // return $response;


        $curl = curl_init();

        curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.zoom.us/v2/users/". request()->route()->parameter('userId') . "/meetings",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => '{"topic": "hello my darling", "type": 2, "start_time": "2020-05-31T12:00:00Z", "duration": 30}',
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer " . $this->jwt,
            "content-type: application/json"
        ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
        return $err;
        } else {
        return $response;
        }

Screenshots (If applicable)
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

I use Guzzle just fine with POST requests to Zoom.

      $client = new GuzzleHttp\Client();

      $response = $client->request('POST', Zoom::$apiRoot . $apiPath, [
          'query' => $query,
          'json' => $payload,
          'headers' => ['Authorization' => "Bearer " . $auth],
          'http_errors' => false
      ]);

where $payload is my JSON body and $query is the query string, if any.

I am glad you are able to achieve this, but unfortunately, it still isn’t working for me. The GET routes work fine, but I cannot get my POST route to work with guzzle, as when I send a POST request in postman it returns the get Route.

     public function createmeeting(Request $request) {
        $payload =  json_encode('{"topic": "hello my darling", "type": 2, "start_time": "2020-05-31T12:00:00Z", "duration": 30}');
        try {
             $url = 'users/' . request()->route()->parameter('userId') . '/meetings';
             $response = $this->client->request('POST', $url, [
                'json' => $payload,
                'headers' =>  $this->headers,
                'http_errors' => false
          ]);
        }
        catch (\GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
        }
        return $response;

Route.api

Route::post('ZoomAPI2/users/{userId}/meetings', 'ZoomAPIV2@createmeeting');

One thing - looks you’re using json_encode() to encode a string. json_encode() returns a string, so not sure if that’s useful at all.

Otherwise, how do you know it’s redirecting to a GET? What kind of response is Guzzle giving you?

Hi,

Yeah the JSON encode thing was because I thought maybe my JSON body wasnt correct, but I think it is.

I only assume its returning the get response (because the response is exactly the same as the get route). i.e. a list of meetings for the user.

Im setting up guzzle in __construct


    public function __construct(Request $request) {
 
        $api_secret = $_ENV['ZOOM_SECRET_KEY'];
        $api_key = $_ENV['ZOOM_API_KEY'];
        $payload = array(
        'iss' => $api_key,
        'exp' => (time() + 60)
        );
        $this->jwt = JWT::encode($payload, $api_secret);

        //create guzzle client
        $this->client = new \GuzzleHttp\Client(['base_uri' => 'http://api.zoom.us/v2/']);
        $this->headers = [
            'Authorization' => 'Bearer ' . $this->jwt,
            'Accept'        => 'application/json',
            'content-type' => 'application/json'
        ];
    } 

Hey @afletcher53,

Have you tried googling this issue? It seems specific to guzzle. Also double check you are making a POST request and not a GET request.

Thanks,
Tommy