Skip to content

Instantly share code, notes, and snippets.

@davidtsadler
Created August 15, 2014 11:51
Show Gist options
  • Save davidtsadler/ed6aefd59f4ac882cdcd to your computer and use it in GitHub Desktop.
Save davidtsadler/ed6aefd59f4ac882cdcd to your computer and use it in GitHub Desktop.
GeteBayDetails example.
<?php
require __DIR__.'/vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
$sites = array(
array('id' => Constants\SiteIds::US, 'name' => 'United States'),
array('id' => Constants\SiteIds::ENCA, 'name' => 'Canada (English)'),
array('id' => Constants\SiteIds::GB, 'name' => 'UK'),
array('id' => Constants\SiteIds::AU, 'name' => 'Australia'),
array('id' => Constants\SiteIds::AT, 'name' => 'Austria'),
array('id' => Constants\SiteIds::FRBE, 'name' => 'Belgium (French)'),
array('id' => Constants\SiteIds::FR, 'name' => 'France'),
array('id' => Constants\SiteIds::DE, 'name' => 'Germany'),
array('id' => Constants\SiteIds::MOTORS, 'name' => 'Motors'),
array('id' => Constants\SiteIds::IT, 'name' => 'Italy'),
array('id' => Constants\SiteIds::NLBE, 'name' => 'Belgium (Dutch)'),
array('id' => Constants\SiteIds::NL, 'name' => 'Netherlands'),
array('id' => Constants\SiteIds::ES, 'name' => 'Spain'),
array('id' => Constants\SiteIds::CH, 'name' => 'Switzerland'),
array('id' => Constants\SiteIds::HK, 'name' => 'Hong Kong'),
array('id' => Constants\SiteIds::IN, 'name' => 'India'),
array('id' => Constants\SiteIds::IE, 'name' => 'Ireland'),
array('id' => Constants\SiteIds::MY, 'name' => 'Malaysia'),
array('id' => Constants\SiteIds::FRCA, 'name' => 'Canada (French)'),
array('id' => Constants\SiteIds::PH, 'name' => 'Philippones'),
array('id' => Constants\SiteIds::PL, 'name' => 'Poland'),
array('id' => Constants\SiteIds::SG, 'name' => 'Singapore'),
);
foreach($sites as $site) {
getDetails($site);
}
function getDetails($site)
{
$service = new Services\TradingService(array(
'apiVersion' => '881',
'siteId' => $site['id']
));
$request = new Types\GeteBayDetailsRequestType();
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = '<PRODUCTION AUTH TOKEN>';
$request->DetailName = array('ShippingCarrierDetails');
$response = $service->geteBayDetails($request);
if ($response->Ack !== 'Success') {
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("Error: %s\n", $error->ShortMessage);
}
}
} else {
printf("---------------------------\n%s [%s]\n\n", $site['name'], $site['id']);
if (count($response->ShippingCarrierDetails)) {
foreach($response->ShippingCarrierDetails as $details) {
echo $details->ShippingCarrier."\n";
}
} else {
print("No details found\n");
}
print("\n---------------------------\n");
}
}
@3zzy
Copy link

3zzy commented Jun 22, 2016

I get an error with this:

Fatal error: Uncaught InvalidArgumentException: Cannot read credentials from /Users/myname/.ebay_sdk/credentials in /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/Credentials/CredentialsProvider.php:132 Stack trace: #0 /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/Credentials/CredentialsProvider.php(83): DTS\eBaySDK\Credentials\CredentialsProvider::DTS\eBaySDK\Credentials\{closure}() #1 /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/Credentials/CredentialsProvider.php(58): DTS\eBaySDK\Credentials\CredentialsProvider::DTS\eBaySDK\Credentials\{closure}() #2 /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/functions.php(61): DTS\eBaySDK\Credentials\CredentialsProvider::DTS\eBaySDK\Credentials\{closure}() #3 /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/ConfigurationResolver.php(55): DTS\eBaySDK\applyCredentials(Object(Closure), Array) #4 /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/Services/BaseService.php(52): DTS\eBaySDK\ConfigurationResolver->resolve(Arr in /Users/myname/workdir/vendor/dts/ebay-sdk-php/src/Credentials/CredentialsProvider.php on line 132

@3zzy
Copy link

3zzy commented Jun 22, 2016

A small modification makes it work:

$service = new Services\TradingService([
      'authToken'   => $config['production']['authToken'],
      'credentials' => [
         'appId'  => $config['production']['credentials']['appId'],
         'certId' => $config['production']['credentials']['certId'],
         'devId'  => $config['production']['credentials']['devId']
      ],
      'siteId'      => $site['id']
    ]);

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment