Hi Andy,

I suspect that either you are sending a wrong id (may be keyword ids
getting mixed with a local database id), or that the keywords do not
belong to the right adgroup. One way to troubleshoot this would be to
download a keyword performance report as shown in
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/Examples/v201003/AddKeywordsPerformanceReportDefinition.cs
and then use its ids to see if the ids you are sending to the server
are valid. If you don't specify the adgroup in this code example, then
it will download keywords for the entire account.

You might also want to look at the following improvements for your
code snippet (though not related to the problem itself):

- Instead of constructing an AdGroupCriterion, you might want to
construct a BiddableAdGroupCriterion or NegativeAdGroupCriterion. This
way, you won't need to provide a fake matchType or keyword text for
your requests while deleting the keyword. See
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/Examples/v201003/DeleteAdGroupCriterion.cs
for a code example that deletes a keyword.

- AdWordsUser can keep track of individual operations and the API
costs, so you can probably use AdWordsUser.GetUnitsForLastOperation to
keep track of API cost instead of calculating it yourself. See
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/src/lib/AdWordsUser.cs#120
for details. Note that you need to enable the ApiUnitsExtension in
App.config to be able to use this method. See
http://code.google.com/p/google-api-adwords-dotnet/source/browse/trunk/src/App.config#53
for details.

Cheers,
Anash P. Oommen,
AdWords API Advisor.

On Jul 30, 12:42 pm, Adwords Beginner <adwo...@dealersolutions.com.au>
wrote:
> Our in-house AdWords Client will update keywords by removing them
> first then create new ones, as I understand AdWords does not support
> updating text of existing keywords.
>
> The local database stores the Google keyword IDs when creating
> keywords at AdWords. When deleting, the client will send Google
> keyword IDs. From time to time, among 3,300 Google keyword IDs sent,
> AdWords might complain around 10 of them as Invalid by returning
> EntityNotFound error.
>
> The codes of removing is like this:
>
>         public static bool RemoveKeywords(IEnumerable<KeywordItem>
> items)
>         {
>             if (items == null)
>                 return true;
>
>             if (items.Count() == 0)
>                 return true;
>
>             List<AdGroupCriterionOperation> operations = new
> List<AdGroupCriterionOperation>(items.Count());
>             foreach (KeywordItem item in items)
>             {
>                 Keyword keyword = new Keyword();
>                 keyword.id = item.Id;
>                 keyword.idSpecified = true;
>
>                 keyword.matchType = KeywordMatchType.PHRASE;
>                 keyword.matchTypeSpecified = true;
>                 keyword.text = "Anything for removing";
>                 ///The KeywordId is a 64-bit integer, and apparently
> is a hash of the keyword text.
>                 ///While by priciple deleting a keyword needs only
> AdGroupId and KeywordId, however,
>                 ///the API expects Keyword Match Type and Keyword
> Text, which in fact can be anything
>                 ///without matching the keyword being deleted.
> Apparently this is a flaw in the API.
>
>                 AdGroupCriterion keywordCriterion = new
> AdGroupCriterion();
>                 keywordCriterion.AdGroupCriterionType = "Keyword";
>                 keywordCriterion.criterion = keyword;
>                 keywordCriterion.adGroupId = item.AdGroupId;
>                 keywordCriterion.adGroupIdSpecified = true;
>
>                 AdGroupCriterionOperation operation = new
> AdGroupCriterionOperation();
>                 operati...@operator = Operator.REMOVE;
>                 operation.operatorSpecified = true;
>                 operation.operand = keywordCriterion;
>                 operations.Add(operation);
>             }
>
>             bool finalResult = false;
>             try
>             {
>                 AdGroupCriterionService adGroupCriterionService =
>
> (AdGroupCriterionService)GlobalSettings.Default.CurrentUser.GetService(AdWo 
> rdsService.v200909.AdGroupCriterionService);
>
> GlobalSettings.Default.APIUnitCostsOfCurrentCampaignOfSession +=
> operations.Count * APIUnitCostsTable.AdGroupCriterion_Remove;
>                 AdGroupCriterionReturnValue result =
> adGroupCriterionService.mutate(
>                     operations.ToArray());
>
>                 if (result != null && result.value != null)
>                 {
>                     foreach (AdGroupCriterion adGroupCriterion in
> result.value)
>                     {
>                         Trace.TraceInformation("Ad group criterion
> with ad group id = '{0}, criterion id = '{1} " +
>                             "and type = '{2}' was deleted.",
> adGroupCriterion.adGroupId,
>                             adGroupCriterion.criterion.id,
> adGroupCriterion.criterion.CriterionType);
>                     }
>                 }
>                 else
>                 {
>                     Trace.TraceWarning("No ad group criteria were
> deleted.\n");
>                 }
>
>                 return true;
>             }
>             catch (AdWordsApiException ex)
>             {
>                 ApiException e = ex.ApiException as ApiException;
>                 List<long> idsInvalid = new List<long>();
>                 foreach (ApiError error in e.errors)
>                 {
>                     EntityNotFound entityError = error as
> EntityNotFound;
>                     if (entityError != null)
>                     {
>                         Trace.TraceWarning("When RemoveKeywords:
> Exception says \"{0}\". The trigger {1} in campaign {2} is in {3}.",
>                             entityError.reason.ToString(),
> entityError.trigger, GlobalSettings.Default.CurrentCampaignName,
> error.fieldPath);
>                         finalResult = true;//this is to resolve legacy
> issue that the keyword was actually deleted sometime ago.
>                         continue;
>                     }
>
>                     Trace.TraceWarning("When RemoveKeywords: Exception
> says \"{0}\". The cause in campaign {1} is in {2}.", error.ToString(),
> GlobalSettings.Default.CurrentCampaignName, error.fieldPath);
>                     finalResult = false;
>                 }
>
>             }
>
>             return finalResult;
>         }
>
> And sometimes I got error log like this:
> 2010-07-30 17:08:04 Warning: When RemoveKeywords: Exception says
> "INVALID_ID". The trigger 18626976346 in campaign Paul XYZ Automation
> is in operations[1179].operand.criterion.id.
> 2010-07-30 17:08:04 Warning: When RemoveKeywords: Exception says
> "INVALID_ID". The trigger 18627217666 in campaign Paul XYZ Automation
> is in operations[1180].operand.criterion.id.
>
> My questions are:
> 1. Are the C# codes above looking OK?
> 2. Is it possible to trace down the Google Keyword IDs at AdWords? And
> how to avoid INVALID_ID error?
>
> Many Thanks
>
> Andy

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to