I need some help with the google ad manager API. I am trying to delete a lineitem
with the following:
from googleads import ad_manager
client = ad_manager.AdManagerClient.LoadFromStorage()
def test(id):
line_item_service = client.GetService('LineItemService',version='v202002')
line_item_name = str(id)
statement = (ad_manager.StatementBuilder(version='v202002').Where('OrderId = :OrderId').WithBindVariable('OrderId',app.config['AD_MANAGER']['ORDER_ID']))
response = line_item_service.performLineItemAction(line_item_service.DeleteLineItems(),statement.ToStatement())
My problem lies with DeleteLineItems()
as I am not sure how to call it correctly. I am not able to find clear usage examples, hence my attempt above. Below are the docs I could find. The error of my current attempt is:
{success: false, error: "<class 'googleads.errors.GoogleAdsValueError'>", message: "Service DeleteLineItems not found"}
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService.DeleteLineItems https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction
So I finally found the answer.
The performLineItemAction
takes in 2 parameters. The first one is the LineItemAction
and the second is a Statement
. I found the docs a little confusing because I thought the LineItemAction
was a method of the LineItem
object. It turns out that the first parameter is actually a dictionary.
line_item_service.performLineItemAction({'xsi_type':'ArchiveLineItems'},statement.ToStatement())
As a side note, once a line item is being delivered we cannot delete it. We can either pause it or archive it. In this case I've chosen to archive it. The different types of line item actions can be found here.
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction