Skip to content

Instantly share code, notes, and snippets.

@davidtsadler
Created June 8, 2016 13:29
Show Gist options
  • Save davidtsadler/2b26c0baf001b3eca5765ad0a3865834 to your computer and use it in GitHub Desktop.
Save davidtsadler/2b26c0baf001b3eca5765ad0a3865834 to your computer and use it in GitHub Desktop.
Getting an item by calling GetSingleItem in the Shopping API using the [eBay SDK for PHP](https://github.com/davidtsadler/ebay-sdk-php)
<?php
require __DIR__.'/vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Shopping\Services;
use \DTS\eBaySDK\Shopping\Types;
use \DTS\eBaySDK\Shopping\Enums;
$service = new Services\ShoppingService([
'credentials' => [
'appId' => 'your-app-id',
'certId' => 'your-cert-id',
'devId' => 'your-dev-id'
],
'siteId' => Constants\SiteIds::GB
]);
$request = new Types\GetSingleItemRequestType();
$request->ItemID = 'your-item-id';
$request->IncludeSelector = 'Details,Description,ShippingCosts';
$response = $service->getSingleItem($request);
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf(
"%s: %s\n%s\n\n",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
$error->ShortMessage,
$error->LongMessage
);
}
}
if ($response->Ack !== 'Failure') {
$item = $response->Item;
printf(
"%s\n%s\n%s\n%s\n%s\n(%s)%.2f\n",
$item->ViewItemURLForNaturalSearch,
$item->ItemID,
$item->Title,
$item->Description,
$item->Quantity,
$item->CurrentPrice->currencyID,
$item->CurrentPrice->value
);
print("Domestic Shipping Information\n");
printf(
"(%s)%.2f\n",
$item->ShippingCostSummary->ShippingServiceCost->currencyID,
$item->ShippingCostSummary->ShippingServiceCost->value
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment