LineItemService - getLineItemsByStatement - Python help - multiple criteria

47 views
Skip to first unread message

Todd Guill

unread,
Jan 4, 2023, 2:54:42 PM1/4/23
to Google Ad Manager API Forum
I have been asked to replicate a report that can't be run in GAM due to the number of lines that would be returned.
I am trying to munge the existing API examples but am lost at the moment. :)

I am trying to get all line items that are not archived and are any of multiple statuses.
The following code is throwing an error asking about commas so I am sure it is completely wrong.

def main(client):
  # Initialize appropriate service.
  line_item_service = client.GetService('LineItemService', version='v202202')
  # Create a statement to select line items.
  statement = (ad_manager.StatementBuilder(version='v202202')
               Where('isArchived = :isArchived')
               IN status('delivering', 'inactive', 'paused', 'ready')
               WithBindVariable('isArchived', False))

And we would like to return a list with 
Order name, line item name, line item Id, start date, end date, and custom targeting
I started with this but it is probably wrong :)

  while True:
    response = line_item_service.getLineItemsByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for line_item in response['results']:
        # Print out some information for each line item.
        print(('Line ID "%d"|name "%s"|startDateTime "%s"|endDateTime "%s"|customTargeting "%s"\n' %
              (line_item['id'], line_item['name'],line_item['startDate'], line_item['endDate'],line_item['customTargeting'])))
      statement.offset += statement.limit
    else:
      break

I appreciate the help.

Ad Manager API Forum Advisor

unread,
Jan 4, 2023, 4:38:21 PM1/4/23
to todd....@dotdashmdp.com, google-doubleclick...@googlegroups.com
Hi Todd,

Thank you for reaching out to the Ad Manager API support team. I am Madhushree and will be assisting you.

I have understood that you are facing an error while retrieving a lineitem from API, to analyse this further can you please provide us with the following details.
  • Network Code
  • User Email
  • Complete SOAP request and response logs of the request which you received an error (SOAP logging must be enabled)
You can send them via Reply privately to the author option, or a direct private reply to this email. 

Regards,
Google Logo
Madhushree
Ad Manager API Team
 

 

ref:_00D1U1174p._5004Q2hZh61:ref
Reply all
Reply to author
Forward
0 new messages