Solved
Invalid Content-Type in Custom Object Bulk Import in PHP
I've looked everywhere and can't figure out why I continue to get the following error when attempting to post a json string to this endpoint:
https://[redacted].mktorest.com/bulk/v1/customobjects/customFormJson_c/import.json?json=payload&access_token=[redacted]
[code] => 612 [message] => Invalid Content Type
I'm using cURL in PHP and this is my code:
$JSON_a = array(
'emailAddress' => 'emailaddress@test.com',
'jSONFormSubmission' => 'Form submission data'
);
$JSON_e = json_encode($JSON_a);
echo "encoded JSON:<br />\n$JSON_e";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$curl_url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$JSON_e);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = array(
'Content-Type: application/json;charset=UTF-8',
'Host: [redacted].mktorest.com',
'Authorization: Bearer '.[redacted],
'Accept: application/json'
);
echo "<pre>";
print_r($headers);
echo "</pre>";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = json_decode(curl_exec ($ch),true);
echo "server output<br /><pre>".print_r($server_output,true)."</pre>";
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
if(!curl_errno($ch)){
echo "<pre>";
curl_getinfo($ch);
echo "</pre>";
}else{
echo "<br />cURL error";
}
curl_close($ch);
I've studied this previous post top to bottom multiple times and I know I have the content-type set correctly, but I'm not sure what I am still doing wrong.