Invalid Content-Type in Custom Object Bulk Import in PHP | Community
Skip to main content
New Participant
July 18, 2023
Solved

Invalid Content-Type in Custom Object Bulk Import in PHP

  • July 18, 2023
  • 2 replies
  • 1830 views

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.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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.

2 replies

SanfordWhiteman
New Participant
July 19, 2023

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

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
July 18, 2023

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.

New Participant
July 27, 2023

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
New Participant
July 27, 2023

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.