SOLVED

Invalid Content-Type in Custom Object Bulk Import in PHP

Go to solution
EricLeeDocker
Level 1

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.
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Invalid Content-Type in Custom Object Bulk Import in PHP


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.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Invalid Content-Type in Custom Object Bulk Import in PHP


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.

EricLeeDocker
Level 1

Re: Invalid Content-Type in Custom Object Bulk Import in PHP

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: Invalid Content-Type in Custom Object Bulk Import in PHP

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: Invalid Content-Type in Custom Object Bulk Import in PHP

Please return to your thread and check responses, @EricLeeDocker.