I’m trying to integrate eBay API in my project.
I use ZendFramework and there is library for eBay FindingAPI, but it doesn’t work for method findItemsByProduct
.
For understanding problem I wrote my small class:
<?php
class MyProject_Model_Ebay
{
const FINDING_API_URL = 'http://svcs.ebay.com/services/search/FindingService/v1?';
private $appId;
public function __construct($appId)
{
$this->appId = $appId;
}
public function findByProduct($id, $type = 'UPC')
{
$params = array(
'productId.@type' => $type,
'productId' => $id,
);
return $this->doApiRequest('findItemsByProduct', $params);
}
public function findByKeywords($keywords)
{
$params = array(
'keywords' => $keywords,
);
return $this->doApiRequest('findItemsByKeywords', $params);
}
private function doApiRequest($operationName, $payload)
{
$global = array(
'OPERATION-NAME' => $operationName,
'SECURITY-APPNAME' => $this->appId,
'GLOBAL-ID' => 'EBAY-US',
'SERVICE-VERSION' => '1.0.0',
'MESSAGE-ENCODING' => 'UTF-8',
'RESPONSE-DATA-FORMAT' => 'JSON',
);
$ret = file_get_contents(
self::FINDING_API_URL . http_build_query($global) . '&REST-PAYLOAD&' . http_build_query($payload)
);
return $ret;
}
}
Method findItemsByKeywords
works OK, but findItemsByProduct
still returns error
Invalid product ID value.
I tried different variants of passing value, but it doesn’t work 🙁 Current version of passing value I saw here: how to use python xml.etree.ElementTree to parse eBay API response?
Usage:
<?php
$eBay = new MyProject_Model_Ebay(
'My-app-id'
);
$eBay->findByProduct('4719331316129');
Response:
{"findItemsByProductResponse":[{"ack":["Failure"],"errorMessage":[{"error":[{"errorId":["41"],"domain":["Marketplace"],"severity":["Error"],"category":["Request"],"message":["Invalid product ID value."],"subdomain":["Search"],"parameter":["4719331316129"]}]}],"version":["1.11.1"],"timestamp":["2012-03-14T06:41:42.600Z"]}]}
Important!
If i change GLOBAL-ID on EBAY-DE, for example, everything is OK! What’s wrong with EBAY-US?!
2
Answers
Seems that you had passed incorrect product ID (itemID instead of ProductID).
$eBay->findByProduct(‘4719331316129’); – 13 digits, when normally ProductId has 8-9 digits
Compare:
The Id you are sending is been treated as the UPC of a product.
The findItemsByProduct requires
productId
type is must be specified while passing product id.
Type can include ISBN, UPC, EAN, or ReferenceID (ePID).
In your case, the ID you are passing is considered as the UPC number. So confirm whether the UPC is correct for that product.