Tops Technologies Pvt Ltd
13
eBay making an API call
For beginner
Chirag Parmar
eBay making an API call
By Chirag Parmar
Trading API Tutorials
The following tutorials have been written specifically for ...
eBay making an API call
By Chirag Parmar
3. I assumed that you are a new for eBay so lets start with registration process....
eBay making an API call
By Chirag Parmar
Note: as a beginner you may download sample codes for better understanding and go...
eBay making an API call
By Chirag Parmar
2. listingType (Required)
The format of the listing the seller wants to use, such...
eBay making an API call
By Chirag Parmar
$itemDescription = $_POST['itemDescription'];
$listingDuration = $_POST['listingD...
eBay making an API call
By Chirag Parmar
$requestXmlBody .=
"<Description><![CDATA[$itemDescription]]></Description>";
$re...
eBay making an API call
By Chirag Parmar
$itemIDs = $response->getElementsByTagName("ItemID");
$itemID = $itemIDs->item(0)...
eBay making an API call
By Chirag Parmar
All fields in the following AddItem request sample are the basic input to create ...
eBay making an API call
By Chirag Parmar
<ListingType>Chinese</ListingType>
<PaymentMethods>PayPal</PaymentMethods>
<PayPa...
eBay making an API call
By Chirag Parmar
</AddItemRequest>
Output
The response includes the ItemID and the list of fees as...
eBay making an API call
By Chirag Parmar
<Fee currencyID="USD">0.0</Fee>
</Fee>
<Fee>
<Name>CategoryFeaturedFee</Name>
<Fe...
eBay making an API call
By Chirag Parmar
</Fee>
<Fee>
<Name>GiftIconFee</Name>
<Fee currencyID="USD">0.0</Fee>
</Fee>
<Fee...
eBay making an API call
By Chirag Parmar
<Fee>
<Name>PhotoDisplayFee</Name>
<Fee currencyID="USD">0.0</Fee>
</Fee>
<Fee>
<...
eBay making an API call
By Chirag Parmar
<Name>ProPackBundleFee</Name>
<Fee currencyID="USD">0.0</Fee>
</Fee>
<Fee>
<Name>...
eBay making an API call
By Chirag Parmar
<Fee currencyID="USD">0.0</Fee>
</Fee>
</Fees>
</AddItemResponse>
Upcoming SlideShare
Loading in...5
×

eBay making an api call

5,559

Published on

Hello Everyone,
This document is going to help you to add your first item on the world's online marketplace eBay
Please follow all the instructions carefully.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,559
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
32
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

eBay making an api call

  1. 1. Tops Technologies Pvt Ltd 13 eBay making an API call For beginner Chirag Parmar
  2. 2. eBay making an API call By Chirag Parmar Trading API Tutorials The following tutorials have been written specifically for the Trading API: Tutorial Description eBay Building Blocks (tasks made easy) Register and Get Your Keys Simple steps for joining the eBay Developers Program. Add an Item the Easy Way Very simple AddItem sample for listing by product. XML Workflow Tutorials (using API directly) Getting Tokens This tutorial illustrates the setup and the API calls needed for getting tokens that let you make calls on behalf of your users XML API FLow: Listing an Item This tutorial illustrates the API workflow for listing an item on eBay. Hello Everyone, This document is going to help you to add your first item on the world's online marketplace eBay Please follow all the instructions carefully. To get started with eBay api you will need following things, so let’s first get it first Developer account Authentication keys for Sandbox and Production Seller Account Register and Get Your Keys Joining the eBay Developers Program is simple. 1. Go to http:developer.ebay.com Even without joining, the eBay Developers Program site contains a Wealth of information about eBay APIs and other resources. 2. Click register or eBay developer login
  3. 3. eBay making an API call By Chirag Parmar 3. I assumed that you are a new for eBay so lets start with registration process. Fill and Submit the registration Form. Read the API license. Fill in the form completely and click the Join Now button at the bottom of the form. 4. Check your email and activate your account When you join, Developer Relations sends an email to the account specified in your registration form. The email contains a link to activate your account. The link in the email takes you to the Account Activation page, which should indicate you have successfully activated your account. 5. After getting your account of developer you may get login with your username and go to MY ACCOUNT section of you profile or click on “Get Yours Keys” 6. Here, Under Application keys label, you will see two option Sandbox keys & Production keys. a. Sandbox environment is a place where developer can run their code for testing purpose. It is same as live server which is called production environment. b. Production environment is a place where developer can place their application towards the world. All transaction like adding item, removing item, making order within production environment are real and you may not use before testing actual output on sandbox environment. 7. Under Application keys label , click on “Generate Sandbox Keys”. 8. After following above instruction you will get Authentication keys for using further while adding our first item on eBay. Now you should have Key Set name (i.e. Key Set 1), DEVID (i.e. 1c03ffba- cb8d-4d67-9910-ee68274493eb), AppID (i.e. topsindi-723f-4902-ad15-f8d583b0edd2), CertID (i.e. 9140416e-b089-41fd-97b4-014c6e45032a) 9. List down all of this and if you still missing any one of them please read all instruction again or email me on chiragparmar2411@gmail.com I would like to assist you for the same. After generating your application keys, now we have to create User token which is necessary to pass eBay’s validation while making api call , go to My Account > Tools > click on Get a User Token. 1. You will see Get a User Token page. 2. Now, Select environment for your token. We will use sandbox environment for now. a. We need one test user who corresponds to following user token not to the actual user who is handling all this. So we will create Sandbox user. Link for sandbox user is listed under environment selection. b. After creating sandbox user we will use this user to get log in while testing our transaction on sandbox. 3. Under Keys label, select a key set or enter one manually. (i.e. Key Set 1) 4. Copy and keep it to safe place for future api call I hope you have completed all above task and followed instruction correctly. Those are the configuration things, which are base of our code and which are going to be used while playing around to code. Now it’s time to play with actual stuff over eBay Platform, you will see actual coding stuff ahead.
  4. 4. eBay making an API call By Chirag Parmar Note: as a beginner you may download sample codes for better understanding and good start up so I’m going to give step by step instruction for same. If you need more assistance, you may directly contact me on chiragparmar2411@gmail.com. Instructions for getting Sample Code 1. Go to https://go.developer.ebay.com/developers/ebay 2. Under Documentation & Tools Menu, Select Code Samples sub menu 3. It is like eBay Developer Home > Documentation & Tools > Code Samples 4. You can find code samples here for all the different APIs that are part of eBay WebServices. 5. Just getting started? Make sure you try the Quick Start sample application. If you want a little more help, see the Tutorials page for step-by-step coding exercises. 6. Now select your Coding Platform. In our case we will select PHP 5.3 7. For adding a item we are using Trading API so we are going to download sample code for trading api. On Code Samples - Trading API page you may find eBay Trading API Code Sample (PHP5/SOAP). Click on Download Code under that label. 8. You will get zip file of 102kb which contains all related webservices for php apis for ebay. 9. Within that zip file, you will get sample code for Additem. 10. Most important thing get-common folder. This contains the code which is common to all the Get... samples (GetCategories, GeteBayOfficialTime...) 11. Go to keys.php file nested under get-common folder and change keys accordingly. As I instructed above, you should change sandbox keys. // sandbox (test) environment Finally we are here. Adding item to ebay sandbox Wait for a while, Before going ahead let me walk through you information about some variables which are important to know. We are going to use Additem Api. It is very important to notice version number of api. eBay Trading API Call Reference Version 837 AddItem ebay provide 2 ways for php to make a api calles. You may use either XML or get method. But for data concern we supposed to use xml call as they are simple to understand and easy to debug. 1. ini_set('magic_quotes_gpc', false); // magic quotes will only confuse things like escaping apostrophe
  5. 5. eBay making an API call By Chirag Parmar 2. listingType (Required) The format of the listing the seller wants to use, such as auction style or fixed price. <ListingType> ListingTypeCodeType </ListingType> 3. PrimaryCategory (Required) Category ID for the first (or only) category in which the item is listed (or will be listed, if the item is new). A number of listing features have dependencies on the primary category. See the descriptions of the fields you are using to determine whether the feature you're supporting depends on the listing's primary category. <PrimaryCategory> CategoryType <CategoryID> string </CategoryID> </PrimaryCategory> 4. Verb In our script there should be one variable which indicates which api call you making, that is verb. Verb always similar to your api call. i.e. we are making ADDITEM call so verb should be additem 5. SiteID SiteID is variable which indicates the eBay site to associate the call with. If you don’t have it please make it 0. Now, lets make our first call. Here is a sample for that. Include keys.php & eBaySession.php file in our script. Prepare all required variables Prepare your xml body as given in example Make api call by creating object of eBaySession class For that you should use as follow, $session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb); Use error debugging methods to check whether our api call is got success or not. Check Sample code as given below for all above instructions After making additem api call you should store response in database. In response you will get ebay url for that particular item and all related information like itemid, listing ending details and all. <?php if(isset($_POST['listingType'])) { ini_set('magic_quotes_gpc', false); // magic quotes will only confuse things like escaping apostrophe //Get the item entered $listingType = $_POST['listingType']; $primaryCategory = $_POST['primaryCategory']; $itemTitle = $_POST['itemTitle']; if(get_magic_quotes_gpc()) { // print "stripslashes!!! <br>n"; $itemDescription = stripslashes($_POST['itemDescription']); } else { $itemDescription = $_POST['itemDescription']; }
  6. 6. eBay making an API call By Chirag Parmar $itemDescription = $_POST['itemDescription']; $listingDuration = $_POST['listingDuration']; $startPrice = $_POST['startPrice']; $buyItNowPrice = $_POST['buyItNowPrice']; $quantity = $_POST['quantity']; if ($listingType == 'StoresFixedPrice') { $buyItNowPrice = 0.0; // don't have BuyItNow for SIF $listingDuration = 'GTC'; } if ($listingType == 'Dutch') { $buyItNowPrice = 0.0; // don't have BuyItNow for Dutch } //SiteID must also be set in the Request's XML //SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, .... //SiteID Indicates the eBay site to associate the call with $siteID = 0; //the call being made: $verb = 'AddItem'; ///Build the request Xml string $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>'; $requestXmlBody .= '<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">'; $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>"; $requestXmlBody .= '<DetailLevel>ReturnAll</DetailLevel>'; $requestXmlBody .= '<ErrorLanguage>en_US</ErrorLanguage>'; $requestXmlBody .= "<Version>$compatabilityLevel</Version>"; $requestXmlBody .= '<Item>'; $requestXmlBody .= '<Site>US</Site>'; $requestXmlBody .= '<PrimaryCategory>'; $requestXmlBody .= "<CategoryID>$primaryCategory</CategoryID>"; $requestXmlBody .= '</PrimaryCategory>'; $requestXmlBody .= "<BuyItNowPrice currencyID="USD">$buyItNowPrice</BuyItNowPrice>"; $requestXmlBody .= '<Country>US</Country>'; $requestXmlBody .= '<Currency>USD</Currency>'; $requestXmlBody .= "<ListingDuration>$listingDuration</ListingDuration>"; $requestXmlBody .= "<ListingType>$listingType</ListingType>"; $requestXmlBody .= '<Location><![CDATA[San Jose, CA]]></Location>'; $requestXmlBody .= '<PaymentMethods>PaymentSeeDescription</PaymentMethods>'; $requestXmlBody .= "<Quantity>$quantity</Quantity>"; $requestXmlBody .= '<RegionID>0</RegionID>'; $requestXmlBody .= "<StartPrice>$startPrice</StartPrice>"; $requestXmlBody .= '<ShippingTermsInDescription>True</ShippingTermsInDescription>'; $requestXmlBody .= "<Title><![CDATA[$itemTitle]]></Title>";
  7. 7. eBay making an API call By Chirag Parmar $requestXmlBody .= "<Description><![CDATA[$itemDescription]]></Description>"; $requestXmlBody .= '</Item>'; $requestXmlBody .= '</AddItemRequest>'; //Create a new eBay session with all details pulled in from included keys.php $session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb); //send the request and get response $responseXml = $session->sendHttpRequest($requestXmlBody); if(stristr($responseXml, 'HTTP 404') || $responseXml == '') die('<P>Error sending request'); //Xml string is parsed and creates a DOM Document object $responseDoc = new DomDocument(); $responseDoc->loadXML($responseXml); //get any error nodes $errors = $responseDoc->getElementsByTagName('Errors'); //if there are error nodes if($errors->length > 0) { echo '<P><B>eBay returned the following error(s):</B>'; //display each error //Get error code, ShortMesaage and LongMessage $code = $errors->item(0)->getElementsByTagName('ErrorCode'); $shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage'); $longMsg = $errors->item(0)->getElementsByTagName('LongMessage'); //Display code and shortmessage echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue)); //if there is a long message (ie ErrorLevel=1), display it if(count($longMsg) > 0) echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue)); } else { //no errors //get results nodes $responses = $responseDoc->getElementsByTagName("AddItemResponse"); foreach ($responses as $response) { $acks = $response->getElementsByTagName("Ack"); $ack = $acks->item(0)->nodeValue; echo "Ack = $ack <BR />n"; // Success if successful $endTimes = $response->getElementsByTagName("EndTime"); $endTime = $endTimes->item(0)->nodeValue; echo "endTime = $endTime <BR />n";
  8. 8. eBay making an API call By Chirag Parmar $itemIDs = $response->getElementsByTagName("ItemID"); $itemID = $itemIDs->item(0)->nodeValue; echo "itemID = $itemID <BR />n"; $linkBase = "http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item="; echo "<a href=$linkBase" . $itemID . ">$itemTitle</a> <BR />"; $feeNodes = $responseDoc->getElementsByTagName('Fee'); foreach($feeNodes as $feeNode) { $feeNames = $feeNode->getElementsByTagName("Name"); if ($feeNames->item(0)) { $feeName = $feeNames->item(0)->nodeValue; $fees = $feeNode->getElementsByTagName('Fee'); // get Fee amount nested in Fee $fee = $fees->item(0)->nodeValue; if ($fee > 0.0) { if ($feeName == 'ListingFee') { printf("<B>$feeName : %.2f </B><BR>n", $fee); } else { printf("$feeName : %.2f <BR>n", $fee); } } // if $fee > 0 } // if feeName } // foreach $feeNode } // foreach response } // if $errors->length > 0 } ?> http://developer.ebay.com/devzone/xml/docs/reference/ebay/additem.html Sample: Basic Call Defines and lists a single item for auction on the eBay US site. Description Note: In addition to the AddItem samples presented here, find more AddItem Samples in the Trading API Guide. User magicalbookseller wants to sell a Harry Potter book on the eBay US site. She wants to start the listing at $1.00 and wants the listing to run for 7 days. She chooses flat rate shipping of $2.50 for a particular shipping service. She'll ship the item within 3 days of receiving cleared payment. She offers a standard return policy. AddItem needs a category ID. You may need to first call GetCategories to determine the category ID. (See GetCategories for more information.) For this example, CategoryID is 377, Fiction Books. As a result of this call, magicalbookseller has a new listing for her Harry Potter book on eBay with the details as provided in the call. You can call GetItem with the ItemID found in AddItem response to confirm the item details. Input
  9. 9. eBay making an API call By Chirag Parmar All fields in the following AddItem request sample are the basic input to create a listing for magicalbookseller's Harry Potter book. To see a photo with the listing, provide a link to the photo in the PictureURL field. (The URL used in this sample is a picture that Magical Bookseller uploaded to EPS using the UploadSiteHostedPictures call.) XML format (HTTP POST). Also available is the .txt version of this XML. <?xml version="1.0" encoding="utf-8"?> <AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <RequesterCredentials> <eBayAuthToken>ABC...123</eBayAuthToken> </RequesterCredentials> <ErrorLanguage>en_US</ErrorLanguage> <WarningLevel>High</WarningLevel> <Item> <Title>Harry Potter and the Philosopher's Stone</Title> <Description> This is the first book in the Harry Potter series. In excellent condition! </Description> <PrimaryCategory> <CategoryID>377</CategoryID> </PrimaryCategory> <StartPrice>1.0</StartPrice> <CategoryMappingAllowed>true</CategoryMappingAllowed> <Country>US</Country> <Currency>USD</Currency> <DispatchTimeMax>3</DispatchTimeMax> <ListingDuration>Days_7</ListingDuration>
  10. 10. eBay making an API call By Chirag Parmar <ListingType>Chinese</ListingType> <PaymentMethods>PayPal</PaymentMethods> <PayPalEmailAddress>magicalbookseller@yahoo.com</PayPalEmailAddress> <PictureDetails> <PictureURL>http://pics.ebay.com/aw/pics/dot_clear.gif</PictureURL> </PictureDetails> <PostalCode>95125</PostalCode> <Quantity>1</Quantity> <ReturnPolicy> <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption> <RefundOption>MoneyBack</RefundOption> <ReturnsWithinOption>Days_30</ReturnsWithinOption> <Description>If you are not satisfied, return the book for refund.</Description> <ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption> </ReturnPolicy> <ShippingDetails> <ShippingType>Flat</ShippingType> <ShippingServiceOptions> <ShippingServicePriority>1</ShippingServicePriority> <ShippingService>USPSMedia</ShippingService> <ShippingServiceCost>2.50</ShippingServiceCost> </ShippingServiceOptions> </ShippingDetails> <Site>US</Site> </Item>
  11. 11. eBay making an API call By Chirag Parmar </AddItemRequest> Output The response includes the ItemID and the list of fees associated with listing magicalbookseller's book. For the basic AddItem call, the only fee is the insertion fee. The listing fee is the total of fees prior to selling the item. (In this case, the listing fee equals the insertion fee.) XML format. Also available is the .txt version of this XML. <AddItemResponse xmlns="urn:ebay:apis:eBLBaseComponents"> <Timestamp>2010-02-16T18:52:41.543Z</Timestamp> <Ack>Success</Ack> <Version>655</Version> <Build>E655_CORE_BUNDLED_10639415_R1</Build> <ItemID>110043671232</ItemID> <StartTime>2010-02-16T18:52:41.027Z</StartTime> <EndTime>2010-02-23T18:52:41.027Z</EndTime> <Fees> <Fee> <Name>AuctionLengthFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>BoldFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>BuyItNowFee</Name>
  12. 12. eBay making an API call By Chirag Parmar <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>CategoryFeaturedFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>FeaturedFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>GalleryPlusFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>FeaturedGalleryFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>FixedPriceDurationFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>GalleryFee</Name> <Fee currencyID="USD">0.0</Fee>
  13. 13. eBay making an API call By Chirag Parmar </Fee> <Fee> <Name>GiftIconFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>HighLightFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>InsertionFee</Name> <Fee currencyID="USD">0.25</Fee> </Fee> <Fee> <Name>InternationalInsertionFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>ListingDesignerFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>ListingFee</Name> <Fee currencyID="USD">0.25</Fee> </Fee>
  14. 14. eBay making an API call By Chirag Parmar <Fee> <Name>PhotoDisplayFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>PhotoFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>ReserveFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>SchedulingFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>SubtitleFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>BorderFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee>
  15. 15. eBay making an API call By Chirag Parmar <Name>ProPackBundleFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>BasicUpgradePackBundleFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>ValuePackBundleFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>PrivateListingFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>ExtendedDurationFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>ProPackPlusBundleFee</Name> <Fee currencyID="USD">0.0</Fee> </Fee> <Fee> <Name>MotorsGermanySearchFee</Name>
  16. 16. eBay making an API call By Chirag Parmar <Fee currencyID="USD">0.0</Fee> </Fee> </Fees> </AddItemResponse>

×