Hi,
Experiencing an issue with the Python Ads SDK when trying to set `bid_type = ‘AUTO’:
Here’s the code:
remote_object = LineItem.load(self.ad_account, object_id)
remote_object.bid_amount_local_micro = None # Must set to NULL when bid_type is 'AUTO'
remote_object.automatically_select_bid = None # Cannot send both bid_type and automatically_select_bid
remote_object.bid_type = 'AUTO' # Enable automatic bidding
remote_object.save()
Here’s the exception I get back in return though:
<BadRequest object at 0x867c240L code=400 details=[{u\'message\': u\'"bid_amount_local_micro" is a required parameter\', u\'code\':
u\'MISSING_PARAMETER\', u\'parameter\': u\'bid_amount_local_micro\'}]>'}
If I set it to a string, ‘NULL’, I get as you would expect and that I’ve seen in my searches around these community boards:
<BadRequest object at 0x863d240L code=400 details=[{u\'message\': u\'Expected Long, got "NULL" for bid_amount_local_micro\', u\'code\': u\'INVALID_PARAMETER\', u\'parameter\': u\'bid_amount_local_micro\'}]>
I found this bit of code in the Python Twitter SDK in Resource.to_params:
It excludes params that have their value of None - but then how do I send a “NULL”? Well, I tried working around this…
params = remote_object.to_params()
if remote_object.bid_type == 'AUTO':
params['bid_amount_local_micro'] = None
resource_uri = LineItem.RESOURCE.format(account_id=self.ad_account.id, id=remote_object.id)
print params
twitter_request = Request(client, 'put', resource_uri, params=params)
response = twitter_request.perform()
… however, no luck, apparently bid_amount_local_micro isn’t being sent at all still:
<BadRequest object at 0x8642240L code=400 details=[{u\'message\': u\'"bid_amount_local_micro" is a required parameter\', u\'code\':
u\'MISSING_PARAMETER\', u\'parameter\': u\'bid_amount_local_micro\'}]>
But I printed out params before sending, here they all are:
{u'bid_amount_local_micro': None,
'bid_type': u'AUTO',
'bid_unit': u'LINK_CLICK',
'campaign_id': u'snipped'',
'charge_by': u'LINK_CLICK',
'created_at': u'snipped',
'id': u'by request!',
'include_sentiment': u'POSITIVE_ONLY',
'name': u'Test',
'objective': u'WEBSITE_CLICKS',
'optimization': u'WEBSITE_CONVERSIONS',
'paused': 'true',
'placements': 'TWITTER_TIMELINE',
'product_type': u'PROMOTED_TWEETS',
'total_budget_amount_local_micro': 100000000,
'updated_at': u'snipped'}
}
My bid_amout_local_micro is there in the params, but still not being sent. Thankfully the OAuth layer can be logged, so let’s log what OAuth sees beyond the Twitter SDK: (OAuth secrets removed)
Collected params:
[(u'bid_type', u'AUTO'),
(u'name', u'Test'),
(u'created_at', u'snip),
(u'total_budget_amount_local_micro', u'100000000'),
(u'campaign_id', u'snip'),
(u'bid_unit', u'LINK_CLICK'),
(u'updated_at', u'snip'),
(u'paused', u'true'),
(u'charge_by', u'LINK_CLICK'),
(u'optimization', u'WEBSITE_CONVERSIONS'),
(u'objective', u'WEBSITE_CLICKS'),
(u'product_type', u'PROMOTED_TWEETS'),
(u'include_sentiment', u'POSITIVE_ONLY'),
(u'id', u'by request'),
(u'placements', u'TWITTER_TIMELINE'),
(u'account_id', u'by request')]
… my bid_amount_local_micro is gone again!
I tried in one last desperate attempt to set the bid_amount_local_micro to False to no avail - the API still expects a Long.
What’s going on? How can I send a null value through the Python Twitter SDK?