Matching return values. Reference ids when creating new objects through API?

29 views
Skip to first unread message

workd...@gmail.com

unread,
Nov 1, 2016, 4:45:36 PM11/1/16
to AdWords API Forum
I am building an application that creates campaigns, adgroups, keywords and ads through the API.

My application has a local representation of these things. i.e. I have a database tables which contains campaigns/adwords etc.

The problem: It is difficult to update my local models with the return values.

To illustrate:
  1. I create a 10 adgroups using "AdGroupService".
  2. I want to save the adgroupIds returned from the API to my database.
  3. I need to match the returned adGroup to my local model.
Ideal solution, if the API has a "referenceId" for each operand:
  1. When creating the AdGroupOperation, allow a referenceId to be specified.
  2. When returning the value after execution, include the referenceId value.
  3. This allows me to map what I sent out to what I get back. So I can save the result back into my models.
How I am working around this:
  1. I am using adgroup name or matching individual properties one by one.
Can anyone suggest a better method to working around this?
Or can someone from Google provide an ideal solution for this problem?

Shwetha Vastrad (AdWords API Team)

unread,
Nov 1, 2016, 5:29:58 PM11/1/16
to AdWords API Forum
Hi,

When you perform a mutate request, if it is successful, the response contains the mutated entities in the same order in which they were passed in the request. You could use this to map the entities to your database. But mapping using AdGroupName and CampaignId is a better option. AdGroups with duplicate names cannot exist in a campaign, so you can use the AdGroupName and CampaignId pair to sync the results back to your database. 

Regards,
Shwetha, AdWords API Team.

workd...@gmail.com

unread,
Nov 3, 2016, 12:16:08 PM11/3/16
to AdWords API Forum
Hi,

Good to know it's returned in order. 

1. Is the solution still valid if there is partial failure? e.g. I perform a mutate request with 5 operations and the third operation results in error.

2. Regarding the example with AdGroupName and CampaignId, how about AdGroupAds and keywords within adgroups? 
Ads in particular are tricky if duplicate ad text is allowed.

Shwetha Vastrad (AdWords API Team)

unread,
Nov 3, 2016, 3:12:53 PM11/3/16
to AdWords API Forum
Hi,

This is still valid if you have set the partialFailure header to true. If this header is set to false or unset, a failure of one operation will result in none of the operations to be committed. If the partialFailure header is set to true, the successful operations are returned in the same order as in the request and the fieldPath in the partialFailureErrors will indicate the index of the operation that failed. 

When an AdGroup has a keyword with a particular text and matchType, if you try to add a keyword with the same combination of text and matchType, you'll not encounter an error and the existing keyword will be updated with the values provided in the request. It's not the same with AdGroupAds. Ads with the duplicate descriptions are allowed. If this is a scenario you're likely to encounter, I would suggest using the ordering in the response to map to your database. 
Reply all
Reply to author
Forward
0 new messages