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.
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:
However, 30 minutes after being generated, the token was active.Please be note that the feed token MAY take up to 24 hours to fully activate from the time it was initially generated/reset.
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
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
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
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.
Sarita
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
Eric Nagel
Don’t change the $cURL value
Sarita
Thanks Eric,I used the same value but not getting any response. Please check http://myprojectdemonstration.com/development/projecttest/cashverseur/API/linkshare/
I am using the $cURL=$cURL = ‘http://productsearch.linksynergy.com/productsearch?token=my-token-value&keyword=backpack’;
Thanks
Eric Nagel
Well, you’re getting a response, so the code it working. Are you partnered with any merchants that carry backpacks (your keyword)?
Sarita
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
Review the documentation to see if this is available. You may be better off with their FTP service, and just download the feeds
Sarita
Can’t i get any product feed if I’m not approved by any merchant program?
Eric Nagel
No. You must be approved to a program before you can get the feed.
Sarita
Thanks for the reply Eric.
Sarita
Thanks Eric.Finally i got products.Can you help me with clickbank API to get products?
Ritesh
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
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
Eric,
would you know how to query the linkshare Merchandiser Query tool by isbn. I cant find information on that anywhere
Eric Nagel
David,
I doubt you can. Maybe use another API to go from ISBN -> book title, then search Linkshare for the book title?
Muhammad Junaid
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.
Eric Nagel
Try something like
wget -O linkshare1289476762.txt -S
http://cli.linksynergy.com/cli/publisher/reports/downloadReport.php?bdate=date&edate=date&cuserid=myid&cpi=mypassword
via AbestWeb
http://www.abestweb.com/forums/rakuten-linkshare-20/transaction-report-api-not-working-now-123012.html
rajp
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
It could be just about anything – what’s the error message you’re receiving?