How to change product quantity using the Ebay API

I am trying to do one simple thing. I want to change the quantity of an existing fixed price item on Ebay using PHP . Is it possible? I have asked about this before and received answers in which I was asked to read this or that. I can't find any real code examples though. I would like to see someone post one. For example ebay item number 123456789 has quantity 50. I want to run some PHP code to change it to quantity 20. I want to enter item number, new quantity and any ebay validation data needed in the code and run it. It's all I need.

+3


source to share


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);

      

+4


source


There are three options for updating your current item on eBay.

You can use ReviseInventoryStatus to quickly update the cardinality as it has some advantages over others.



If you're okay using Composer in your PHP projects, I've developed an SDK that makes it easy to use the eBay API. The example below shows how to use the SDK using ReviseInventoryStatus. Comments in your code should tell you what you need to change 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 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 element, such as Title, you will need to use any of the Revise operations as they are designed to update 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 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);
}

      

+4


source


Here is an example for testing, just replace id and cardinality.

This php code was generated from this site by clicking the "get php code" button. The php SDK can also be 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);

      

+1


source







All Articles