question

bowiggings avatar image
0 Likes"
bowiggings asked ·

Help converting php finding code to shopping api

Hi I'm trying to convert my php finding api code to the shopping api to do a GetSingleItem call. Could anyone help me with why this is failing please... ack == "Success") { $results = ''; // If the response was loaded, parse it and build links foreach($resp->Item as $item) { $Description = $item->Description; $itemid = $item->ItemID; // For each SearchResultItem node, build a link and append it to $results $results .= "$itemid $Description"; } } // If the response does not indicate 'Success,' print an error else { $results = "

Oops! The request was not successful. Make sure you are using a valid "; $results .= "AppID for the Production environment.

"; } echo $results; ?>
PHP
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.

bowiggings avatar image
0 Likes"
bowiggings answered ·
Thank you so much Answer, your a star. Spent hours on that last night and rewrote the whole thing twice was simply that one line... if ($resp->Ack == "Success") { Cheers pal :)
· 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 ·
Your API request is fine. Your code is failing the "ack" check. XML node names are case sensitive in PHP, use $resp->Ack instead. You can dump out the $resp variable to see the results or dump out the $apicall variable and paste it into a browser to view formatted XML. You'll find it easier to debug if you use something simple like Title instead of the Description node.
· 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.

helios825 avatar image
0 Likes"
helios825 answered ·
I'm not sure if you can use simplexml_load_file to make a remote API call. file_get_contents would do it, however, as a courtesy. Then you could use simplexml_load_string() on the string of data-response you get from it. A better way to make outgoing calls is to use the cURL library. I wrote a [helper function here][1] you are welcome to use, to make handling a little easier. [1]: http://www.helios825.org/cURLfriend.php
· 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.