How to avoid ?Internal Error? message when using adCenter API

As in every live system there are many things that can go wrong. Although we put a lot of efforts into ensuring the system is responsive, reliable, with descriptive error messages, there are still cases when we return a generic error message "Internal Error". In these exception cases we look in logs and try to understand what went wrong and how to fix it. “Internal error” usually means “There is a case in application that doesn’t comply with the assumptions we’ve made nor is appropriate to return a descriptive error message and you’ll have to rely on us to fix this for you.” In the case I am going to describe this is not the case – there is a way you can fix things.

In our error logs we found an exception related to desterilizing request header so we’ve investigated possible reasons and found that a SOAP header in the request with duplicate elements could  return the “Internal Error” response.

This is how the wrong SOAP request looks:

    1: <s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
    2:   <s:Header>
    3:     <h:ApplicationToken i:nil="true" xmlns:h="https://adcenter.microsoft.com/api/advertiser/v5" 
    4:                         xmlns:i="https://www.w3.org/2001/XMLSchema-instance"/>
    5:     <h:CustomerAccountId xmlns:h="https://adcenter.microsoft.com/api/advertiser/v5">
    6:       256490
    7:     </h:CustomerAccountId>
    8:     
    9:     <h:DeveloperToken xmlns:h="https://adcenter.microsoft.com/api/advertiser/v5" 
   10:                       xmlns:i="https://www.w3.org/2001/XMLSchema-instance">
   11:       <h:Value>CannotRevealThat</h:Value>
   12:     </h:DeveloperToken>
   13:  
   14:     <h:DeveloperToken xmlns:h="https://adcenter.microsoft.com/api/advertiser/v5" 
   15:                       xmlns:i="https://www.w3.org/2001/XMLSchema-instance">
   16:       <h:Value>CannotRevealThat</h:Value>
   17:     </h:DeveloperToken>
   18:  
   19:     <h:UserCredentials xmlns:h="https://adcenter.microsoft.com/api/advertiser/v5" 
   20:                        xmlns:i="https://www.w3.org/2001/XMLSchema-instance">
   21:       <h:Username>MySuperSecretuserName</h:Username>
   22:       <h:Password>CannotRevealThatAsWell</h:Password>
   23:     </h:UserCredentials>
   24:   </s:Header>
   25:   <s:Body>
   26:     <GetCampaignsByAccountIdRequest xmlns="https://adcenter.microsoft.com/api/advertiser/v5">
   27:       <AccountId>123456</AccountId>
   28:     </GetCampaignsByAccountIdRequest>
   29:   </s:Body>
   30: </s:Envelope>

 

Note that DeveloperToken in SOAP Header is duplicated. In order to return a valid non-error response, all elements in the header should have only one instance.
After removing it, everything is fine and the "Internal Error" message is gone.

Thus we’ve just added one more step in the list when you receive "Internal Error" response:

  1. Capture the SOAP messages (request and response)
  2. Analyze them if they are according MSDN Documentation and check for syntax errors
  3. Check for duplicates in request message header.
  4. If you still see the error, contact our Technical Support team with the error messages. With the messages, we’re able to more quickly troubleshoot your issue.

 

Hope this helps,
Galin Iliev,
SDE, adCenter
https://www.galcho.com/blog