Can't change keyword bid in v201302 C# .Net

153 views
Skip to first unread message

road11

unread,
Jun 3, 2013, 2:08:33 PM6/3/13
to adwor...@googlegroups.com
I'm using the sample code pretty much line for line from the v201302 samples published by Google for "UpdateKeyword." It doesn't work. It doesn't throw an error message, but it doesn't change the bid either. I've got a preexisting adgroup and a preexisting keyword and have verified both are correct. I just want to change the bid. Anybody know how (since the sample code seems to be wrong)?

public void Run(AdWordsUser user, long adGroupId, long keywordId) {
      // Get the AdGroupCriterionService.
      AdGroupCriterionService adGroupCriterionService =
          (AdGroupCriterionService) user.GetService(AdWordsService.v201302.AdGroupCriterionService);
 
      // Since we are not updating any keyword-specific fields, it is enough to
      // create a criterion object.
      Criterion criterion = new Criterion();
      criterion.id = keywordId;
 
      // Create ad group criterion.
      BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
      biddableAdGroupCriterion.adGroupId = adGroupId;
      biddableAdGroupCriterion.criterion = criterion;
 
      // Create the bids.
      BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
      CpcBid cpcBid = new CpcBid();
      cpcBid.bid = new Money();
      cpcBid.bid.microAmount = 1000000;
 
      biddableAdGroupCriterion.biddingStrategyConfiguration = biddingConfig;
 
      // Create the operation.
      AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
      operation.@operator = Operator.SET;
      operation.operand = biddableAdGroupCriterion;
 
      try {
        // Update the keyword.
        AdGroupCriterionReturnValue retVal =
            adGroupCriterionService.mutate(new AdGroupCriterionOperation[] {operation});
 
        // Display the results.
        if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
          AdGroupCriterion adGroupCriterion = retVal.value[0];
          long bidAmount = 0;
          foreach (Bids bids in (adGroupCriterion as BiddableAdGroupCriterion).
              biddingStrategyConfiguration.bids) {
            if (bids is CpcBid) {
              bidAmount = (bids as CpcBid).bid.microAmount; /*original bid always comes back; never changes*/
              break;
            }
          }
 
          Console.WriteLine("Keyword with ad group id = '{0}', id = '{1}' was updated with " +
              "bid amount = '{2}' micros.", adGroupCriterion.adGroupId,
              adGroupCriterion.criterion.id, bidAmount);
        } else {
          Console.WriteLine("No keyword was updated.");
        }
      } catch (Exception ex) {
        throw new System.ApplicationException("Failed to update keyword.", ex);
      }
    }


road11

unread,
Jun 4, 2013, 8:16:39 AM6/4/13
to adwor...@googlegroups.com
Just fyi, this operation works in library v201209, but that version will be sunset in July and calls to it won't work after 7/22/13. Really need to get this working, guys.

road11

unread,
Jun 4, 2013, 1:03:41 PM6/4/13
to adwor...@googlegroups.com

Actually, I’ve solved this problem. Your sample code was missing a couple of lines. I went ahead and took the liberty of publishing my solution for other folks who have tripped over the same issue…

https://code.google.com/p/google-api-adwords-dotnet/issues/detail?id=110


Takeshi Hagikura (AdWords API Team)

unread,
Jun 6, 2013, 2:56:12 AM6/6/13
to adwor...@googlegroups.com
Hi, 

Thanks for filing a issue. 
We're fixing that in the next release.

Best,
- Takeshi, AdWords API Team

adw...@webvitamins.com

unread,
Nov 10, 2015, 1:40:11 PM11/10/15
to AdWords API Forum
Was this issue fixed?  I am having the same problem (running v.201509).  And unfortunately the link posted by road11 is returning a 403 Forbidden.

Thanks,
Dave

adw...@webvitamins.com

unread,
Nov 10, 2015, 2:16:01 PM11/10/15
to AdWords API Forum
I've fixed the problem - in the sample code above, the CpcBid is not added to the BiddingStragegyConfiguration's Bids collection.  Here's the missing line:

biddingConfig.bids = new Bids[] { cpcBid };

Reply all
Reply to author
Forward
0 new messages