PHP API Soap Header Authentication

549 views Asked by At

I have a small problem which I can't solve. I'm trying to connect to a SOAP API (criteo) which works fine with SoapUI. When I try to replicate the logic in e.g. php I get auth. errors. I'm pretty sure that the header information are not passed correctly (I tried already several solutions which I found here without any result).

This is the request in SoapUI:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v20="https://advertising.criteo.com/API/v201010">
   <soapenv:Header>
      <v20:apiHeader>
         <v20:authToken>12345</v20:authToken>
         <v20:appToken>123456</v20:appToken>
      </v20:apiHeader>
   </soapenv:Header>
   <soapenv:Body>
      <v20:getReportDownloadUrl>
         <v20:jobID>12345</v20:jobID>
      </v20:getReportDownloadUrl>
   </soapenv:Body>
</soapenv:Envelope>

In php I created the header like that:

/*
 * wsdl: https://advertising.criteo.com/API/v201010/AdvertiserService.asmx?WSDL
 */
    $authTokens = new stdClass();
    $authTokens->authToken = 12345;
    $authTokens->appToken = '123456';

    $header =  new SoapHeader('https://advertising.criteo.com/API/v201010/AdvertiserService.asmx', "apiHeader", $authTokens, true);
    $client->__setSoapHeaders(array($header));

    print_r($client->getAccount());

When I run the script I'll get an error:

Uncaught SoapFault exception: [soap:Receiver] Server was unable to process request. ---> Unable to cast object of type 'System.Web.Services.Protocols.SoapUnknownHeader' to type 'Criteo.WebService.DataModel.apiHeader'

Can somebody give me a hint ? Thanks for the help.

1

There are 1 answers

0
glukkkk On