Search code examples
phpsoapsoap-clientsoapheader

PHP Soap - Authentication header missing


I have been using an API for a WMS which has updated to include authentication headers. I have been provided some required details but have been unable to sucessfully use the API. I have asked the developers but they are unable to help as they do not use PHP.

Previous to the last update, this would work:

$wsdl = URL_HERE;
$soapClient = new SoapClient($wsdl);
$params = array('customer' => $get_users_company->custcode_code);
$response = $soapClient->GetProducts($params);

With the authentification headers, this is what I currently have which is causing the error Authentication header missing

$wsdl = URL_HERE;
$ns = NAMESPACE_HERE;

$soapClient = new SoapClient($wsdl);
$headerbody = array('ID' => 'PROVIDED_ID_HERE', 'KEY' => 'PROVIDED_KEY_HERE');
$headers = new SOAPHeader($ns, 'AuthHeader', $headerbody);
$soapClient->__setSoapHeaders($headers);

$response = $soapClient->__soapCall("GetProducts", array('customer' => $get_users_company->custcode_code));

I'm not 100% sure I am doing this correctly, but without the last line, I get no errors and the page loads fine (No results). Am I correct in thinking the headers are being sent?


Solution

  • I have heard the good old, "we can't help because we are XML Gods and your little php is beneath us"...but you can still get technical support from them by speaking their XML language. Dump out your actual, raw XML and communicate with them using that - don't mention PHP.

    Follow the example here and get your request. Make sure it is matching what the documentation of your API is requesting. If it is, call your technical support and show them your XML. If it isn't, then, you know what you need to fix.