Invalid Content-Type on Bulk API call | Community
Skip to main content
New Participant
March 1, 2020
Solved

Invalid Content-Type on Bulk API call

  • March 1, 2020
  • 2 replies
  • 6918 views

Hi everyone

Having some trouble with a Marketo Bulk API job.  Here's the Python code:

 

# marketo params parameters = { 'format': 'csv', 'access_token': access_token, 'createdAt': '{"startAt": "2020-02-15T23:59:59-00:00","endAt": "2020-02-26T23:59:59-00:00"}', 'activityTypeIds': '[113]' } headers = {'accept': 'application/json'} # first call response = requests.post( "https://(redacted).mktorest.com/bulk/v1/activities/export/create.json", params=parameters, headers=headers )

 

The error I get is 612 - invalid content type. This is a little confusing to me though. I'm not uploading a multipart file or anything, so shouldn't it be regular application/json?

 

Thanks.

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

Yes, when you POST JSON, the request Content-Type should be application/json.

 

So make sure you've set that header! Or use json=payload, which sets it automatically.  

 

Note the way you're mixing params and body is pretty confusing, even if some Marketo API endpoints accept this mixture it's not advisable.

2 replies

New Participant
March 3, 2020

The body literally has to be a JSON string -- just getting into using the API myself.  Please look at the docs here:
https://developers.marketo.com/rest-api/bulk-extract/bulk-activity-extract/

 

And the request needs to be submitted as a POST, not GET.  This literally worked for me in Postman:

body

----------

{
"format": "CSV",
"filter": {
"createdAt": {
"startAt": "2020-02-01T00:00:00Z",
"endAt": "2020-03-01T00:00:00Z"
},
"acitivyTypeIds": [
113
]
}
}

 

response
-----------

{
    "requestId""13b9#170a17da0c4",
    "result": [
        {
            "exportId""ae60fc08-cd1b-46ed-8905-c84b858b1c66",
            "format""CSV",
            "status""Created",
            "createdAt""2020-03-03T17:42:09Z"
        }
    ],
    "success"true
}
 
Good luck!
SanfordWhiteman
New Participant
March 3, 2020

Correct, that's what I said above. Pls highlight your JSON though.

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
March 1, 2020

Yes, when you POST JSON, the request Content-Type should be application/json.

 

So make sure you've set that header! Or use json=payload, which sets it automatically.  

 

Note the way you're mixing params and body is pretty confusing, even if some Marketo API endpoints accept this mixture it's not advisable.

New Participant
March 3, 2020

Weird. Just tried in Postman, with these details:

 

https://(redacted).mktorest.com/bulk/v1/activities/export/create.json?format=csv&access_token=(redacted)&createdAt={ "startAt": "2020-02-15T23:59:59-00:00","endAt": "2020-02-26T23:59:59-00:00"}&activityTypeIds=[113]

 

Header is: 

 

Content-Type: application/json

 

And error code is:

 

 

{ "requestId": "8c00#1709e393153", "success": false, "errors": [ { "code": "609", "message": "Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@9bfa1393" } ] }

 

 

Hmmm what am I missing here?

 

Also, could you elaborate on what you mean by "mixing params and body" in the Python code? 

SanfordWhiteman
New Participant
March 3, 2020

Also, could you elaborate on what you mean by "mixing params and body" 


You're passing some parameters in the query string (though apparently not URL-encoding them, which is bound to fail with some values!) yet POSTing other parameters in the JSON body.

 

You should be putting everything in the body (a.k.a. payload, a.k.a. request body, a.k.a. entity-body). The fact that certain things seem to work when passed in the query string is coincidental. (It's a factor of the way some web servers have a combined "params" object that merges query params, post bodies, HTTP headers, even environment variables and cookies - but isn't supported.)