locked
GetAccounts - API unauthorized access RRS feed

  • Question

  • For some reason, I can't seem to get AuthHeader right with GetAccounts.

    PHP
    1// Use either the sandbox or production URI. 
    2// This example is for the sandbox URI. 
    3//$URI = "https://sandboxapi.adcenter.microsoft.com/api/advertiser/v5.1/"; 
    4// The following commented-out line contains the production URI. 
    5$URI = "https://adcenterapi.microsoft.com/api/advertiser/v5.1/"
    6 
    7// The adCenter API namespace. 
    8$xmlns = "https://adcenter.microsoft.com/api/advertiser/v5"
    9 
    10// The proxy for the Campaign Management Web service. 
    11$accountProxy = $URI . "CustomerManagement/CustomerManagement.asmx?wsdl"
    12$campaignProxy = $URI . "Reporting/ReportingService.svc?wsdl"
    13 
    14// Create the SOAP client. 
    15$opts = array('trace' => true); 
    16 
    17 
    18/* Account Request - Doesn't work, API unauthorized access */ 
    19$ApiUserAuthHeader=new ApiUserAuthHeader(); 
    20$ApiUserAuthHeader->UserName=$username
    21$ApiUserAuthHeader->Password=$password
    22$ApiUserAuthHeader->UserAccessKey=$developerTokenValue
    23 
    24$headerApiUserAuthHeader = 
    25    new SoapHeader 
    26    ( 
    27        $xmlns
    28        'ApiUserAuthHeader'
    29        $ApiUserAuthHeader
    30        false 
    31    ); 
    32 
    33$inputHeaders = array($headerApiUserAuthHeader); 
    34 
    35 
    36// The name of the service operation that will be called. 
    37$action = "GetAccounts"
    38 
    39$client = new SOAPClient($accountProxy$opts); 
    40 
    41$params=array('APIFlags'=>0); 
    42 
    43$result = $client->__soapCall($action,array($action.'Request' => $params),null,$inputHeaders,$outputHeaders); 
    44 


    SOAP Request
    1<?xml version="1.0" encoding="UTF-8"?> 
    2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://adcenter.microsoft.com/syncapis" xmlns:ns2="https://adcenter.microsoft.com/api/advertiser/v5"
    3    <SOAP-ENV:Header> 
    4        <ns2:ApiUserAuthHeader> 
    5            <UserName>xxxx</UserName> 
    6            <Password>xxxx</Password> 
    7            <UserAccessKey>xxxx</UserAccessKey> 
    8        </ns2:ApiUserAuthHeader> 
    9    </SOAP-ENV:Header> 
    10    <SOAP-ENV:Body> 
    11        <ns1:GetAccounts> 
    12            <ns1:APIFlags>0</ns1:APIFlags> 
    13        </ns1:GetAccounts> 
    14    </SOAP-ENV:Body> 
    15</SOAP-ENV:Envelope> 

    The username. password and UserAccessKey are exactly the same as used in this example:
    http://adcentercommunity.com/blogs/api/archive/2008/06/02/v5-1-reporting-sample-in-php.aspx

    Which works.



    Any ideas?


    Hackzilla

    Monday, January 5, 2009 10:54 AM

Answers

  • Upon searching some more in the forums, I have found someone with a very similar error.

    http://social.msdn.microsoft.com/Forums/en-US/adcenterdev/thread/22dbce2a-85fc-4f94-ab1c-bccc9b07b41c/

    Jeff suggested it could have been a namespace issue, but it was never confirmed.


    I'd rather get the code working based off msn php example, and not have to resort to raw soap.


    Why is it that GetAccounts has a different way to authorize than KeywordPerformance ?


    Hackzilla
    Monday, January 5, 2009 3:34 PM
  • I have now found there is an example for GetAccounts written in PHP for adcenter v5.1
    Link: http://msdn.microsoft.com/en-us/library/cc764418.aspx

    This example produces the following soap request:

    1<?xml version="1.0" encoding="UTF-8"?> 
    2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://adcenter.microsoft.com/syncapis"
    3    <SOAP-ENV:Header> 
    4        <ns1:ApiUserAuthHeader> 
    5            <ns1:UserName>xxx</ns1:UserName> 
    6            <ns1:Password>xxx</ns1:Password> 
    7            <ns1:UserAccessKey>xxx</ns1:UserAccessKey> 
    8        </ns1:ApiUserAuthHeader> 
    9    </SOAP-ENV:Header> 
    10    <SOAP-ENV:Body> 
    11        <ns1:GetAccounts/> 
    12    </SOAP-ENV:Body> 
    13</SOAP-ENV:Envelope> 
    14 

    This looks closer, but still fails with
    "Server Server was unable to process request. ---> |-400001|-1|API unauthorized access|"


    Hackzilla
    • Edited by Hackzilla Tuesday, January 6, 2009 9:50 AM Added Link
    • Marked as answer by Chris Norred MSFT Thursday, January 8, 2009 1:44 AM
    Monday, January 5, 2009 4:18 PM
  • Hackzilla said:

    I have now found there is an example for GetAccounts written in PHP for adcenter v5.1
    Link: http://msdn.microsoft.com/en-us/library/cc764418.aspx

    This example produces the following soap request:

    1<?xml version="1.0" encoding="UTF-8"?> 
    2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://adcenter.microsoft.com/syncapis"
    3    <SOAP-ENV:Header> 
    4        <ns1:ApiUserAuthHeader> 
    5            <ns1:UserName>xxx</ns1:UserName> 
    6            <ns1:Password>xxx</ns1:Password> 
    7            <ns1:UserAccessKey>xxx</ns1:UserAccessKey> 
    8        </ns1:ApiUserAuthHeader> 
    9    </SOAP-ENV:Header> 
    10    <SOAP-ENV:Body> 
    11        <ns1:GetAccounts/> 
    12    </SOAP-ENV:Body> 
    13</SOAP-ENV:Envelope> 
    14 

    This looks closer, but still fails with
    "Server Server was unable to process request. ---> |-400001|-1|API unauthorized access|"


    Hackzilla


    I have noticed that there seems to be a slighlt error with the example.

    The soap is slightly wrong:
        <SOAP-ENV:Body> 
            <ns1:GetAccounts/> 
        </SOAP-ENV:Body> 

    It should be more like:
        <SOAP-ENV:Body> 
            <ns1:GetAccounts>
                <ns1:APIFlags>0</ns1:APIFlags>
            </ns1:GetAccounts>
        </SOAP-ENV:Body> 

    The line from the example is:
        // Execute the SOAP call. 
        $result = $client->__soapCall 
        ( 
            $action
            array('APIFlags' => 0), 
            null, 
            $authHeader 
        ); 

    It should be:
        // Execute the SOAP call. 
        $params = array('APIFlags'=>0); 
     
        $result = $client->__soapCall 
        ( 
            $action
            array($action.'Request' => $params), 
            null, 
            $authHeader 
        ); 
     


    Hackzilla

    Tuesday, January 6, 2009 10:02 AM
  • I was using the wrong username and password.

    Oh well.


    Hackzilla
    • Marked as answer by Hackzilla Wednesday, January 7, 2009 4:20 PM
    Wednesday, January 7, 2009 4:19 PM
  • The difference you are seeing is related to the version of PHP you are using. The MSDN documentation states the version that successfully works with the associated code. Glad you got it working!

    Jeff Dillon, API Support

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Header>
        <ApiUserAuthHeader xmlns="http://adcenter.microsoft.com/syncapis">
          <UserName>xxxx</UserName>
          <Password>xxxx</Password>
          <UserAccessKey>xxxx</UserAccessKey>
        </ApiUserAuthHeader>
      </soap:Header>
      <soap:Body>
        <GetAccounts xmlns="http://adcenter.microsoft.com/syncapis">
          <APIFlags>0</APIFlags>
        </GetAccounts>
      </soap:Body>
    </soap:Envelope>
    Wednesday, January 7, 2009 8:18 PM

All replies

  • Upon searching some more in the forums, I have found someone with a very similar error.

    http://social.msdn.microsoft.com/Forums/en-US/adcenterdev/thread/22dbce2a-85fc-4f94-ab1c-bccc9b07b41c/

    Jeff suggested it could have been a namespace issue, but it was never confirmed.


    I'd rather get the code working based off msn php example, and not have to resort to raw soap.


    Why is it that GetAccounts has a different way to authorize than KeywordPerformance ?


    Hackzilla
    Monday, January 5, 2009 3:34 PM
  • I have now found there is an example for GetAccounts written in PHP for adcenter v5.1
    Link: http://msdn.microsoft.com/en-us/library/cc764418.aspx

    This example produces the following soap request:

    1<?xml version="1.0" encoding="UTF-8"?> 
    2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://adcenter.microsoft.com/syncapis"
    3    <SOAP-ENV:Header> 
    4        <ns1:ApiUserAuthHeader> 
    5            <ns1:UserName>xxx</ns1:UserName> 
    6            <ns1:Password>xxx</ns1:Password> 
    7            <ns1:UserAccessKey>xxx</ns1:UserAccessKey> 
    8        </ns1:ApiUserAuthHeader> 
    9    </SOAP-ENV:Header> 
    10    <SOAP-ENV:Body> 
    11        <ns1:GetAccounts/> 
    12    </SOAP-ENV:Body> 
    13</SOAP-ENV:Envelope> 
    14 

    This looks closer, but still fails with
    "Server Server was unable to process request. ---> |-400001|-1|API unauthorized access|"


    Hackzilla
    • Edited by Hackzilla Tuesday, January 6, 2009 9:50 AM Added Link
    • Marked as answer by Chris Norred MSFT Thursday, January 8, 2009 1:44 AM
    Monday, January 5, 2009 4:18 PM
  • Hackzilla said:

    I have now found there is an example for GetAccounts written in PHP for adcenter v5.1
    Link: http://msdn.microsoft.com/en-us/library/cc764418.aspx

    This example produces the following soap request:

    1<?xml version="1.0" encoding="UTF-8"?> 
    2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://adcenter.microsoft.com/syncapis"
    3    <SOAP-ENV:Header> 
    4        <ns1:ApiUserAuthHeader> 
    5            <ns1:UserName>xxx</ns1:UserName> 
    6            <ns1:Password>xxx</ns1:Password> 
    7            <ns1:UserAccessKey>xxx</ns1:UserAccessKey> 
    8        </ns1:ApiUserAuthHeader> 
    9    </SOAP-ENV:Header> 
    10    <SOAP-ENV:Body> 
    11        <ns1:GetAccounts/> 
    12    </SOAP-ENV:Body> 
    13</SOAP-ENV:Envelope> 
    14 

    This looks closer, but still fails with
    "Server Server was unable to process request. ---> |-400001|-1|API unauthorized access|"


    Hackzilla


    I have noticed that there seems to be a slighlt error with the example.

    The soap is slightly wrong:
        <SOAP-ENV:Body> 
            <ns1:GetAccounts/> 
        </SOAP-ENV:Body> 

    It should be more like:
        <SOAP-ENV:Body> 
            <ns1:GetAccounts>
                <ns1:APIFlags>0</ns1:APIFlags>
            </ns1:GetAccounts>
        </SOAP-ENV:Body> 

    The line from the example is:
        // Execute the SOAP call. 
        $result = $client->__soapCall 
        ( 
            $action
            array('APIFlags' => 0), 
            null, 
            $authHeader 
        ); 

    It should be:
        // Execute the SOAP call. 
        $params = array('APIFlags'=>0); 
     
        $result = $client->__soapCall 
        ( 
            $action
            array($action.'Request' => $params), 
            null, 
            $authHeader 
        ); 
     


    Hackzilla

    Tuesday, January 6, 2009 10:02 AM
  • I was using the wrong username and password.

    Oh well.


    Hackzilla
    • Marked as answer by Hackzilla Wednesday, January 7, 2009 4:20 PM
    Wednesday, January 7, 2009 4:19 PM
  • The difference you are seeing is related to the version of PHP you are using. The MSDN documentation states the version that successfully works with the associated code. Glad you got it working!

    Jeff Dillon, API Support

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Header>
        <ApiUserAuthHeader xmlns="http://adcenter.microsoft.com/syncapis">
          <UserName>xxxx</UserName>
          <Password>xxxx</Password>
          <UserAccessKey>xxxx</UserAccessKey>
        </ApiUserAuthHeader>
      </soap:Header>
      <soap:Body>
        <GetAccounts xmlns="http://adcenter.microsoft.com/syncapis">
          <APIFlags>0</APIFlags>
        </GetAccounts>
      </soap:Body>
    </soap:Envelope>
    Wednesday, January 7, 2009 8:18 PM
  • Hi Jeff,

    This is not an issue for PHP only, I am using C# code and also faced the same issue so many times in last month and also got same error on 31 Jan 2009, when calling the GetAccounts method. Seems like there is a bug from adCenter side. 

    Parvendra Kumar Rana
    Monday, February 2, 2009 6:46 AM