我创建了一个函数来使用库存API在eBay上创建库存项目. 该脚本从数据库生成一个json,并将其发送到ebay api url. 当我在我的网站上执行该函数时,我得到一个错误,结果没有进一步的信息.
Array
(
[errors] => Array
(
[0] => Array
(
[errorId] => 2004
[domain] => ACCESS
[category] => REQUEST
[message] => Invalid request
[longMessage] => The request has errors. For help, see the documentation for this API.
)
)
)
当我使用API Explorer将相同的json发送到相同的API url时,我得到了一个成功的204结果.
我希望你们有一些提示或解决方案,让这件事运作起来.提前谢谢你.
从我的脚本生成的JSON.您可以复制JSON并将其插入到API资源管理器中,这样它就可以工作了.
{
"product":{
"title":" Original ",
"brand":"Bosch",
"mpn":"A444",
"aspects":{
"Produktart": ["Abschleppkabel"],
"Im Lieferumfang enthalten":["Abschleppkette"],
"Besonderheiten":["Geringe Dehnung"],
"Material":["Kohlenstoffstahl"],
"Zulässige Tragfähigkeit":["100"],
"Geeignet für":["Wohnmobil"],
"Gütesiegel & Kennzeichnungen":["TÜV Rheinland\/GS"],
"Durchmesser":["78 Zoll"],
"Herstellungsland und -region":["Deutschland"],
"Maximale Belastbarkeit":["151 kg"]
},
"description":"TEST",
"imageUrls":["https:\/\/www.eccaro.de\/uploads\/img\/"],
"condition":"USED_EXCELLENT",
"packageWeightAndSize":{
"dimensions":{
"height":"200",
"length":"300",
"width":"100",
"unit":"CENTIMETER"
},
"weight":{
"value":"69",
"unit":"GRAM"
}
},
"availability":{
"shipToLocationAvailability":{
"quantity":2
}
}
}
}
我的功能
function export_part($token_data,$ebay_db,$aspects,$aspect_string,$artbez,$her_name,$hnr,$galurl,$hoehe_part,$laenge_part,$breite_part,$gewicht,$menge,$bestandseinheit){
$headers = array
(
'Authorization: Bearer '. $token_data['TokenValue'],
'Accept:application/json',
'Content-type: application/json',
'Content-Language:de-DE',
);
$url = 'https://api.ebay.com/sell/inventory/v1/inventory_item/'.$bestandseinheit;
echo $url;
//Build JSON
$test->product->title = $artbez;
$test->product->brand = "Bosch";
$test->product->mpn = $hnr;
$aspect_string;
foreach($aspects as $key => $aspect){
if($aspect == 'NOTSET'){
}else{
$test->product->aspects->$key[0] = $aspect;
}
}
$test->product->description = "TEST";
$test->product->imageUrls[0] = $galurl;
$test->product->condition = "USED_EXCELLENT";
$test->product->packageWeightAndSize->dimensions->height = $hoehe_part;
$test->product->packageWeightAndSize->dimensions->length = $laenge_part;
$test->product->packageWeightAndSize->dimensions->width = $breite_part;
$test->product->packageWeightAndSize->dimensions->unit = "CENTIMETER";
$test->product->packageWeightAndSize->weight->value = $gewicht;
$test->product->packageWeightAndSize->weight->unit = "GRAM";
$test->product->availability->shipToLocationAvailability->quantity = $menge;
$test = json_encode($test,JSON_UNESCAPED_UNICODE);
echo "<pre>";
echo $test;
echo "</pre>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $test);
$data = curl_exec($ch);
curl_close($ch);
$response = json_decode($data, true);
print_r('<pre>');
print_r($response);
print_r('</pre>');
return $response;
}
反馈到 comments ADYSON
我将API Explorer与以下内容一起使用.
Web服务URI(终结点) https://api.ebay.com/sell/inventory/v1/inventory_item/12345678个
HTTP标头
Authorization:Bearer
Accept:application/json
Content-Type:application/json
Content-Language:de-DE
请求主体
从头开始精确定位JSON
站点ID:77 Select 接口:盘点接口 Select 一个API调用:createOrReplaceInventoryItem Advanced
呼叫响应 状态:204无内容时间:1670毫秒
响应标头
x-ebay-c-request-id:ri=OQyFByKejb%2Fh,rci=0a2960442f6ba7ba
rlogid:t6pitnmsgwj70%3D9vjdpitnmsgwj70*iflek%28rbpv6775-18cf427b8db-0x178
x-ebay-c-version:1.0.0
content-language:de-DE
x-ebay-client-tls-version:TLSv1.3
x-ebay-request-id:18cf427b-8db0-a49e-b4a6-19abf6872fae!inventory_item_PUT!slcslrinvapi26-jcjbh-tess0040.stratus.slc.ebay.com!r1slrinvapi26[]
set-cookie:ebay=%5Esbf%3D%23%5E;Domain=.ebay.com;Path=/; Secure
content-encoding:gzip
cache-control:private
pragma:no-cache
content-type:application/json
date:Wed, 10 Jan 2024 16:14:52 GMT
server:ebay-proxy-server
x-envoy-upstream-service-time:304
x-ebay-pop-id:UFES2-LVSAZ01-api
connection:close
响应体 空的
易趣API文档中的错误代码2004
错误ID:2004
错误类别:请求
消息:请求无效
长消息:请求有错误.有关帮助,请参阅此接口的文档.
域:访问
HTTP状态代码:400
我希望这能帮到你.但我想这和我以前写的一模一样. 我不知道错误可能出在哪里.在这种情况下,eBay文档并不是很有成效. 当我使用eBay文档中的样例JSON时,它是相同的错误.所以我认为变速箱有故障.可能使用CURLOPT_POST发送的数据长度不理想.但我已经以相同的方式完成了所有其他API调用.令牌、位置、列表本身、发布以及更新API调用都以完全相同的方式实现.