Oct.25

Using the LinkShare Merchandiser Web Service


When I first generated my token, the services were not working for me. After contacting support (which was easy to do), they promptly replied:

Please be note that the feed token MAY take up to 24 hours to fully activate from the time it was initially generated/reset.

Linkshare Web Services Token

Linkshare Web Services Token

However, 30 minutes after being generated, the token was active.

Building the query URL is fairly straight-forward. At its simplest, you pass your token and a keyword:

http://productsearch.linksynergy.com/productsearch?token=[your token here]&keyword=backpack

Refer to the Merchandiser Query API page for documentation on the other parameters you may use, such as category, merchant, and sorting.

Putting it all together:

$cURL = 'http://productsearch.linksynergy.com/productsearch?token=[your token here]&keyword=backpack';
$xml = simplexml_load_file($cURL);

for ($i = 0; $i < count($xml->item); $i++) {
	$oProduct = $xml->item[$i];
	?>
	<div class="post">
		<h2 class="title"><a href="<?= $oProduct->linkurl ?>" target="_blank" style="text-decoration:none"><?= $oProduct->productname ?></a></h2>
		<div class="entry">
			<p><a href="<?= $oProduct->linkurl ?>" target="_blank"><img src="<?= $oProduct->imageurl ?>" alt="<?= $oProduct->productname ?>" title="<?= $oProduct->productname ?>" style="max-height:100px; max-width:100px; float:left" onerror="ImgError(this)" /></a><?= $oProduct->description->short ?></p>
			<br style="clear:all" />
		</div>
		<div class="meta">
			<p class="byline"><a href="<?= $oProduct->linkurl ?>">$<?= number_format($oProduct->price, 2) ?></a></p>
			<p class="links"><a href="<?= $oProduct->linkurl ?>" class="more">Get More Info</a> <b>|</b> From <a href="<?= $oProduct->linkurl ?>" class="comments"><?= $oProduct->merchantname ?></a></p>
		</div>
	</div>
	<?php
}

Refer to the 3rd step in my Building a Datafeed Site series for an explanation of the ImgError JavaScript event.

This PHP code is meant to be dropped into a static WordPress template, many of which can be downloaded from free CSS templates.

If you wanted to improve performance, you could save the Merchandiser results to MySQL for local caching.

To see a site built on the LinkShare Merchandiser API, check out this site on Transcend SD Cards.

May 11, 2011 Update
LinkShare has updated the URLs for their APIs. The code here has been reflected with the new URLs.

Resources
Share this Story:
  • facebook
  • twitter
  • gplus

Comments(23)

  1. Garrett
    2231 days ago

    Nice write-up. As always, the code samples are a huge help for wrapping your mind around how feeds function. FYI, I’m currently seeing feed errors on your SD site (not sure if it’s your side or LS).

    Thanks.

    • Eric Nagel
      2231 days ago

      Hahaha – of course, the service is down now 🙂

      Maybe my next post should be about using memcache to cache results for when the provider’s API goes down 🙂

      • Garrett
        2231 days ago

        I’d by interested in that one…seems like hitting APIs in realtime (in my limited experience) is a quick/easy way to get rolling, but probably not a great long-term solution if your site gets good traction.

  2. Trackback: Data Feeds – Using the LinkShare Merchandiser Web Service (Eric Nagel Blog) | LinkShare UK Blog

  3. Trackback: Affiliate Marketing Data Feeds – Using the LinkShare Merchandiser Web Service (Erc Nagel Blog) | LinkShare Blog

  4. Sarita
    1539 days ago

    Hi I am facing the following error on running the file:

    Warning: simplexml_load_file() [function.simplexml-load-file]: http%3A%2F%2Fmyprojectdemonstration.com%2Fdevelopment%2Fprojecttest%2Fcashverseur%2FAPI%2Flinkshare%2Findex.php%3Ftoken%3D594978f1ee8529987d5d516816e57358fa79ca6c3206108fdfada906a9eac5e2:2: parser error : Extra content at the end of the document in /home/myprojec/public_html/development/projecttest/cashverseur/API/linkshare/index.php on line 50

    Warning: simplexml_load_file() [function.simplexml-load-file]: Warning: simplexml_load_file() [f in /home/myprojec/public_html/development/projecttest/cashverseur/API/linkshare/index.php on line 50

    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/myprojec/public_html/development/projecttest/cashverseur/API/linkshare/index.php on line 50
    There are no available products at this time.

    I have put the url=”http://myprojectdemonstration.com/development/projecttest/cashverseur/API/linkshare/”

    $token = “594978f1ee8529987d5d516816e57358fa79ca6c3206108fdfada906a9eac5e2”;

    Please share the code if there is some php support error.I am runnig PHP 5.2.1 on my server.

    Regards

  5. Sarita
    1539 days ago

    No, I am not.I just want to get all products not any specific but i started with this value.Could you please help me how to get all products?I have only account and also don’t have much information about this.But i just want to get all products without any criteria.
    Many thanks!

    • Eric Nagel
      1538 days ago

      Review the documentation to see if this is available. You may be better off with their FTP service, and just download the feeds

  6. Sarita
    1529 days ago

    Can’t i get any product feed if I’m not approved by any merchant program?

    • Eric Nagel
      1529 days ago

      No. You must be approved to a program before you can get the feed.

  7. Sarita
    1529 days ago

    Thanks for the reply Eric.

  8. Sarita
    1529 days ago

    Thanks Eric.Finally i got products.Can you help me with clickbank API to get products?

  9. Ritesh
    1400 days ago

    Hello,
    i am new in feed api development.
    i have one problem in linkedshare product full merchandiser file in php how to i can auto download file from my ftp.
    i use ft_get but its only download 10 file.

    than i have one more query how to easy way to in parse this .xml.gz file to table please guide me.

    regards
    Ritesh

    • Eric Nagel
      1367 days ago

      Ritesh,

      I seem to recall something goofy about how Linkshare handles FTP files. Like the files don’t actually exist, but if you request them, it’ll magically appear and be sent to you? It’s unrelated to the API, so I don’t know much more about it.

      Use the API to determine your merchant relationships, then request the file (even if it’s not there) and you may get it.

  10. david E
    1373 days ago

    Eric,
    would you know how to query the linkshare Merchandiser Query tool by isbn. I cant find information on that anywhere

    • Eric Nagel
      1367 days ago

      David,

      I doubt you can. Maybe use another API to go from ISBN -> book title, then search Linkshare for the book title?

  11. Muhammad Junaid
    1148 days ago

    Hello,

    Please can you help me to get Sales from the Linkshare? I could not find any sufficient data about the API. Thanks in advance.

  12. rajp
    1112 days ago

    Eric,
    My code works perfect on my local machine but fails on the hosting site.Did you overcome anything like this issue with hosting.is it something to do with the simplexml_load_file is not enabled on hosting

    • Eric Nagel
      1112 days ago

      It could be just about anything – what’s the error message you’re receiving?

Leave a comment

Comment