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:
[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);
Solved! Go to Solution.
I know I have the content-type set correctly
Nope. You’re sending JSON and setting the Content-Type to application/json.
The Bulk Custom Object Import endpoint expects multipart/form-data.
I know I have the content-type set correctly
Nope. You’re sending JSON and setting the Content-Type to application/json.
The Bulk Custom Object Import endpoint expects multipart/form-data.
Thanks, Sanford!
I finally figured out the issue after you pointed to the json content-type being not a valid route.
Basically all of the multipart messaging stuff in the example had to be removed (the boundaries, etc.) and only the data posted. After that, Marketo returned a successful response saying the job was queued up.
The correct payload is multipart/form-data.
Your programming language or HTTP library may automatically add the MIME structure when instantiating a multipart/form-data object but the example, which is language-agnostic raw HTTP payload, is still correct.
Please return to your thread and check responses, @EricLeeDocker.