joe
joe

Reputation: 1135

API related with XML?

Is it done correctly? I am still confused with how api works. I am newbie. I have gone around google to find answers. I followed tutorial and tried to modify it. It is basic one.

I would like to retrieve the images of products which is on sale (mode=hot) for slideshow. I will appreciate the help if you could help me to understand how api shld be done.

EDIT I am trying to pull the images from database in pinnacle cart. so i wanted to list out what it have in xml. All xml you see below is on source view but not on webpage itself, is it normal? Also when I am trying to show the images on webpage and the images don't appear. I am not sure where I went wrong.

     <Product>
  <Price><![CDATA[695.00000]]></Price>
 <Visible><![CDATA[Yes]]></Visible>
<Taxable><![CDATA[Yes]]></Taxable>
<Weight><![CDATA[0.00]]></Weight>
<UPC><![CDATA[]]></UPC>
<Sku><![CDATA[]]></Sku>
<Title><![CDATA[Necklace]]></Title>
<URL><![CDATA[https://xxxxx/staging/index.php?p=product&amp;id=80]]></URL>
<ThumbnailImageUrl><![CDATA[http://www.xxxxxxxxxx.com/staging/images/products/thumbs/100040.jpg]]></ThumbnailImageUrl>
<ImageUrl><![CDATA[http://www.xxxxxxxx.com/staging/images/products/100040.jpg]]></ImageUrl>
<Discontinued><![CDATA[No]]></Discontinued>
<Options>    </Options>
<Added><![CDATA[2010-05-12 13:50:00]]></Added>
<ManufaturerName><![CDATA[]]></ManufaturerName>
<Description><![CDATA[<p>&nbsp;</p><p>&nbsp;</p>]]></Description>
<AmazonId><![CDATA[]]></AmazonId>
<AmazonItemCondition><![CDATA[]]></AmazonItemCondition>
<AmazonIdType><![CDATA[]]></AmazonIdType>
<EbayCategoryId><![CDATA[]]></EbayCategoryId>
<YahooPath><![CDATA[]]></YahooPath>
<GoogleItemCondition><![CDATA[]]></GoogleItemCondition>
<PricegrabberCategory><![CDATA[]]></PricegrabberCategory>
<PricegrabberItemCondition><![CDATA[]]></PricegrabberItemCondition>
<PricegrabberPartNumber><![CDATA[]]></PricegrabberPartNumber>
<InventoryControl><![CDATA[Yes]]></InventoryControl>
<PID><![CDATA[80]]></PID>
<ProductId><![CDATA[100040]]></ProductId>
<Qoh><![CDATA[1]]></Qoh>
<NextagCategory><![CDATA[]]></NextagCategory>
<NextagPartNumber><![CDATA[]]></NextagPartNumber>
<NextagItemCondition><![CDATA[]]></NextagItemCondition>
</Product>

My code

    <?php
    $shop='www.xxx.com/staging/content/admin/plugins/openapi/index.php?';
    $user = "asd";
    $password = "ad";
    $token = 'token';

    // Assemble the account url
    $url = 'https://'.$shop."username=".$user."&amp;password=".$password."&amp;token=".$token. "&apiType=xml&call=GetProducts&mode=hot";

    // Setup the cURL object
    $curl = curl_init();
    curl_setopt($l_oCurl, CURLOPT_POST, 1);
    curl_setopt( $curl, CURLOPT_URL, $url );

    $response=curl_exec($curl);
    curl_close($curl);
    $image_xml = new SimpleXMLElement($response);
   **foreach($xml->ThumbnailImageUrl as $thumbs){
echo "<img src=".$thumbs."/>";**
}

    ?>

Upvotes: 0

Views: 465

Answers (1)

Gordon
Gordon

Reputation: 317119

SimpleXml can load remote URLs with simplexml_load_file and all libxml bases extensions can be used with a custom Stream Context. Just create your custom context with stream_context_create and then set it with libxml_set_streams_context. See Context List and Options

To generate a URL encoded string, use http_build_query

As for using SimpleXml, please see the Basic Usage Examples in the PHP Manual. You basically just have to traverse to the node and echo it, e.g.

echo $sxe->someNode->someOtherNode->ThumbnailImageUrl;

Upvotes: 3

Related Questions