skip to Main Content

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.

3

Answers


  1. 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);
    
    Login or Signup to reply.
  2. 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.

    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 DTSeBaySDKConstants;
    use DTSeBaySDKTradingServices;
    use DTSeBaySDKTradingTypes;
    use DTSeBaySDKTradingEnums;
    
    // 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 ServicesTradingService(array(
        'authToken' => $authToken,
        'apiVersion' => '899',
        'siteId' => $siteID
    ));
    
    $request = new TypesReviseInventoryStatusRequestType();
    $inventoryStatus = new TypesInventoryStatusType();
    $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: %sn%snn",
                $error->SeverityCode === EnumsSeverityCodeType::C_ERROR ? 'Error' : 'Warning',
                $error->ShortMessage,
                $error->LongMessage
            );
        }
    }
    
    if ($response->Ack !== 'Failure') {
        foreach ($response->InventoryStatus as $inventoryStatus) {
            printf("Quantity for [%s] is %snn",
                $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 DTSeBaySDKConstants;
    use DTSeBaySDKTradingServices;
    use DTSeBaySDKTradingTypes;
    use DTSeBaySDKTradingEnums;
    
    // 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 ServicesTradingService(array(
        'authToken' => $authToken,
        'apiVersion' => '899',
        'siteId' => $siteID
    ));
    
    $request = new TypesReviseItemRequestType();
    $item = new TypesItemType();
    $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: %sn%snn",
                $error->SeverityCode === EnumsSeverityCodeType::C_ERROR ? 'Error' : 'Warning',
                $error->ShortMessage,
                $error->LongMessage
            );
        }
    }
    
    if ($response->Ack !== 'Failure') {
        printf("Quantity for [%s] has been updatednn", $itemID);
    }
    
    Login or Signup to reply.
  3. 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);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search