I am trying to make a script that sends data through PUT. However I seem not to succeed.
I have tried to do so with a CURL script but to no avail.
///######## INDICATE PUT
curl_setopt($this->CurlOBJ, CURLOPT_CUSTOMREQUEST, 'PUT');
I think I need to do more however generally speaking what I can find on the internet is that I am supposed to this by :
$data = file_get_contents('php://input')
I have however no clue how to send data with file_get_contents(); Furthermore I am asked to send a header with an API key.
However my second question is how to send a header key with PUT. Third is... Is using PUT a good idea for building an API. This however is a side question.
So how can I send data by PUT and getting any valid return?
Answer
Tadman has send me in the right direction! So even though this question had been marked as a duplicate. Still his answer gave me the solution.
For those like me that didn't have enough with the first answer hereby my piece of working code.
Thanks!
<?php $bookingID = 'aae2cdfd-6789-474d-828c-190e14a0f01e'; $url = 'https://api.someapp.com/application/'.$bookingID.'/update'; $data = array( 'changeDate' => date('c'), 'options' => array( 'allowEdit' => true ) ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); ///######### SET THE HEADER $headers = array('apiSetKey: 2388089'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if (!$response) { return false; } else { ///######## JSON DECODE DATA $response = json_decode($response, true); print_r($response); } ?>