In this next step of our case study on getting started with affiliate marketing, we will examine how to automate the process of adding affiliate products from LinkShare to our site.
Merchandiser Data Feed Program
LinkShare offers a service that they refer to as the Merchandiser Data Feed Program that allows publishers to maintain a database of product links that is updated daily. Unfortunately, there is a one-time setup fee of $250 unless specific criteria has been satisfied.
Since we are hoping to get started with as little upfront cost as possible, this is probably not our best option and is one that I have not personally explored. However, there is another option for those of us that do not meet the criteria to avoid the setup fee.
Merchandiser Query Tool API
Before you get scared by the mention of API, let me tell you that this is extremely easy to implement and does not require extensive technical knowledge when you use the process that I am about to share with you.
The Merchandiser Query Tool API is a Web service that allows you to run a query against any one, or all, of the merchants that you have a partnership with at LinkShare and will return a listing of affiliate products. The query can return a maximum of 4,020 search results, which should be more than sufficient for our needs.
So how do we leverage this service?
In order to efficiently use this service, we are going to create a custom script (fancy word for PHP page) that we can use throughout our site to display relevant affiliate products.
There are a few prerequisites that must be met in order to use this script: 1) we have an account at LinkShare.com and have been approved for at least one merchant; 2) we have requested and received our web services token from LinkShare.
Creating Custom LinkShare Script
Now that we have satisfied the prerequisites, we are ready to create our script. Don’t worry, it really isn’t as bad as it sounds. To get our script working on our site, we need to perform the following steps.
- Save the code from Code Example #1 to a file named linkshare.php
- Open the file in a text editor and insert our LinkShare token on Line 4
- Upload the file to our web host
Now, wasn’t that easy?
At this point, we have a functioning custom script on our site that will return affiliate products from our merchants at LinkShare. To test that our script is working, simply open a new browser or tab and navigate to the following URL:
1 | http://yourdomainname.com/linkshare.php?keyword=yourkeyword |
Be sure to actually update the link to include the appropriate domain name and a relevant keyword for at least one merchant. If everything is setup properly, we should see a display of products from at least one of our merchants.
There is the possibility that we will see a message that there aren’t any available products. That doesn’t mean that the script is not working, as we may simply need to change the keyword to match the products of our approved merchants.
Also, this script assumes that our web host supports PHP5 as the call to simplexml_load_file will not work if your host is running PHP4. If you encounter this problem, let me know and I can share the code to work around that issue.
One last note about the code example, you will note that there is a URL on Line 2 that has been commented out. For whatever reason, I found the standard LinkShare link to be extremely unreliable and often resulted in a script failure. By changing to the URL on Line 3, I have not had any problems but feel free to experiment with either URL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <? //$url = "http://feed.linksynergy.com/productsearch"; $url = "http://65.245.193.50/productsearch"; $token = "ADDTOKENHERE"; // Add your LinkShare token here $results = ''; $resturl = $url."?"."token=".$token; if (isset($_GET["keyword"])) { $keyword = $_GET["keyword"]; $resturl .= "&keyword=".$keyword; } if (isset($_GET["cat"])) { $category = $_GET["cat"]; $resturl .= "&cat=".$category; } if (isset($_GET["max"])) { $maxresults = $_GET["max"]; $resturl .= "&max=".$maxresults; } if (isset($_GET["mid"])) { $mid = $_GET["mid"]; $resturl .= "&mid=".$mid; } $SafeQuery = urlencode($resturl); $xml = simplexml_load_file($SafeQuery); if ($xml) { foreach ($xml as $item) { $link = $item->linkurl; $title = $item->productname; $imgURL = $item->imageurl; $price = $item->price; $merchantname = $item->merchantname; $description = $item->description->short; if($link != "") $results .="<div id=\"product\"> <div id=\"product_img\"><a href=\"$link\"><img border=\"0\" src=\"$imgURL\"/></a></div> <div id=\"product_link\"><a href=\"$link\">$title</a></div> <div id=\"product_desc\">".$description."</div> <div id=\"product_price\">Add to Cart: <a href=\"$link\">$price</a></div> </div>"; } } if ($results == '') { $results = "<div id=\"product\">There are no available products at this time.</div>"; } print $results; ?> |
Now that we have our custom script installed on the server and everything is working great, we need to investigate how we can actually implement this script on our site.
Implementing Custom LinkShare Script
Ideally, we will want to incorporate one or more affiliate products within the content of a blog post. As an example of what we want to accomplish, look at how the affiliate products are integrated in this post about buying the right football gloves.
In order to implement the script in the manner described here, our site will need to satisfy the following prerequisites: 1) Exec-PHP plugin must be installed, as we will be executing PHP code within a blog post 2) our web host must support cURL (if not, there is a workaround).
Next, we simply need to copy the code from Code Example #2 into our blog post and update the URL parameters as necessary. There are four parameters that we can specify:
- keyword :: Replace KEYWORD with the keyword that you would like to use for your product search
- cat :: Replace CATEGORY with a product category to restrict the search results
- max :: Replace MAX with the maximum number of products to return in the search results
- mid :: Replace MERCHANT with the merchant id of an advertiser to limit the search results to their products only
Of the four parameters above, only the keyword is required. The remaining parameters are optional, although they will assist in refining our search results so the products match the content of our post as closely as possible.
Note: If you choose not to use one of the optional parameters, remove the entire parameter (i.e. remove “&mid=MERCHANT” not just “MERCHANT” if you choose not to specify a merchant).
To receive the best quality search results, it may be necessary to experiment with a variety of parameter settings.
1 2 3 4 5 6 7 8 9 | <?php $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, "http://" . $_SERVER['SERVER_NAME'] . "/linkshare.php?keyword=KEYWORD&cat=CATEGORY&max=MAX&mid=MERCHANT"); curl_setopt($cURL, CURLOPT_HEADER, 0); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); $strPage = curl_exec($cURL); curl_close($cURL); echo($strPage); ?> |
At this point we should have our custom script installed on the server and have a new blog post that is returning relevant affiliate products within the content of the post.
Wrapping It Up
The process above is exactly what I have done to integrate affiliate products on both Pro Football Workouts and Chicago Football Gifts. Keep in mind that the code provided above does not include any true error handling, but it has been working well on my sites.
Also, as mentioned earlier, you may encounter problems depending on certain configurations made by your web host. The two most likely issues will be support of PHP5 and/or cURL. If you encounter problems with either of these, let me know and I can offer assistance.
Is this a perfect process?
Not by any means, as there is still a good deal of manual work involved and the code could certainly be improved upon (adding robust paging controls, error handling, etc.). This should get you started though and allow you to start adding affiliate products from LinkShare.
Now go earn some money!






{ 75 comments… read them below or add one }
At the start of the post, I must admit that this could be very technical and I may not be able to do it on my own. But your explanations really cleared up some things for me. Maybe, when I find the time, I might put this into action.
John, it really isn’t too bad but I understand that the technical aspect might make a lot of people shy away. If you have questions, be sure to let me know.
I really cannot stand Linkshare to be quite honest with you. But you did write a pretty good comprehensive DIY guide for adding products. I wish Linkshare had a more easier interface to navigate.
Good to see a detailed example like this. Most websites I’ve seen just say you should do this and this but never elaborates on how, but you do. Now, I’m not going to be doing anything with affiliate products any time soon, so I don’t really give a damn in that aspect, but it’s fun for me to read about this kind of stuff because I like to know how things work… that and I’m a programmer.
I wonder if that’s a static address though. What if their IP changes?
For anyone with any php knowledge, this is pretty sraight-forward code to read. For people not familiar with php, it’s still simple in that they can just plug in the token and go.
Nice post!
Kelvin Kaos last blog post..WordGirl: My New Favorite PBS Show
Thanks Kelvin! This post was actually a lot of fun to write as I love digging into the technical things and trying to explain that in a way that will help other people.
I was trying to decide how much detail to give about the entire code block and hope that I provided enough without losing people.
Re: the IP, I haven’t had any issues with it and have been using it for quite some time. That also means that I haven’t reverted back and tried their domain name either. This has been one of those “if it ain’t broke, don’t fix it” thinks for me.
that was great examples really .. i visited several sited , blogs but nobody have time to explain the things, they usually put a short code for any task and they dont worry that it is understandable by others or not..
but you really did a great job…
Glad to hear that you liked it and hopefully you will find it useful. Thanks for stopping by!
My eyes started glazing over halfway through, so you’ll have to forgive me for that. One question, though. This script is limited to this particular network, I assume. So what about the others (if there are others)? Isn’t tthere some kind of script which can pull in data from all the major aff. networks?
Ling, you’re right in that this is only for LinkShare. I’ve got a separate script for Share-a-Sale as the process is different for me. There is no question that these could be combined into one script, which is what many of the tools have done for you.
The problem with making one script of your own is that each network, as well as each feed, is different enough that it can quickly become unmanageable.
It is all over my head Derek. I doubt that I can do what you expect me to do in your last paragraph. I like your style though!
It never hurts to try.
Sweet! I’ve already copied the code so I can use it, but now I have to figure out if I already have a LinkShare account or if I still need to create one. Oh, and I already copied your code so even if you take it down, it’s too late
Nicks last blog post..Make PDF Files With PDFCreator
Lol, you can be pretty certain that this code will be here as long as this blog exists.
Let me know if you have any questions, as well as if you are able to make any use out of this code.
It is really the technical side of it, as you are saying derek, that scares people off! The information is nice, but I am having difficulties to understand the codes!
I tried to use Linkshare on one of my previous ventures and couldn’t really make it pay. I have been building my traffic to my current blog and have been getting plenty of click throughs to amazon so hopefully will get some conversions and make some money. Then I might have a look into some other advertisers.
As I already have a linkshare account then I will probably use them so these tips will come in very handy when i get around to it.
Currently busy writing articles for my blog and redesigning one of my sites from scratch. New Design, New Content, New Host, Everything
Man this looks hard. Its gonna take quite a while to figure this out.
45 Second Newss last blog post..Israeli’s Accused Of War Crimes
Thanks for the instructions.
That’s a good technical article. However I wasn’t not very comfortable doing this on my own. In fact adding the right affiliate product on your page from LinkShare could be tricky. Thanks for your insight.
Nice post, I was looking for something like this and you’re explanation of how to do it was great. Thanks again!
thanks for such nice article this is really helpfull for my blog
thanks
I’m pretty new to affiliate marketing. I’ve been using Amazon, which I like because they have such a wide array of products that they can always match something to your content. I will check out this Linkshare thing though as I think it will enable me to get more targeted products on my sites.
BTW. I developed a object oriented wrapper for cURL in PHP that may be of use to you. It just makes your code neater and easier to manage. I tend to build a generic getURL( $url, $additional_opts ) for my scripts, so I just need to call a function to get a url. You can find the class here with some instructions.
Davids last blog post..Enableing Chinese, Arabic and Other High Unicode in WordPress Slugs
Does anyone have any comments on the difference between LinkShare and ShareASale. I’m especially interested in why a merchant would use both or why those promoting affiliate programs would prefer one over the other. Do you all use both? Would you stop promoting a store that eliminated one of them? Which do you prefer? Thanks for any input.
Internet Strategists last blog post..Have a Blog? You Win By Reading This Blog Review Contest Entry on Best Blog Design!
One must know HTML or coding for doing such thing. I can’t do that.
That seems kind of complicated to me, but if I really wanted to, I’m sure I could figure it out. I’d rather just stick with Amazon than messing with all that code, though, although I have to admit I have derived pleasure from coding in the past.
Thanks for the code, works great!
Thomass last blog post..Meditation classes for kids in schools
wow..thanks for sharing the codes. very informative article. keep on posting.. I need that in my website…
I need to really start caching via affiliate links. So far private ad sales, adsense and once in a while referral income are the only monetization means.
Does anyone know about a good Amazon affiliate plugin?
Ajith Edassery | Blog Moneys last blog post..Google Monitor: Track your search engine ranking for FREE
Wow, I never knew that How To Add Affiliate Products From LinkShare. That’s pretty interesting…
I have downloaded the product datafeed XML file from my Linkshare FTP account. In this file there are limited imformation, how can i get all the information ?
I have used linkshare earlier but I find it very difficult to make sales and dropeed it
Sanavass last blog post..Create a Blog at a Mouse Click
Thank you for this tutorial, I learned a lot!
I’d like to take the script a bit farther and develop an application that will pull products via web services.
I’m not using WordPress and I really don’t want to implement RSS for my site on a mass scale. I really need one that will allow me to compile my own data feeds since they won’t provide any unless you’re a performer or have money to invest.
Can you point me in the right direction?
~Karen
Nice to see a tutorial like this on the Linkshare system, I’d love to point you at a resource that I’ve developed which is a free plugin for wordpress to show Linkshare merchandiser products within your blog.
its available here.
Linkshare Merchandiser Plugin
I hope it will be useful.
.-= Tony´s last blog ..Meat and Cheese T-Shirts =-.
Great post! Keep up the good work!
.-= j henry´s last blog ..If you want to be one… =-.
hey friend!
thank you for sharing your experience with us! i am very grateful.
Ont thing though… I uploaded the code in .php but when i tried it the page gave me a 401 not found error.
then i uploaded it in .htm / .html and gave me a no resilts found error with a partial code on the screen.
u can check out yourself with the test link. my domain is savingsonthefly.com
your help will be greatly appreciated!
Thank you so much, this was tremendously helpful.
Hi
thanks for this easy to understand guide. You can make use of the merchandiser for free if you’ve been a member for 3 months and have made 50 sales in the previous month – don’t quote me on the exact criteria and maybe its different for UK residents. Anywho, are you able t provide an explanation on how to use the merchandiser. I’ve downloaded the folders from the linkshare server but I don’t have a clue where to put them, what to do with them etc…
thanks for your time!
This code works great for the results I was looking for. Just one question, I have been searching all over and I am new to PHP and have some knowledge in HTML and I am looking for a way to format the results into 2 or 3 columns across instead of just the list, but I have not been able to figure out using tables with the results. Is this possible? Thanks so much for this information as it has been very helpful!
Hi,
fantastic post and very useful. I’m tryin a couple of plugins and codes on my site. I’m looking to add the paginator, similar to what you have on your chicago footbal page. Would you mind sharing the code or instructions.
Thank you much.
This would probably make the most sense as a separate post to fully explain the pagination.
In a nutshell, in the Code Example #2 above I’ve added two additional parameters to the link for the current page number and the results per page. In the Code Example #1, I read in the values of these parameters and if not yet set I assign default values. In the loop of the results, I then offset the array of results according to the page number I am on and build the pagination links at the end of the loop.
I know that probably doesn’t make a ton of sense, so that is why I will provide the code and explanation in the form of a post.
Thanks for the info. I very much look forward to your post with the code. I know a thing or two about PHP but not savy; an example code is of great help. Also the XML response does include the number of pages – is there a way to use that also as the final value?
Thanks
Stop on by later this morning for the pagination code. As a note, you’ll find that the main section of code was changed from the original example but I have provided the full page of code.
Hope you find it helpful.
Hi,
i can’t find it – I’ll check-in again later.
Thanks in advanced for all your help.
Sorry, you can find the new post right here.
I hope this thread isnt dead yet. I have configured the Code Example 1 on my website and it works fine, however, I want to format the search results as a table 3 columns wide. I dont really mind if all results are on one page, but I do need the table results. Can someone help me out?
I do agree that there is manual work to be done here. But it is worth it if you are able to start the affiliate products. I’m sorry I can’t help you big24fan. I would like to see that.
I am a novice. I can’t figure out how to paste a picture banner at all.
I did do some text pastes, but it was months ago and I remember having to be sure to copy only certain things or it wouldn’t work. Now, I am forgetting how to do even that.
Can you help me with the picture banners?
What exactly are you trying to do with banners? I’m not sure I follow so if you could provide additional information that would be helpful…
Hello Buddies,
I was trying to work further on your great code, but it seems like “cat” parameter to get categories feed is not working, for example i put “Electronics” for cat and put “computer” as keyword but no results, i used the same spellings as in linkshare dashboard, also try it with cat_ID but nothing worked, any suggestion on this.
Thanks n take care
Are you limiting your query to a particular merchant? Did you change the MID from my example to an accurate merchant?
If you’d like, shoot me the query you are using via email and I will give it a go to see if I can determine why it isn’t working as expected.
THank you very much derek for your reply . And it is strange, it works now. i think there was some issue at linkshare side. i didnt use the MID , i just use the cat, keyword and my token, I will ask for your help again
.
Thanks again!
Happy to hear it is working for you now! I appreciate you following up and letting me know.
Thanks man ! I am searching many hours to find a way to implement to automate the coupons from linkshare. Great!
Buy a New Computer hopes you will read… Computer Hardware Discount Coupons
Derek,
I am pretty familiar with API’s. I use CJ, Amazon, Yahoo etc regularly. But with link share no matter what I do to the query I always get a “Problem Loading Page” error unless I change the token and then I get an xml result that says invalid token.
Any Suggestions?
James, have you checked the URL you are using for their service? Take a look up in Code Example #1 and you will see that I had to change the URL that I was using to the IP address of their server as I was getting extremely inconsistent results when using the fully qualified name.
Beyond that, I would probably try using the token that gives you the “Problem Loading Page” error but strip it down to a really basic query. I don’t know what else you were adding to the query but I would try something as basic as using your token and a single keyword, or just a single merchant id, to see if you can get results. It could be a problem with your query, but this first step will confirm your token works properly.
Hey Derek,
We have been having a heck of a time with this REST call to Linkshare your post is great but still does not work for us simply telling us there is no data at this time. We have tested our query in the Google REST Client and it is operable. We could not test that in your code as we are novices and need a cut and paste solution. We did run your code as products would not be too bad but what we wanted to start with is coupons. Our REST client call returns 800 results via XML but we cannot find the code to impliment this correctly. Could you help us out with getting this to work with products and coupons? We could try to do it with cut and paste examples or just hire you for a couple of hours? Thanks
Chris McGrath hopes you will read… Build your own Grey Water Recycling System
The only problem I see with this approach of integrating affiliate products is duplicate content for seo purpose, many other websites as well will publish same content.
I prefer to incorporate affiliate products manually and alter product description text to make it unique.
Gregory hopes you will read… CAM Delivers XML Payload Precision for Business Partners
Gregory, that is a very valid point and one that does need consideration. One option that I have used in the past is to pull the product feeds into my own database or as individual posts and then go back and edit the content to be unique. If you’re only doing a product here and there, it will probably be easier to do manually as you mention.
Duplicate content is really something you have to consider if you use this technic but as you said you can spin the content and avoid that kind of problems.
Hey, it’s awesome that I can just copy and paste it…great job!
Hi,
I am getting following error:
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity “ftp%3A
I have followed your above instructions but unable to resolve it. Can u Help me.
Thanks in advance
Does your host support simplexml? What version of PHP is your host running? Also, what host are you using? I’ve read numerous posts about people with HostGator needing to have php.ini setup differently for their sites in order for the simplexml to work.
thanks for this.
very usefuld for a newbie ind this bussines like me..
klaus@iphone 4s pris hopes you will read… 4.000.000 iPhone 4S solgt første 3 dage!
Yikes ! The title of this post piqued my interest as I seek a better way to create an online store, but wow, it went over my head. I am currently using a third party tool, but it is limiting.
APIs intimidate me. That being said, your instructions seem complete, so I’ll re-read, and re-re-read them.
Which third party tool are you using? I’ve been using Datafeedr for quite some time and am really pleased with it. There are a few mentions of it here on the blog if you’re interested in reading more about it.
Derek: A while back I briefly looked into Datafeedr, but decided to stick with Popshops. I want more flexibility without paying a price. Thanks for reminding me of Datafeedr – I’ll peruse your blod for more info. Sheese…I wish I was more knowledgeable in this area.
Wow this isn’t what I had expected I had some trouble with this a few weeks ago and I only wish this had been published then. It took forever to trouble shoot my problems.
Linkshare seems pretty darn cool. I’d just stuck to a limited amount of networks till recently. I’ll explore and play around with it! Thanks.
Hi, Thanks for sharing this. It was exactly what I was looking for. If anyone is having problems getting the above code to work, you may need to change the linkshare URL on line 4 to:
$url = “http://productsearch.linksynergy.com/productsearch”;
Vijay hopes you will read… 2 For 1 Hour Rexflexology Session
Thanks for the update. I know at the time this was written the various links were painfully inconsistent in their reliability.
I have tried this and had no such luck, but I am new. I would like to have this option on one of my pages. Can anyone assist me in getting this done?
steve hopes you will read… 2.00 Carat Natural Sapphire and Genuine Diamond Ring – $39 + Free Shipping
Hi Derek,
I got the code exmple 1 to work took me a bit but finally works…
now as for code example 2 i installed the wp php exec plugin and activated it. But when i plug in the curl code it just posts as if i put it in my blog as text. here is the url http://skincare.deelfinders.com/skin-care-anti-aging/perricone-md-neuropeptide-facial-conformer-2-ounce-tube/ please let me know if i need to do the curl work around or perhaps the plugin is not working right.
thanks for your post it Will defiantly help me!
Deelfinders hopes you will read… Perricone MD Neuropeptide Facial Conformer, 2-Ounce Tube
How can we take advantage of the following info for automated link generation ….
http://cli.linksynergy.com/cli/publisher/links/webServices.php?serviceID=43
im really needing to get this to work so i can create all the nitch sites i have planned.
Deelfinders hopes you will read… Perricone MD Neuropeptide Facial Conformer, 2-Ounce Tube
It looks like you may have fixed this, or removed the code, as I am not seeing it displayed on the page.
well i removed it got impatient… the code you see there is a coupon plug in which is nice but not what im looking for.. i want image content as well… i reposted the script you can see it now any help would be awesome sir!
Deelfinders hopes you will read… 3M Products – 3M – Lint Roller Refill Roll, 30 Sheets/Roll – Sold As 1 Each – Exclusive ScotchTM film backed adhesive. – Remove lint, pet hair, dust and more from clothing with smooth rolling action. – Exclusive coreless roll for less environmental waste. – 30 sheets per roll. -
It looks like the opening line of the code sample is missing. The
< ?phpline. Without that the code will not work as it doesn't recognize that you're starting a PHP code block.{ 2 trackbacks }