Skip to content

Instantly share code, notes, and snippets.

@davidtsadler
Created November 8, 2012 21:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davidtsadler/4041969 to your computer and use it in GitHub Desktop.
Save davidtsadler/4041969 to your computer and use it in GitHub Desktop.
eBay LMS uploadFile API example
<?php
/*
* This is an edited version of the code found at https://www.x.com/developers/ebay/forums/ebay-apis-talk-your-fellow-developers/ebay-lms-uploadfile-api-not-working-please-help
*
*/
/*
* Replace the values for the following variables with your own.
*
* $taskReferenceId and $fileReferenceId are values returned after calling createUploadJob.
*
* $userToken is the Auth Token for the user upon whose behalf the uploadFile call is made.
*/
$taskReferenceId = 00000000000;
$fileReferenceId = 00000000000;
$userToken = 'xxxxxxxxx';
/*
* CURL parameters
*/
// Production URL
$target = 'https://storage.ebay.com/FileTransferService';
// Sandbox URL
//$target = 'https://storage.sandbox.ebay.com/FileTransferService';
$timeout = 60;
$headers = array(
'CONTENT-TYPE:text/xml'
,'X-EBAY-SOA-OPERATION-NAME:uploadFile'
,"X-EBAY-SOA-SECURITY-TOKEN:$userToken"
,'X-EBAY-SOA-SERVICE-NAME:FileTransferService'
);
/*
* Data to upload.
*/
$request = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<BulkDataExchangeRequests>
<Header><Version>795</Version><SiteID>0</SiteID></Header>
<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<Item ComplexType="ItemType">
<ApplicationData>54524</ApplicationData>
<AutoPay>true</AutoPay>
<Country>US</Country>
<Currency>USD</Currency>
<Description><![CDATA[<strong>Merchant Sku: </strong>54524<br><br><strong>Shipping Weight: </strong>8.00 oz<br><br><strong>Dimensions: </strong>13.00"L X 7.50"W<br><br><strong>Description</strong><br>Stay warm and cozy all year long with the Hot Water Bottle. Made with natural and durable rubber latex, the Hot Water Bottle conforms to the contours of your body while the ribbed outer surface helps keep the contents hot. The bottle is 7.5 inches wide and 13 inches long and can hold up to two quarts of water. The Hot Water Bottle has a strong plastic cap with a small handle that twists easily, securing the bottle and preventing water from leaking out. The bottle is perfect for heat therapy on sore, tense muscles and can also be filled with cold water and used as an ice pack.<br><br><strong>Features</strong><br><ul><li>Durable rubber latex helps retain desired temperature.</li><li>Can be used for heat therapy or as an ice pack.</li><li>Strong plastic cap prevents leaks.</li><li>Holds up to 2 quarts of water.</li><li>Lifetime limited warranty.</li></ul><br><br>]]></Description>
<HitCounter>NoHitCounter</HitCounter>
<ListingDetails>
<PayPerLeadEnabled>false</PayPerLeadEnabled>
</ListingDetails>
<ListingDuration>GTC</ListingDuration>
<ListingType>FixedPriceItem</ListingType>
<Location>Nashua, NH</Location>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>itspaypal@paypal.com</PayPalEmailAddress>
<PrimaryCategory>
<CategoryID>1277</CategoryID>
</PrimaryCategory>
<Quantity>500</Quantity>
<ShippingDetails>
<GlobalShipping>false</GlobalShipping>
<ShippingServiceOptions>
<ShippingService>ShippingMethodStandard</ShippingService>
<ShippingServiceCost>0</ShippingServiceCost>
<ShippingServiceAdditionalCost>0</ShippingServiceAdditionalCost>
<ShippingServicePriority>1</ShippingServicePriority>
<FreeShipping>false</FreeShipping>
</ShippingServiceOptions>
<ShippingType>Flat</ShippingType>
</ShippingDetails>
<Site>US</Site>
<StartPrice>11.95</StartPrice>
<Storefront>
<StoreCategoryID>2756431010</StoreCategoryID>
</Storefront>
<SubTitle></SubTitle>
<Title><![CDATA[Hot Water Bottle]]></Title>
<DisableBuyerRequirements>false</DisableBuyerRequirements>
<SKU>54524</SKU>
<CategoryBasedAttributesPrefill>false</CategoryBasedAttributesPrefill>
<PostalCode>03063</PostalCode>
<ShippingTermsInDescription>false</ShippingTermsInDescription>
<PictureDetails>
<GalleryType>None</GalleryType>
<PhotoDisplay>None</PhotoDisplay>
<PictureURL>http://www.colonialmedical.com/imgsize.php?w=320&amp;img=images/deta</PictureURL>
<PictureSource>Vendor</PictureSource>
<ExternalPictureURL>http://www.colonialmedical.com/imgsize.php?w=320&amp;img=images/deta</ExternalPictureURL>
</PictureDetails>
<DispatchTimeMax>3</DispatchTimeMax>
<SkypeEnabled>false</SkypeEnabled>
<ReturnPolicy>
<RefundOption>MoneyBack</RefundOption>
<ReturnsWithinOption>Days_30</ReturnsWithinOption>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<Description>Must be in resaleable condition for return.</Description>
<WarrantyOfferedOption></WarrantyOfferedOption>
<WarrantyTypeOption></WarrantyTypeOption>
<WarrantyDurationOption></WarrantyDurationOption>
<EAN></EAN>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
</ReturnPolicy>
<InventoryTrackingMethod>SKU</InventoryTrackingMethod>
<ConditionID>1000</ConditionID>
<ConditionDescription>New</ConditionDescription>
<PostCheckoutExperienceEnabled>false</PostCheckoutExperienceEnabled>
<UnitInfo>
<UnitType></UnitType>
<UnitQuantity>1</UnitQuantity>
</UnitInfo>
</Item>
<Version>795</Version>
<WarningLevel>Low</WarningLevel>
</AddFixedPriceItemRequest>
</BulkDataExchangeRequests>
XML;
/*
* GZIP and base64 encode our data.
*/
$data = base64_encode(gzencode($request, 5));
/*
* Now make the actual request to eBay.
*/
$xml = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<uploadFileRequest xmlns:sct="http://www.ebay.com/soaframework/common/types" xmlns="http://www.ebay.com/marketplace/services">
<taskReferenceId>$taskReferenceId</taskReferenceId>
<fileReferenceId>$fileReferenceId</fileReferenceId>
<fileFormat>gzip</fileFormat>
<fileAttachment>
<Data>$data</Data>
</fileAttachment>
</uploadFileRequest>
XML;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$resp = curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
echo $resp;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment