Level 80
May 11, 2017
5
Level 2
How to use CURL with php
I need help with curl and php...
In API which I need to use I have example of CURL request:
curl https://api.example.com/api/AvailabilitySearch ^ -H "Authorization: Bearer eyJ0ehsagdasjhgdashdgaOiJIUzI1NiJ9.eyJpc3Msjhdshjdasd7676N5c3RlbXMuY29tIn0.DBR5UPxxxxxxzxzxzxzxzxzxzxyzxyzxyzxyzyxzyxyzxyxxWQ_BkS1mzxw" ^ -d VisitDate=2017-05-08 ^ -d PartySize=2 ^ -d ChannelCode=ONLINE
How to make this curl request in php?
Level 80
@aleksov The Guzzle docs show you how to create and send requests. The above would look something like:
$client = new GuzzleHttp\Client;
$response = $client->get('https://api.example.com/api/AvailabilitySearch', [
'headers' => [
'Authorization' => 'Bearer YOUR_TOKEN_HERE',
],
'form_params' => [
'VisitDate' => '2017-05-08',
'PartySize' => '2',
'ChannelCode' => 'ONLINE',
],
]);
// You need to parse the response body
// This will parse it into an array
$response = json_decode($response->getBody(), true);
9 likes
Please or to participate in this conversation.