Use following php code to hit timekit api using php curl
<?php
$curl = curl_init();
// use payload json file
// $payload = file_get_contents(DIR. '/payload.json');
// OR use payload as string
$payload = '{
"resource_id": "d187d6e0-d6cb-409a-ae60-45a8fd0ec879",
"graph": "confirm_decline",
"start": "2018-08-12T21:30:00-07:00",
"end": "2018-08-12T22:15:00-07:00",
"what": "Catch the lightning",
"where": "Courthouse, Hill Valley, CA 95420, USA",
"description": "The lightning strikes at 10:04 PM exactly! I need you to be there Doc!",
"meta":{
"latitude":"34.1381168",
"longitude":"-118.3533783"
},
"customer": {
"name": "Marty McFly",
"email": "marty.mcfly@timekit.io",
"phone": "(916) 555-4385",
"voip": "McFly",
"timezone": "America/Los_Angeles"
}
}'
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.timekit.io/v2/bookings",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
'Authorization: Basic '. base64_encode(":<TIMEKIT_API_KEY>")
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}