twitter-python-ads-sdk
twitter-python-ads-sdk copied to clipboard
A minimum of 1 items must be provided for categories
When updating a line item, I see a response from the like the following:
{
"operation_errors": [
[
{
"code": "INVALID_PARAMETER",
"message": "A minimum of 1 items must be provided for categories",
"parameter": "categories"
}
]
],
"request": [
{
"operation_type": "Update",
"params": {
"account_id": "...",
"bid_amount_local_micro": 290000,
"bid_type": "MAX",
"include_sentiment": "ALL",
"line_item_id": "adagr",
"name": "...",
"optimization": "DEFAULT"
}
}
]
}
Are categories actually required to update a bid on a line item? If this isn't a bug, is there some documentation surrounding this? It appears that categories are not required to be set when working in the web app.
Looks like this error may be returned when the placement for a line_item is set to PUBLISHER_NETWORK and a category is not set.
Thanks, @josephtyler! I was just going to open an issue for this exact thing.
Repro:
>>> from twitter_ads.client import Client
>>> from twitter_ads.campaign import LineItem
>>> ...
>>> client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
>>> account = client.accounts(ACCOUNT_ID)
>>> line_item = LineItem(account).load(account, 'a7bs8')
>>> line_item.name
u'Untitled'
>>> line_item.name = 'add a name'
>>> line_item.save()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jshishido/.virtualenvs/adsapi/lib/python2.7/site-packages/twitter_ads/resource.py", line 200, in save
resource, params=self.to_params()).perform()
File "/Users/jshishido/.virtualenvs/adsapi/lib/python2.7/site-packages/twitter_ads/http.py", line 72, in perform
raise Error.from_response(response)
twitter_ads.error.BadRequest: <BadRequest object at 0x10f091690 code=400 details=[{u'message': u'A minimum of 1 items must be provided for categories', u'code': u'INVALID_PARAMETER', u'parameter': u'categories'}]>
Looks like this happens because we send all of the line item attributes in the update request and categories is empty:
response = Request(
self.account.client, method,
resource, params=self.to_params()).perform()
(Note: this is using twitter-ads 1.2.2, which hasn't yet been updated for v2, which is why we see paused instead of entity_status.)
>>> line_item.to_params()
{
'bid_type':u'MAX',
'name':'add a name',
'bid_amount_local_micro':10000000,
'created_at': u'2017-10-21T15:57:13Z',
'campaign_id':u'9qpme',
'bid_unit':u'ENGAGEMENT',
'updated_at': u'2017-10-21T16:45:43Z',
'paused':'true',
'charge_by':u'ENGAGEMENT',
'optimization':u'DEFAULT',
'placements':'TWITTER_TIMELINE',
'objective':u'TWEET_ENGAGEMENTS',
'product_type':u'PROMOTED_TWEETS',
'include_sentiment':u'POSITIVE_ONLY',
'id':u'a7bs8',
'categories':''
}
cc: @jbabichjapan, @tushdante
Looks like #119 attempts to address this.