Working on this for a week now. Having trouble executing this code. I want to retrieve data via SOAP and work with it in PHP. My trouble is, that I am having trouble sending the 'RequesterCredentials'.
I will show the xml code so you all can see the info I am trying to send, and then the PHP code I am using.
XML SAMPLE CODE
POST /AuctionService.asmx HTTP/1.1
Host: apiv2.gunbroker.com
Content-Type: text/xml; charset=utf-8
Content-Length: 200
SOAPAction: "GunBrokerAPI_V2/GetItem"
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<RequesterCredentials xmlns="GunBrokerAPI_V2">
<DevKey>devkey</DevKey>
<AppKey>appkey</AppKey>
</RequesterCredentials>
</soap:Header>
<soap:Body>
<GetItem xmlns="GunBrokerAPI_V2">
<GetItemRequest>
<ItemID>312007942</ItemID>
<ItemDetail>Std</ItemDetail>
</GetItemRequest>
</GetItem>
PHP CODE THAT I AM USING TO MAKE THE CALL
$client = new SoapClient("http://apiv2.gunbroker.com/AuctionService.asmx?WSDL");
$appkey = 'XXXXXX-XXXXXX-XXXXXX';
$devkey = 'XXXXXX-XXXXXX-XXXXXX';
$header = new SoapHeader('GunBrokerAPI_V2','RequesterCredentials',array('DevKey' => $devkey,'AppKey' => $appkey),0);
$client->__setSoapHeaders(array($header));
$result = $client->GetItem('312343077');
echo '<pre>',print_r($result,true),'</pre>';
THE RESULT I GET
stdClass Object
(
[GetItemResult] => stdClass Object
(
[Timestamp] => 2012-11-07T18:17:31.9032903-05:00
[Ack] => Failure
[Errors] => stdClass Object
(
[ShortMessage] => GunBrokerAPI_V2 Error Message : [GetItem]
You must fill in the 'RequesterCredentialsValue' SOAP header for this Web Service method.
[ErrorCode] => 1
)
// the rest if just an array of empty fields that I could retrieve if i wasnt havng problems.
Im not sure if the problem is the way Im sending the SoapHeaders or if I am misunderstanding the syntax. I would greatly appreciate any and all help.
Use object instead of associative array for headers:
$obj = new stdClass();
$obj->AppKey = $appkey;
$obj->DevKey = $devkey;
$header = new SoapHeader('GunBrokerAPI_V2','RequesterCredentials',$obj,0);
And next problem you might face will be at GetItem
call, you allso need object, wrapped in associative array:
$item = new stdClass;
$item->ItemID = '312343077';
$item->ItemDetail = 'Std';
$result = $client->GetItem(array('GetItemRequest' => $item));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.