Created
December 14, 2018 07:24
-
-
Save roelvan/19d77777d6f365a913ba1e11b92b1d59 to your computer and use it in GitHub Desktop.
CREATE booking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// get cURL resource | |
$ch = curl_init(); | |
// set url | |
curl_setopt($ch, CURLOPT_URL, 'https://[jouw-subdomein].bookfast.app/bookings'); | |
// set method | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
// return the transfer as a string | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
// set headers | |
curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
'x-api-key: geheime_sleutel_die_je_krijgt', | |
'Content-Type: application/json; charset=utf-8', | |
]); | |
// json body | |
$json_array = [ | |
'phone' => '+321234567', | |
'numberOfSpots' => 1, | |
'firstName' => 'Iris', | |
'lastName' => 'Vandetest' | |
'coupon' => 'TEST', | |
'email' => '[email protected]', | |
'eventId' => '[unieke_bookfast_event_id]', // id van evenement in kwestie | |
'metadata' => [ | |
'test' => 'Van Roel!' | |
] | |
]; | |
$body = json_encode($json_array); | |
// set body | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); | |
// send the request and save response to $response | |
$response = curl_exec($ch); | |
// stop if fails | |
if (!$response) { | |
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); | |
} | |
echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL; | |
echo 'Response Body: ' . $response . PHP_EOL; | |
// close curl resource to free up system resources | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment