I'm POSTing to an API that expects a json array called "updateRecord" in the body. I've tried a hundred different methods of getting the data across, but each method fails except for me literally writing the array as escaped text inside the CURLOPT_POSTFIELDS
option.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://url.com/update");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"updateRecord\":[{\"fielda\":\"77777\",
\"fieldb\":\"11.77\",\"fieldc\":\"12\",\"fieldd\":\"12\",\"fielde\":\"99\",
\"fieldf\":\"01\",\"fieldg\":\"TEST\",
\"fieldh\":\"Y\",\"fieldi\":\"Approved\"}]}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Authorization: Basic XXXXXXXXXXXXXXXXXX";
$headers[] = "Cache-Control: no-cache";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close ($ch);
echo $result;
For static test data to prove the API works, this is fine, but I am lost on how to take a pre-existing array in PHP and convert it into a format that will work here, like:
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);