I'm trying to do one simple thing. I want to change the quantity of an existing fixed priced item on ebay using PHP. Is this possible? I've asked this before and got responses telling me to read this or that. I'm not able to find any actual code examples though. I'd love to see someone post one. For example, ebay item number 123456789 has a qty of 50. I want to run some PHP code to change it to qty of 20. I want to enter the item number, the new quantity, and any ebay verification data needed into the code and run it. That's all I need.
-
are you pulling the ebay data to your own site? What you are trying to accomplish and what you already have setup is a little vague. – Robert Lee Nov 30 '14 at 17:31
-
Read about eBay's API - https://go.developer.ebay.com/developers/ebay/products/what-ebay-api – Nov 30 '14 at 17:34
-
I don't have anything set up. I'm totally new to the ebay API thing, and it is a bit over my head. I am good with php though. I just want to know if what I asked is possible, and if so, I'd like to see some code to do it. Can you make changes to an ebay listing with PHP? – CheeseFlavored Nov 30 '14 at 17:36
-
please, don't use capslock. – JohnKiller Nov 30 '14 at 18:01
3 Answers
Try this it works for me
$feed = <<< EOD
<?xml version="1.0" encoding="utf-8"?>
<ReviseItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>$eBay->auth_token</eBayAuthToken>
</RequesterCredentials>
<Item ComplexType="ItemType">
<ItemID>$itemid</ItemID>
<Quantity> int </Quantity>
</Item>
<MessageID>1</MessageID>
<WarningLevel>High</WarningLevel>
<Version>$eBay->api_version</Version>
</ReviseItemRequest>
EOD;
$feed = trim($feed);
$site_id = 3;//3 For UK
$headers = array
(
'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $this->api_version,
'X-EBAY-API-DEV-NAME: ' . $this->dev_id,
'X-EBAY-API-APP-NAME: ' . $this->app_id,
'X-EBAY-API-CERT-NAME: ' . $this->cert_id,
'X-EBAY-API-CALL-NAME: ' . $call_name,
'X-EBAY-API-SITEID: ' . $site_id,
);
// Send request to eBay and load response in $response
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $this->api_endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $feed);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);

- 2,077
- 3
- 28
- 55
-
i think this raw code is the best, because you dont need to learn other ppl classes like David T example – jmp Jul 29 '16 at 18:10
There are three options available for updating a live item on eBay.
For quickly updating an item's quantity you may want to use ReviseInventoryStatus as it has some advantages over the others.
- Up to a maximum of 4 items can be updated in a single call.
- Confirmation of the updated quantity is included in the response.
If you are OK with using Composer in your PHP projects I have developed a SDK that simplifies using the eBay API. The example below shows how to use the SDK with ReviseInventoryStatus. The comments in the code should tell you what you will need to change in order for it to work.
<?php
require 'vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
// Your authorization token associated with the seller's account.
$authToken = 'abcd123';
// The ID of the item you wish to update (Must be a string).
$itemID = '123456789';
// The new quantity (Must be an integer and not a string!).
$quantity = 20;
// The numerical ID of the site that the item was listed on. For example the site ID for ebay.com is 0 and for ebay.co.uk it is 3. A complete list is available from eBay: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/types/SiteCodeType.html.
$siteID = '0';
$service = new Services\TradingService(array(
'authToken' => $authToken,
'apiVersion' => '899',
'siteId' => $siteID
));
$request = new Types\ReviseInventoryStatusRequestType();
$inventoryStatus = new Types\InventoryStatusType();
$inventoryStatus->ItemID = $itemID;
$inventoryStatus->Quantity = $quantity;
$request->InventoryStatus[] = $inventoryStatus;
$request->ErrorLanguage = 'en_US';
$request->WarningLevel = 'High';
$response = $service->reviseInventoryStatus($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') {
foreach ($response->InventoryStatus as $inventoryStatus) {
printf("Quantity for [%s] is %s\n\n",
$inventoryStatus->ItemID,
$inventoryStatus->Quantity
);
}
}
If you are interested in updating other aspects of an item, for example it's Title, you will want to use either of the Revise operations as these are designed for updating more fields.
<?php
require 'vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
// Your authorization token associated with the seller's account.
$authToken = 'abcd123';
// The ID of the item you wish to update (Must be a string).
$itemID = '123456789';
// The new quantity (Must be an integer and not a string!).
$quantity = 20;
// The numerical ID of the site that the item was listed on. For example the site ID for ebay.com is 0 and for ebay.co.uk it is 3. A complete list is available from eBay: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/types/SiteCodeType.html.
$siteID = '0';
$service = new Services\TradingService(array(
'authToken' => $authToken,
'apiVersion' => '899',
'siteId' => $siteID
));
$request = new Types\ReviseItemRequestType();
$item = new Types\ItemType();
$item->ItemID = $itemID;
$item->Quantity = $quantity;
$request->Item = $item;
$request->ErrorLanguage = 'en_US';
$request->WarningLevel = 'High';
$response = $service->reviseItem($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') {
printf("Quantity for [%s] has been updated\n\n", $itemID);
}
-
How can I get an item’s HTML description? It’s a live listing and I have its id. – Amir Hajiha Sep 28 '18 at 22:39
Here is a ready to test example, just replace the item id and quantity.
This php code was generated from this site by clicking on the "retrieve php code" button. The SDK for php can be also downloaded there.
require_once 'EbatNs_Session.php';
require_once 'EbatNs_Logger.php';
require_once 'EbatNs_ServiceProxy.php';
require_once 'EbatNs_Session.php';
require_once 'EbatNs_DataConverter.php';
$session = new EbatNs_Session();
$session->setSiteId(0);
$session->setUseHttpCompression(1);
$session->setAppMode(0);
$session->setDevId(YOUR_DEV_ID_HERE);
$session->setAppId(YOUR_APP_ID_HERE);
$session->setCertId(YOUR_CERT_ID_HERE);
$session->setRequestToken(YOUR_TOKEN_HERE);
$session->setTokenUsePickupFile(false);
$session->setTokenMode(true);
require_once 'EbatNs_ServiceProxy.php';
$proxy = new EbatNs_ServiceProxy($session, 'EbatNs_DataConverterUtf8');
require_once 'ReviseInventoryStatusRequestType.php';
$reviseinventorystatusrequest = new ReviseInventoryStatusRequestType();
$inventorystatus = new InventoryStatusType();
$reviseinventorystatusrequest->addInventoryStatus($inventorystatus);
$inventorystatus->setItemID("YOUR ITEM ID");
$inventorystatus->setQuantity("YOUR QUANTITY");
$reviseinventorystatusrequest->setErrorLanguage("en_US");
$reviseinventorystatusrequest->setVersion("899");
$reviseinventorystatusrequest->setWarningLevel("High");
$response = $proxy->ReviseInventoryStatus($reviseinventorystatusrequest);