I need to send a PUT
request with cUrl in PHP. However, I don't get the request body to work.
I need to send the following JSON as PUT
request.
{
"orders": [
{
"order_id": "TBRQCH"
}
]
}
Here is what I tried:
$data['orders'][] = array("order_id" => $orderid);
$curl = curl_init();
curl_setopt($curl, CURLOPT_PUT, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "XXXX");
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
However, it does not work correctly because I get the message from the endpoint that orders is missing. When copy the encoded string to Postman and send the request manually to the API then it works fine.
What am I doing wrong?