question

improveyourlife avatar image
0 Likes"
improveyourlife asked ·

Using GetSingleItem with SimpleXMLElement

I'm using finding service has URL and it works fine, $url = ' http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced'; $url .= '&SERVICE-NAME=FindingService&SERVICE-VERSION=1.0.0&GLOBAL-ID=EBAY-GB'; $url .= '&SECURITY-APPNAME=' . $appid . '&RESPONSE-DATA-FORMAT=XML'; $url .='&keywords=' . $itemnumber; I now need to call GetSingleItem $url2 = ' http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=XML≈pid=' . $appid . '&siteid=0&version=967&ItemID=' . $itemnumber . "&IncludeSelector=Description,ItemSpecifics"; Both return success using $resp2 = file_get_contents($url2); but when i use $xml2 = new SimpleXMLElement($resp2); it returns a non object, how can i call the elements from resp2 for its details similar too $itemid = (string) $xml->searchResult->item->itemId; $shipcost = (string) $xml->searchResult->item->shippingInfo->shippingServiceCost;
apitrading api
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
Hi I have done this and it is empty, do i need to cast int or string to it? $xml2->Item->Quantity
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

clickimusprime avatar image
0 Likes"
clickimusprime answered ·
Extracting data from XML works the same way in every XML API, but the nodes vary. Save the XML response to a file and load it into a hierarchical viewer like Firefox. Or read the docs, which include a hierachical display. $qty = (string) $xml2->searchResult->item->Quantity; <--- $xml2 2018-01-04T23:54:39.220Z Success E1033_CORE_APILW_18542200_R1 1033 <--- $xml2->Item 1 <--- $xml2->Item->Quantity 0 If you still can't figure it out, find a PHP tutorial.
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
I dobt get an error just cant get it out of the var_dump array, tried allsorts similar to finditemsadvanced but no success
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
Ok, ive done a var_dump and can see the Quantity but not sure how to call that out of the xml2, i'm getting an error using GetSingleItem ["PostalCode"]=> string(6) "wn69jt" ["PrimaryCategoryID"]=> string(6) "183498" ["PrimaryCategoryName"]=> string(69) "Health & Beauty:E Cigarettes, Vapes & Accs:E Cigarettes, Vapes & Mods" ["Quantity"]=> string(1) "5" ["Seller"]=> array(4) { ["UserID"]=> string(15) "improveyourlife" ["FeedbackRatingStar"]=> string(6) "Purple" ["FeedbackScore"]=> string(3) "525" ["PositiveFeedbackPercent"]=> string(5) "100.0" } ["BidCount"]=> string(1) "0" ["ConvertedCurrentPrice"]=> string(5) "31.92" ["CurrentPrice"]=> string(4) "23.9" ["ListingStatus"]=> string(6) "Active" ["QuantitySold"]=> string(1) "0" ["ShipToLocations"]=> string(9) "Worldwide" ["Site"]=> string(2) "UK" ["TimeLeft"]=> string(14) "P25DT20H42M21S" ["Title"]=> string(80) "Aspire CF SUB OHM Mod Battery Ecig Vape Kit Carbon Fibre +Aspire k3 +Samsung 25r" ["HitCount"]=> string(2) "81" ["PrimaryCategoryIDPath"]=> string(19) "26395:183497:183498" ["Country"]=> string(2) "GB" ["ReturnPolicy"]=> array(4) { ["ReturnsWithin"]=> string(7) "14 days" ["ReturnsAccepted"]=> string(16) "Returns Accepted" ["Description"]=> string(14) "Only if broken" ["ShippingCostPaidBy"]=> string(5) "Buyer" } ["AutoPay"]=> string(5) "false" ["IntegratedMerchantCreditCardEnabled"]=> string(5) "false" ["HandlingTime"]=> string(1) "0" ["ConditionID"]=> string(4) "1000" ["ConditionDisplayName"]=> string(3) "New" ["GlobalShipping"]=> string(5) "false" ["QuantitySoldByPickupInStore"]=> string(1) "0" ["NewBestOffer"]=> string(5) "false" ["AvailableForPickupDropOff"]=> string(4) "true" ["EligibleForPickupDropOff"]=> string(4) "true" } }
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
This does not work either if ($xml2) { $json = json_encode($xml2); $array = json_decode($json,TRUE); echo "

QUANTITY IS - " . array_search("Quantity",$array) ."

"; }
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
Pasting the URL i get XML result
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
I cant for the life of me work this API out, i have just var_dump the findItemsAdvanced and it looks identical, i would be glad to move to GetSingleItem but i cant seem to get info off the documentation. I have look at searchResult for findingApi, i found information right away on that but item listing details for GetSingleItem.. no, goin to look again
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
I've looked at docs, cant see wood for trees this is how a call findItemsAdvanced so if i need to change to getsingleitems i'm not sure of the tree structure it outputs $qty = (string) $xml2->searchResult->item->Quantity;
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

clickimusprime avatar image
0 Likes"
clickimusprime answered ·
Since the Shopping API returns different data, it has a different format and doesn't return a searchResult node. Look at the docs or the XML response itself to determine where the data you need is located. Also, FWIW, if you already have the item number the call to findItemsAdvanced may not be necessary. GetSingleItem/GetMultiplItem return a lot of the same data. Depends on your needs.
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

improveyourlife avatar image
0 Likes"
improveyourlife answered ·
I have got rid of the errors, only thing now is how do i extract the quantity of that item? is it from xml2? when i use this method same as $url findItemsAdvanced i get a non object error $qty = (string) $xml2->searchResult->item->Quantity;
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.