Skip to main content
Level 9
Mar 1, 2020 10:37 PM UTC
Solved

Invalid Content-Type on Bulk API call

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.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Mar 1, 2020 10:59 PM UTC

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.

8 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Mar 1, 2020 10:59 PM UTC

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.

Translate
Level 9
Mar 3, 2020 2:31 AM UTC

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? 

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Mar 3, 2020 6:30 AM UTC

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.)

Translate
Level 1
Mar 3, 2020 5:44 PM UTC

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!
Translate
SanfordWhiteman
User Group Leader
User Group Leader
Mar 3, 2020 6:19 PM UTC

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

Translate