Search code examples
curltwitter

How delete targeting criterion with twurl?


I am trying to use twurl to experiment with the Twitter ads API. I can do GETs pretty well, but trying to POST I am having issues. A simple example is deleteing a targeting_criterion:

twurl -H "https://ads-api.twitter.com" -X POST "/5/batch/accounts/XXXX/targeting_criteria" -d ‘[{"operation_type":"Delete","params":{"targeting_criterion_id":"m08op5"}}]’ 

The response is:

{"errors":[{"code":"UNAUTHORIZED_ACCESS","message":"This request is not properly authenticated"}],"request":{"params":{}}}

I get the same if I use -r instead of -d. But using the same credentials I am able to programatically delete via HTTP. I suspect the error response is masking some other goof I am making.

Thoughts? Suggestions? Thx!


Solution

  • Did you try adding "Content-Type" request header by setting below option for twurl?:

    -A "Content-Type: application/json"

    It is required (See the documentation):

    All parameters are sent in the request body and a Content-Type of application/json is required.

    FYI, we also have a Developer Forum site where you can ask these kinds of questions by having appropriate categories. In this case, it's under the Advertiser Tools and APIs category.