I was trying to update some customer records on an API when this question struck.
First I request the customer object from the API and transform it into an array, the update I have to perform consists on appending a quite big second array to the one I first got, so I decided to do so and then, use UPDATE to upload the whole new array as substitute for the old one.
Since this is the actual API and every change I made would go directly into production, I am not sure if this is going to work, and I thought that I could always delete the old object and make a simple POST request to upload the new one.
This is the method tasked to upload the new array ($response).
function updateReceipt($response, $receiptId, $uri4, $token){
$ch = curl_init();
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $uri4.$receiptId,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => http_build_query($response),
CURLOPT_HTTPHEADER => array("Content-Type: application/json", "key: ".$token)
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$response = json_decode($response, true);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "Status code: $http_code ";
curl_close($ch);
return $updated;
}
So, will the PUT method accept the whole array and update the customer record? Does PUT require more accurate changes to be done for it to wrok?
What do you think about the DELETE first, POST next solution? Is it going to be more efficient?
Thank you all for your help!