locked
Updating keywords and ads RRS feed

  • Question

  • Hi,

     

    I am trying to update keywords and I need to write code around error handling.

     

    The documentation says:

     

    Microsoft adCenter API supports partial success for methods that manipulate campaigns and orders. Partial success is not supported for order items and ads. If one order item or ad in a batch fails, the entire batch fails.

     

    Partial success is not supported for order items (keywords) and ads. But the sample code shows handling of both successful and error records as well as records that weren’t created. I need to better understand what happens when I update a batch of keywords or ads for the use case when there is an  error in the batch of keywords. What is in the response that I get? Will I get both successful and error results as well as records that weren’t updated or if even one record fails will all the records be returned as error?

     

    Thanks for your help,

    Hari

     

    --

     

    AdCenterOrderItem[] items = new AdCenterOrderItem[1];
     
    // TODO initialize each orderItem to be created
    items[0].Keyword = "test";
    ......
    MyAddOrderItems(items);
     
    // Add OrderItems into adCenter
    void MyAddOrderItems(AdCenterOrderItem items)
    {
       EntityResultType result = AddOrderItems(
    0, orderId, LanguageType.French, items);
     
       //handle the OrderItems created successfully
       foreach(EntitySuccessType created in result.SuccessRow)
       {
          //created.Id is the orderItem ID; 
    //created.Index is the corresponding index into items
          Items[created.Index].Id = created.Id;
     
          //TODO store the orderItem and the ID into database
        }
     
       //handle the OrderItems with errors
       foreach(EntityErrorType failed in result.ErrorRow)
       {
          //failed.Index is the corresponding index into items
          //TODO display error
          DisplayError(Items[failed.Index].Keyword, failed.ErrorCode);
     
          //TODO correct the error
            
          //TODO re-create this orderItem and handle the error
          //can call this piece of code recursively
          MyAddOrderItems(items[failed.index];
       }
     
       //re-create OrderItems that don't have errors or were not created
       int unprocessedCnt = items.Length – 
    result.SuccessRow.Length - result.ErrorRow.Length;
     
       if (unprocessedCnt > 0)
       {
          int index = 0;
          AdCenterOrderItem[] unprocessedItems = new 
    AdCenterOrderItem[unprocessedCnt];
     
          for (int i = 0; i < items.Length; i++)
          {
             boolean match = false;
             foreach(EntitySuccessType created in result.SuccessRow)
             {
                if (created.Index == i)
                {
                   match = true;
                   break;
                }
             }
     
             foreach(EntityErrorType failed in result.ErrorRow)
             {
                if (failed.Index == i)
                {
                   match = true;
                   break;
                }
             }
     
             if (match == false)
             {
                unprocessedItems[index++] = ItemsIdea;   
             }
          }
     
          //make a recursive call
          MyAddOrderItems(unprocessedItems);
          
       }
    }

     

    Wednesday, May 16, 2007 7:43 PM

Answers

  • It seems like the documentation has it backwards...

    Methods with order items support partial success. The entity result type will contains both success rows and failure rows. Methods with campaigns and orders do not support partial success.

    As a heads up I should add that partial success is going to go away in the future, more communication to follow on that.

    Thursday, May 17, 2007 3:19 AM
  • Yes, and then on failure you will know all the items in the batch that caused the failure. But this is future stuff, more details to follow on that later.
    Friday, May 18, 2007 8:51 PM

All replies

  • It seems like the documentation has it backwards...

    Methods with order items support partial success. The entity result type will contains both success rows and failure rows. Methods with campaigns and orders do not support partial success.

    As a heads up I should add that partial success is going to go away in the future, more communication to follow on that.

    Thursday, May 17, 2007 3:19 AM
  • Does that mean that in future it will be either everything in the batch is a success or even if one item fails the entire batch is a failure?

    thanks,
    hari
    Friday, May 18, 2007 5:55 PM
  • Yes, and then on failure you will know all the items in the batch that caused the failure. But this is future stuff, more details to follow on that later.
    Friday, May 18, 2007 8:51 PM