PHP XML-XML curl function not working. Please help

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi Everyone,

I'm trying to get the following php script to work with an ebay API. It
sends XML and then returns XML and formats it into links. THing is it
doesn;t work, and I'm not sure why. Can anyone see where I'm going

Thank you in advance,



$query = 'ipod';

$endpoint = ' ?';

$resp =

if ($resp) {
    $results = '';

    foreach($resp->Item as $item) {
        $link  = $item->ViewItemURLForNaturalSearch;
        $title = $item->Title;

        $results .= "<a href=\"$link\">$title</a><br/>";

else {
    $results = "Oops! Must not have gotten the response!";

<!-- Build the HTML page with values from the call response -->
eBay Search Results for <?php echo $query; ?>

<h1>eBay Search Results for <?php echo $query; ?></h1>

<?php echo $results;?>



function constructPostCallAndGetResponse($endpoint, $query)
    $xmlRequest  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    $xmlRequest .= "<FindItemsAdvancedRequest
    $xmlRequest .= "<QueryKeywords>";
    $xmlRequest .= $query;
    $xmlRequest .= "</QueryKeywords></FindItemsAdvancedRequest>";

    $session  = curl_init($endpoint);                       // create a
curl session

    curl_setopt($session, CURLOPT_POST, true);      // POST request type
    curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); // set the
body of the POST
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);    // return
values as a string - not to std out
    $headers = array(
      'X-EBAY-API-CALL-NAME: FindItemsAdvanced',
      'X-EBAY-API-SITEID: 0',                                 // Site 0
is for US
      'X-EBAY-API-APP-ID: My ID Goes Here. Removed for security',
      'X-EBAY-API-VERSION: 559',
      'Content-Type: text/xml;charset=utf-8',
    curl_setopt($session, CURLOPT_HTTPHEADER, $headers);    //set
headers using the above array of headers

    $responseXML = curl_exec($session);                     // send the request

    return $responseXML;  // returns a string
} // function

Re: PHP XML-XML curl function not working. Please help

raj escribió:
Quoted text here. Click to load it

When I run the code you paste, the eBay server replies:

    Application ID invalid

Quoted text here. Click to load it

Ah, yep, this must be the reason.

My guess is that you have some silly typo in your code but since your
XML parser routines cannot handle error responses you don't even see the
error message. Just try this to see raw XML:

echo constructPostCallAndGetResponse($endpoint, $query);

Next time try to change "does not work" with something more informative
like "I see no error messages but the response is empty".

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor al baño María:

Site Timeline