When calling the flexible audiences endpoint defined in
“Custom Audiences | Docs | Twitter Developer Platform”
The post request returns an error
“invalid json string”
The json string is:
[
{
"operation_type":"Create",
"params":{
"name":"my_flexible_audience_name",
"audience_type":"FLEXIBLE",
"segments":{
"boolean_operator":"AND",
"child_segments":[
{
"custom_audience_id":"TYIF",
"frequency":1,
"frequency_comparator":"NUM_GT",
"lookback_window":30,
"negate":true,
"child_segments":[
]
},
{
"boolean_operator":"OR",
"child_segments":[
{
"custom_audience_id":"TXR1",
"lookback_window":30,
"child_segments":[
]
},
{
"custom_audience_id":"TYFO",
"frequency":1,
"frequency_comparator":"NUM_GT",
"lookback_window":30,
"negate":true,
"child_segments":[
]
}
]
}
]
}
}
}
]
This is defined in postman.
This is how I am calling it in python:
resource = '/' + '10' + '/batch/accounts/{account_id}/custom_audiences'.format(account_id=account_id)
headers = {'Content-type': 'application/json'}
params = request.get_json
response = Request(client, 'post', resource, headers=headers, params=params).perform()
The error returned is :
<BadRequest object at 0x109055520 code=400 details=[{‘code’: ‘INVALID’, ‘message’: ‘The JSON string format is invalid’}]>
Hey @_mshariff
Interesting, have you tried changing this line:
response = Request(client, 'post', resource, headers=headers, params=params).perform()
to something like
response = Request(client, 'post', resource, headers=headers, body=params).perform() ?
Thanks!
Hi @imit8me,
Thank you for your response. This still returns the same error message
Hi @imit8me
Any idea on where the issue with this could be.