Last active
May 26, 2016 15:24
-
-
Save dstollie/af30fa8e66d4c9547e0ca8db0b60cef8 to your computer and use it in GitHub Desktop.
SamenZwolle.nl activiteit aanmaken PHP voorbeeld
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 | |
error_reporting(E_ALL); | |
ini_set("display_errors", 1); | |
$appUrl = 'http://samenzwolle.bijna.live/api/activities'; | |
$apiKey = '$2y$10$WaWaK1rIVzjiIYh4gkbl.uexHS8dMNBSfcPOO1l3/9k8V4xnQUwBi'; | |
$body = "{\"name\":\"Voorbeeld activiteit\",\"description\":\"Dit is een omschrijving\",\"start_date\":[\"09-05-2016 00:00\",\"11-05-2016 00:00\"],\"end_date\":[\"10-05-2016 00:00\",\"12-05-2016 00:00\"],\"url_email\":\"https://example.com/activities/1\",\"street\":\"Wilhelm Rontgenstraat\",\"house_number\":\"11B\",\"zipcode\":\"8013NE\",\"postbox\":\"-\",\"image1\":\"http://lorempixel.com/400/200/\",\"image2\":\"http://lorempixel.com/400/200/\",\"image3\":\"http://lorempixel.com/400/200/\",\"agreement\":\"1\"}"; | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $appUrl, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_POSTFIELDS => $body, | |
CURLOPT_HTTPHEADER => array( | |
'Accept: application/json', | |
'Authorization: Bearer ' . $apiKey, | |
'Content-Type: application/json' | |
), | |
)); | |
$response = curl_exec($curl); | |
$info = curl_getinfo($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
echo "<pre>"; | |
echo "<h1>Request Body</h1>"; | |
echo print_r(json_decode($body, true)); | |
echo "<h1>Response</h1>"; | |
echo "Status code " . $info['http_code']; | |
if ($err) { | |
echo "cURL Error #:" . $err; | |
} else { | |
echo "<pre>"; | |
echo print_r(json_decode($response, true)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment