Twitter ads launching via API even when receiving 400 Bad Request



We recently tried launching an ad with a large number of users specified in the targeting criteria.

We received a 400/Bad request back from our API call, with the detail message:

TwitterAds::BadRequest:0x50533840 code=400 details="[{:code=>“INVALID”, :message=>“Number of Targeted User TargetingCriteria (101) exceeds the limit (100)”, :attribute=>“targeting_type”}]">

Upon checking up on our account at however, we saw the ad we were trying to launch successfully deployed and delivering!

I strongly believe this is a bad bug, as receiving a 400 Bad Request with details of what was wrong with your request is usually not indicative that the request resulted in an operation that will successfully create something on your network, and start spending money.

Please follow up if you would like any additional info that may help you debug.


Thanks for the question, @ampifii. Could you please provide the request you’re making that’s resulting in this error? My assumption is that, in the POST accounts/:account_id/targeting_criteria request, you’re using either FOLLOWERS_OF_USER or SIMILAR_TO_FOLLOWERS_OF_USER, but I’d like to confirm. Awaiting your response.


Correct. For each targeted user, we make the call:

Posting data:
{:line_item_id=>“8nk30”, :targeting_type=>“SIMILAR_TO_FOLLOWERS_OF_USER”, :targeting_value=>“23600234”}

(as an example)


Got it. Thanks, @ampifii. As the error message states, there is a limit of 100 on that targeting type.

Taking a closer look at the targeting on this line item, it looks like there are 101 targeting entities: 1 LOCATION and 100 SIMILAR_TO_FOLLOWERS_OF_USER. After the 400 error, were subsequent targeting criteria requests made on this line item? Or was it just that single request?


I believe we made subsequent requests to add the remaining users. I can replay the requests and check.



Great, thanks! We’ll keep a look out for your reply.



I just looked and we did not make subsequent requests, as we had logic to stop if an error was encountered. That was the last request in our stream for launching the ad.



Very help, @ampifii. Thanks! We’ll work to repro to determine what’s happening.


@ampifii: One more clarifying question. Were you using the POST accounts/:account_id/targeting_criteria or the POST batch/accounts/:account_id/targeting_criteria endpoint?


/accounts/18ce541dt2m/targeting_criteria … NOT the batch version.



Thanks for the clarification, @ampifii.

For the POST endpoint, you set a single targeting criterion at a time. In other words, it’s not possible to specify all 101 in one request (that’s what the batch endpoint is for).

Given that this line item already included 100 SIMILAR_TO_FOLLOWERS_OF_USERs, the 101st request would fail, as it did. That doesn’t mean the 100 previous would be affected.

To reiterate, the POST batch/accounts/:account_id/targeting_criteria endpoint is the way to go. Set targeting in a single request.

I hope this helps clarify. Thanks again.