Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

Using the LinkShare Merchandiser Web Service

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers.

Linkshare Web Services
Linkshare Web Services
Building a product site using the LinkShare Merchandiser Web Service is one of the easiest and most straight-forward tasks you can do. If you’re just getting started with datafeeds and product-based sites, you may want to start here.

If you don’t have an account, you first need to signup with LinkShare. Then login, and click on Web Services under Links. Next, generate or update your token. You’ll need this when making requests.

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.

Comments
  • Garrett
    Posted October 26, 2010 12:52 pm 0Likes

    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
      Posted October 26, 2010 12:54 pm 0Likes

      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
        Posted October 26, 2010 1:08 pm 0Likes

        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.

  • Trackback: Data Feeds – Using the LinkShare Merchandiser Web Service (Eric Nagel Blog) | LinkShare UK Blog
  • Trackback: Affiliate Marketing Data Feeds – Using the LinkShare Merchandiser Web Service (Erc Nagel Blog) | LinkShare Blog
  • Sarita
    Posted September 17, 2012 8:29 am 0Likes

    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

  • Sarita
    Posted September 18, 2012 12:51 am 0Likes

    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
      Posted September 18, 2012 8:14 am 0Likes

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

  • Sarita
    Posted September 27, 2012 6:36 am 0Likes

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

    • Eric Nagel
      Posted September 27, 2012 10:16 pm 0Likes

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

  • Sarita
    Posted September 28, 2012 12:53 am 0Likes

    Thanks for the reply Eric.

  • Sarita
    Posted September 28, 2012 3:33 am 0Likes

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

  • Ritesh
    Posted February 4, 2013 12:48 am 0Likes

    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
      Posted March 8, 2013 9:05 am 0Likes

      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.

  • david E
    Posted March 2, 2013 4:25 pm 0Likes

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

    • Eric Nagel
      Posted March 8, 2013 9:04 am 0Likes

      David,

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

  • Muhammad Junaid
    Posted October 14, 2013 5:22 am 0Likes

    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.

  • rajp
    Posted November 18, 2013 8:47 pm 0Likes

    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
      Posted November 18, 2013 9:00 pm 0Likes

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

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.