Hello everyone!,
I am trying to communicate to eBay with there SOAP API, using the ext/soap of PHP. This is my first real time programming SOAP, but from the docs I thought I understood it all, I have worked with SOAP XML docs before...
Basically I have read so many things when I was trying to fix this problem, I don't even being to understand what is going on anymore. It seems like there are so many different ways to do 'right'... Let me throw you my questions first, "Can you provide me with a some sort of tutorial that will show me how to interface with ext/soap in the way that will work for my task, and/or provide me with a simple example of working commented code so that I can better understand how a full working piece comes together?" Though one thing I do ask, please don't just throw the answer at me, I really want to learn how this all works, I love steeping on problems .
OK so now for the requirements!, I know what SOAP XML document I need it needs to look like this:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<api:RequesterCredentials soapenv:mustUnderstand="0" xmlns:api="urn:ebay:api:eBayAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
<ebl:eBayAuthToken></ebl:eBayAuthToken>
<ebl:Credentials>
<eblevId>[DevID]</eblevId>
<ebl:AppId>[AppID]</ebl:AppId>
<ebl:AuthCert>[CertID]</ebl:AuthCert>
<ebl:Username>[Username]</ebl:Username>
<eblassword>[Password]</eblassword>
</ebl:Credentials>
</api:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<GetRuNameRequest xmlns="urn:ebay:api:eBayAPI">
<Version xmlns="urn:ebay:apis:eBLBaseComponents">433</Version>
<ClientUseCase xmlns="urn:ebay:apis:eBLBaseComponents">GigaDeal</ClientUseCase>
</GetRuNameRequest>
</soapenv:Body>
</soapenv:Envelope>
This is the PHP code that I thought would do the trick:
class ebay_Credentials
{
private $DevID;
private $AppID;
private $CertID;
private $Username;
private $Password;
function __construct($_DevID, $_AppID, $_CertID, $_Username, $_Password)
{
$this->DevID = new SOAPVar($_DevID, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->AppID = new SOAPVar($_AppID, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->CertID = new SOAPVar($_CertID, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->Username = new SOAPVar($_Username, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->Password = new SOAPVar($_Password, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
}
}
class ebay_Auth
{
private $Credentials;
private $eBayAuthToken;
function __construct($_DevID, $_AppID, $_CertID, $_Username, $_Password)
{
$credentials = new ebay_Credentials($_DevID, $_AppID, $_CertID, $_Username, $_Password);
$this->Credentials = new SOAPVar($credentials, SOAP_ENC_OBJECT,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
}
}
class ebay_Soap
{
private $header;
private $client;
function __construct($wsdl, $_DevID, $_AppID, $_CertID, $_Username, $_Password)
{
$auth = new ebay_Auth($_DevID, $_AppID, $_CertID, $_Username, $_Password);
$this->header = new SoapHeader('urn:ebay:api:eBayAPI', 'RequesterCredentials', $auth, 0);
$this->client = new SoapClient($wsdl, array('trace' => 1));
}
function __GetRuName($suffix)
{
$data = array('Version' => new SoapVar(433, XSD_STRING, null, null, null, 'urn:ebay:apis:eBLBaseComponents'),
'ClientUseCase' => new SoapVar($suffix, XSD_STRING, null, null, null, 'urn:ebay:apis:eBLBaseComponents'));
return $this->client->__soapCall('GetRuName', $data, null, $this->header);
}
}
$test = new ebay_Soap('http://developer.ebay.com/webservices/latest/eBaySvc.wsdl',
'[DevID]',
'[AppID]',
'[CertID]',
'[Username]',
'[Password]');
$result = $test->__GetRuName(null);
print htmlspecialchars($test->__getLastRequest());
print_r($result);
But that results in:
Fatal error: Uncaught SoapFault exception: [soapenv:Server.userException] com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled. in /var/www/htdocs/workspace/jc/index.php:61 Stack trace: #0 /var/www/htdocs/workspace/jc/index.php(61): SoapClient->__soapCall('GetRuName', Array, NULL, Object(SoapHeader)) #1 /var/www/htdocs/workspace/jc/index.php(73): ebay_Soap->__GetRuName(NULL) #2 {main} thrown in /var/www/htdocs/workspace/jc/index.php on line 61
What am I doing wrong here, it makes sense to me .
Also I would wonder how you would make a child element for say: 'ClientUseCase', of course being able to define it's namespace.
Thanks for your time, and I truly appreciate any help you can provide!
Thanks!
- Andrew BalmosI was able to find the solution with the ebay developer, codebase section.
What I was missing was the following two things:
1) The SoapHeader needed to be in a array:
$this->header = new SoapHeader('urn:ebay:api:eBayAPI', 'RequesterCredentials', $auth, 0);
in the ebay_Soap __construct should have been:
$this->header = array(new SoapHeader('urn:ebay:api:eBayAPI', 'RequesterCredentials', $auth, 0));
Also I need to build a location option for the __soapCall option's:
return $this->client->__soapCall('GetRuName', $data, null, $this->header);
should have been changed to and the new code added to:
$query = http_build_query(array('callname' => 'GetRuName','siteid' => 0,'version' => 433,'appid' => '[appid]', 'Routing' => 'default'));
$location = "https://api.sandbox.ebay.com/wsapi?{$query}";
$result = $this->client->__soapCall('GetRuName', array($data), array('location' => $location), $this->header);
return $result;
Andrew
I am trying to communicate to eBay with there SOAP API, using the ext/soap of PHP. This is my first real time programming SOAP, but from the docs I thought I understood it all, I have worked with SOAP XML docs before...
Basically I have read so many things when I was trying to fix this problem, I don't even being to understand what is going on anymore. It seems like there are so many different ways to do 'right'... Let me throw you my questions first, "Can you provide me with a some sort of tutorial that will show me how to interface with ext/soap in the way that will work for my task, and/or provide me with a simple example of working commented code so that I can better understand how a full working piece comes together?" Though one thing I do ask, please don't just throw the answer at me, I really want to learn how this all works, I love steeping on problems .
OK so now for the requirements!, I know what SOAP XML document I need it needs to look like this:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<api:RequesterCredentials soapenv:mustUnderstand="0" xmlns:api="urn:ebay:api:eBayAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
<ebl:eBayAuthToken></ebl:eBayAuthToken>
<ebl:Credentials>
<eblevId>[DevID]</eblevId>
<ebl:AppId>[AppID]</ebl:AppId>
<ebl:AuthCert>[CertID]</ebl:AuthCert>
<ebl:Username>[Username]</ebl:Username>
<eblassword>[Password]</eblassword>
</ebl:Credentials>
</api:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<GetRuNameRequest xmlns="urn:ebay:api:eBayAPI">
<Version xmlns="urn:ebay:apis:eBLBaseComponents">433</Version>
<ClientUseCase xmlns="urn:ebay:apis:eBLBaseComponents">GigaDeal</ClientUseCase>
</GetRuNameRequest>
</soapenv:Body>
</soapenv:Envelope>
This is the PHP code that I thought would do the trick:
class ebay_Credentials
{
private $DevID;
private $AppID;
private $CertID;
private $Username;
private $Password;
function __construct($_DevID, $_AppID, $_CertID, $_Username, $_Password)
{
$this->DevID = new SOAPVar($_DevID, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->AppID = new SOAPVar($_AppID, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->CertID = new SOAPVar($_CertID, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->Username = new SOAPVar($_Username, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
$this->Password = new SOAPVar($_Password, XSD_STRING,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
}
}
class ebay_Auth
{
private $Credentials;
private $eBayAuthToken;
function __construct($_DevID, $_AppID, $_CertID, $_Username, $_Password)
{
$credentials = new ebay_Credentials($_DevID, $_AppID, $_CertID, $_Username, $_Password);
$this->Credentials = new SOAPVar($credentials, SOAP_ENC_OBJECT,
null, null, null, 'urn:ebay:apis:eBLBaseComponents');
}
}
class ebay_Soap
{
private $header;
private $client;
function __construct($wsdl, $_DevID, $_AppID, $_CertID, $_Username, $_Password)
{
$auth = new ebay_Auth($_DevID, $_AppID, $_CertID, $_Username, $_Password);
$this->header = new SoapHeader('urn:ebay:api:eBayAPI', 'RequesterCredentials', $auth, 0);
$this->client = new SoapClient($wsdl, array('trace' => 1));
}
function __GetRuName($suffix)
{
$data = array('Version' => new SoapVar(433, XSD_STRING, null, null, null, 'urn:ebay:apis:eBLBaseComponents'),
'ClientUseCase' => new SoapVar($suffix, XSD_STRING, null, null, null, 'urn:ebay:apis:eBLBaseComponents'));
return $this->client->__soapCall('GetRuName', $data, null, $this->header);
}
}
$test = new ebay_Soap('http://developer.ebay.com/webservices/latest/eBaySvc.wsdl',
'[DevID]',
'[AppID]',
'[CertID]',
'[Username]',
'[Password]');
$result = $test->__GetRuName(null);
print htmlspecialchars($test->__getLastRequest());
print_r($result);
But that results in:
Fatal error: Uncaught SoapFault exception: [soapenv:Server.userException] com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled. in /var/www/htdocs/workspace/jc/index.php:61 Stack trace: #0 /var/www/htdocs/workspace/jc/index.php(61): SoapClient->__soapCall('GetRuName', Array, NULL, Object(SoapHeader)) #1 /var/www/htdocs/workspace/jc/index.php(73): ebay_Soap->__GetRuName(NULL) #2 {main} thrown in /var/www/htdocs/workspace/jc/index.php on line 61
What am I doing wrong here, it makes sense to me .
Also I would wonder how you would make a child element for say: 'ClientUseCase', of course being able to define it's namespace.
Thanks for your time, and I truly appreciate any help you can provide!
Thanks!
- Andrew BalmosI was able to find the solution with the ebay developer, codebase section.
What I was missing was the following two things:
1) The SoapHeader needed to be in a array:
$this->header = new SoapHeader('urn:ebay:api:eBayAPI', 'RequesterCredentials', $auth, 0);
in the ebay_Soap __construct should have been:
$this->header = array(new SoapHeader('urn:ebay:api:eBayAPI', 'RequesterCredentials', $auth, 0));
Also I need to build a location option for the __soapCall option's:
return $this->client->__soapCall('GetRuName', $data, null, $this->header);
should have been changed to and the new code added to:
$query = http_build_query(array('callname' => 'GetRuName','siteid' => 0,'version' => 433,'appid' => '[appid]', 'Routing' => 'default'));
$location = "https://api.sandbox.ebay.com/wsapi?{$query}";
$result = $this->client->__soapCall('GetRuName', array($data), array('location' => $location), $this->header);
return $result;
Andrew