📜 ⬆️ ⬇️

eBay API: Step Two

Hi, habravchane.

The publication is inspired by this article - “eBay API: First Steps” and could theoretically be its continuation. It is useful to those who tried to start working with the eBay API, did not find where to ask what to do and spat on this activity. Or asked, did not wait for an answer and in the end still spat.

I do not pretend to the truth in any instance and I will gladly accept tips on overcoming bugs that have not been overcome.
')


First of all, I want to leave a small remark: to start working with the eBay API quickly - it will not work. The catastrophic number of omissions and inconsistencies in the documentation, flaws and bugs in the API mechanism itself, the implicitness and ambiguity of using combinations of query conditions force us to test each step separately. And to test more than once: what worked fine yesterday will return an error today, and continue to work tomorrow as if nothing had happened.

However, in order not to build a slander on a reputable company, let's forget about the previous paragraph and write off everything that I'm just stupid, stupid and underdeveloped. And that a real programmer will succeed much faster and more correctly.

Therefore, if you have a working mechanism for parsing Ebay pages - think again whether it is worth switching to a civilized way of receiving data or continue adjusting the parser from time to time to the eBay design that changes in time. Moreover, from the point of view of a simple buyer, you will not receive any fundamentally new data, but for example, you will lose information about the current discount or the handling of the event “the lot is rotten, re-expose”.

But if on duty you need to monitor at least a couple or three thousand products and periodically check prices - you definitely need an API. My small project desperately needed to automate updating prices and adding new products, and eBay design changes became so frequent in 2014 that I decided to stop smoking to stop parsing, write the beginnings of the eBay API library and start programming at the same time as old age.

Since the project engine was written in PHP, I didn’t have a choice, and therefore we’ll continue with it.

Nacham with the findItemsAdvanced function, which means “Find a lot of products by keyword, with a completely useless result for non-US residents.” Then we will consider (probably already in the next article) other functions that will turn useless answers into useful ones.

You have already received Application Keys as stated here . Take the AppID from Production Keys - due to the fact that the bugs in Sandbox and Production are different, we will immediately work with the "combat" version - and substitute it in the right place of the header. As you will see later, the headers in the eBay API can take many different forms, so I will bring them separately in each case.

<?php /*        store //      , partnumber  itemID //       */ function findItemsAdvanced($request) { $headers = array( 'X-EBAY-SOA-SERVICE-NAME:FindingService', 'X-EBAY-SOA-OPERATION-NAME:findItemsAdvanced', 'X-EBAY-SOA-SERVICE-VERSION:1.12.0', 'X-EBAY-SOA-GLOBAL-ID:EBAY-US', 'X-EBAY-SOA-SECURITY-APPNAME:_AppID', // AppID    "X-EBAY-API-REQUEST-ENCODING: XML", 'Content-Type: text/xml;charset=utf-8', ); $endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1?'; 

The remaining values ​​of the headings can be simply copied, they are the same for all.

Make a request.
All my inquiries are in the category of "Spare parts for motorcycles" and are focused on the relevant section of eBay USA - "EBAY-MOTORS". Find a list of suitable sections here , a list of categories here and do not forget to substitute them into your requests.

  $xmlRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; $xmlRequest .= "<findItemsAdvancedRequest xmlns='http://www.ebay.com/marketplace/search/v1/services'>"; $xmlRequest .= "<categoryId>10063</categoryId>"; // 10063 -    // 6028 -     $xmlRequest .= "<descriptionSearch>false</descriptionSearch>"; //     ,  $xmlRequest .= "<keywords>".$request."</keywords>"; //  :    $xmlRequest .= "<itemFilter><name>Condition</name><value>New</value></itemFilter>"; //  : , /    $xmlRequest .= "<itemFilter><name>FeedbackScoreMin</name><value>3000</value></itemFilter>"; //   $xmlRequest .= "<itemFilter><name>ListingType</name><value>FixedPrice</value></itemFilter>"; //    $xmlRequest .= "<itemFilter><name>AvailableTo</name><value>RU</value></itemFilter>"; //        ,         .      ,          .    . $xmlRequest .= "<itemFilter><name>PaymentMethod</name><value>PayPal</value></itemFilter>"; //        Paypal.      ,     -,    Paypal.  eBay    . $xmlRequest .= "<itemFilter><name>HideDuplicateItems</name><value>true</value></itemFilter>"; //       ?  . //$xmlRequest .= "<itemFilter><name>ExcludeSeller</name><value>storename</value></itemFilter>"; //   :         .       . $xmlRequest .= "<outputSelector>SellerInfo</outputSelector> //         


Here I would like to elaborate on the descriptionSearch parameter.
Description - this is the area of ​​the lot description at the very bottom - under the photos, delivery calculation, etc. Theoretically, the seller can write there any nonsense that falls into our result and will not match our query.

For example, you are looking for an elephant, and a certain seller sells a cat: in the title is a cat, in the photo is a cat, but the description says something like “This is a huge cat, a real elephant!”. This product will fall into our issue, although in fact it will not contain any elephant. And the price for it will be appropriate: as for a cat.

Finish the request:
  $session = curl_init($endpoint); curl_setopt($session, CURLOPT_POST, true); curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_HTTPHEADER, $headers); $responseXML = curl_exec($session); curl_close($session); ?> 


It's time to send our request ...
 <?php header('X-Accel-Buffering: no'); ob_get_flush(); $responseXML = Ebay_shopping::findItemsAdvanced('cobra exhaust c90t'); // "cobra exhaust c90t" —   "  Cobra   Suzuku Boulevard C90T".      "iPhone",          :     <categoryId>9355</categoryId>. $responseXML = simplexml_load_string($responseXML); print_r($responseXML); ?> 

... and get an answer:
He is long ...
 SimpleXMLElement Object ( [ack] => Success [version] => 1.13.0 [timestamp] => 2014-11-24T18:01:37.836Z [searchResult] => SimpleXMLElement Object ( [@attributes] => Array ( [count] => 11 //   11 ,    ) [item] => Array ( [0] => SimpleXMLElement Object ( [itemId] => 360763537259 //  ,   .         eBay      ,   eBay. [title] => Cobra Speedster Exhaust with Powerport Long 2005 Suzuki C90T Boulevard //  .     $request. [globalId] => EBAY-MOTOR //  eBay,      [primaryCategory] => SimpleXMLElement Object ( [categoryId] => 178001 [categoryName] => Other Exhaust Parts ) [galleryURL] => http://thumbs4.ebaystatic.com/m/mbTIInAkeUhM9YV7mV7GtcQ/140.jpg //      .      . [viewItemURL] => http://www.ebay.com/itm/Cobra-Speedster-Exhaust-Powerport-Long-2005-Suzuki-C90T-Boulevard-/360763537259?pt=Motorcycles_Parts_Accessories //          ebay [paymentMethod] => Array ( [0] => PayPal [1] => VisaMC [2] => AmEx [3] => Discover ) [autoPay] => false [postalCode] => 46528 [location] => Goshen,IN,USA [country] => US [sellerInfo] => SimpleXMLElement Object ( [sellerUserName] => motored_e [feedbackScore] => 11025 //    ,   FeedbackScoreMin  3000 [positiveFeedbackPercent] => 99.1 // ...       .      [feedbackRatingStar] => YellowShooting [topRatedSeller] => false ) [shippingInfo] => SimpleXMLElement Object ( [shippingServiceCost] => 0.0 [shippingType] => FlatDomesticCalculatedInternational [shipToLocations] => Worldwide [expeditedShipping] => true [oneDayShippingAvailable] => false [handlingTime] => 1 ) [sellingStatus] => SimpleXMLElement Object ( [currentPrice] => 521.51 [convertedCurrentPrice] => 521.51 [sellingState] => Active [timeLeft] => P11DT9H1M57S ) [listingInfo] => SimpleXMLElement Object ( [bestOfferEnabled] => false [buyItNowAvailable] => false [startTime] => 2013-10-12T02:58:34.000Z [endTime] => 2014-12-06T03:03:34.000Z [listingType] => FixedPrice [gift] => false ) [returnsAccepted] => true [condition] => SimpleXMLElement Object ( [conditionId] => 1000 //      "1000"  "New"...  ,   [conditionDisplayName] => New ) [isMultiVariationListing] => false [topRatedListing] => false ) ) ) [paginationOutput] => SimpleXMLElement Object ( [pageNumber] => 1 [entriesPerPage] => 100 [totalPages] => 1 [totalEntries] => 11 ) [itemSearchURL] => http://www.ebay.com/sch/10063/i.html?_sasl=riderswarehouse&payment=PayPal&_fss=1&LH_SpecificSeller=1&LH_PayPal=1&_nkw=cobra+exhaust+c90t&LH_BIN=1&LH_ItemCondition=1&_saslop=2&LH_AvailTo=1&_fblo=3000&_fbsc=1&_fls=1&_incaucbin=0&_ipg=100&_os=S%7CD&_pgn=1&_saact=168&_sop=15 //      ,      $request   ebay ) 



I would like to highlight some points of response.
[shipToLocations] => Worldwide
This flow doesn’t really mean anything. If the seller manually blacklisted your country and is not going to send his goods there for any money, then Worldwide will in the same place flaunt an answer.

[convertedCurrentPrice] => 521.51
The eBay API can issue us prices in the currency in which the seller billed them. In practice, it is more correct to bring all prices in dollars, and this is exactly what this line does.

[timeLeft] => P11DT9H1M57S
After this time has elapsed, the lot will become rotten and will be re-installed (Item Relisted). After some time, we can no longer find it by itemID.

[entriesPerPage] => 100
[totalPages] => 1
The eBay API has a global limit of 100 lots per page. If there was more at your request, you will have to make several requests and stitch the answers together. There is no such function in the eBay API and we will write it later.

With the answer you received, you can already do something and you will probably get better at it. If this article will be interesting for hack readers, in the next we will analyze how I process it and what comes out of it.

We will also consider a possible algorithm for combining several eBay API functions “from life”, feed the result of one function to the input of another, apply several filters and get a result worthy of writing to your database.
Good luck.

Source: https://habr.com/ru/post/244119/


All Articles