Aleks Per
Aleks Per

Reputation: 1639

Request to API works in Postman but not when I try with laravel/guzzle

I make an API and now I try to access to that API. WIth Postman everything is perfect and works fine:

enter image description here

but when I try the same with guzzle/laravel with code:

$res3 = $client3->post('https://app.EXAMPLE.com/api/update/'.$serial, [
    'headers' => [
        'Authorization' => 'Bearer '.$res2['token'],
        'Content-Type' => 'application/json'
    ],

    'form_params' => [

      'token' => $res2['token'],
        'bookingdate' => '07/07/2018 12:00 am',
        'notes' => $SpecialRequests
        ]
]);

I got:

Object

data : debug : class : "Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException" file : "/home/user_name/public_html/vendor/dingo/api/src/Auth/Auth.php" line : 113

What is a problem? WHy works in Postman but won't work with Laravel/Guzzle library?

Upvotes: 4

Views: 5143

Answers (1)

groodt
groodt

Reputation: 1993

In Postman, it looks like you are sending the token as a request parameter. In your code, it looks like you are using form_params, which are application/x-www-form-urlencoded.

Try this: http://docs.guzzlephp.org/en/stable/quickstart.html#query-string-parameters

$res3 = $client3->post('https://app.EXAMPLE.com/api/update/'.$serial, [ 'headers' => [ 'Authorization' => 'Bearer '.$res2['token'], 'Content-Type' => 'application/json' ], 'query' => [ 'token' => $res2['token'], 'bookingdate' => '07/07/2018 12:00 am', 'notes' => $SpecialRequests ] ]);

Upvotes: 5

Related Questions