How to Upload Variable Products Into My Amazon Affiliate Account

Read Time: 12 mins Languages:

The Amazon Associates program, in conjunction with Amazon Spider web Services (AWS), offers developers a powerful means to search the Amazon Store'due south catalog using a RESTful API and integrate information for nearly any product list into a web page. If y'all are a programmer with a business mindset and looking for ways to monetize your site, you lot tin sign upwards to be an Amazon affiliate and earn a commission every fourth dimension a user clicks on your product link and completes a buy. (And as far as affiliate revenue programs go, Amazon'due south commissions are amidst the most generous.)

For those of you who are new to the idea of affiliate marketing, let's suppose y'all are running a blog or website featuring moving picture reviews. For every moving-picture show review that is posted, you tin can benefit by including a link for readers to buy the picture somewhere nearly your article. To brand information technology more attractive to click, the link can include a thumbnail image of the DVD, the full movie proper noun, the lowest toll available, and a "Purchase" button.

In this tutorial, I will bear witness you lot how to create a dedicated, reusable class in PHP that connects to the Production Merchandising API and fetches XML data based on the proper noun of the product and the shopping category (in this instance "Movies"). At the end, we will populate that data into a small, fully customizable HTML template and so that we terminate up with a working demo of a mini affiliate module. Let's get started.

[Delight note before accessing the example demo that if you opt to purchase or rent the DVD from the link provided, information technology will result in a commission payment to Envato Tuts+.]

Registering for an Affiliate ID and Getting Credentials

First, sign up for an business relationship at affiliate-program.amazon.com. It's gratis, and you lot just need to follow the steps to create a contour for your website. You'll exist asked to verify your identity at the end of the process by entering your telephone number, receiving an automated phone call, and entering the passcode that you are given.

Once you've completed the registration, you will be given an Amazon Affiliate ID (in this example, information technology is "envtuts-20"). Log in to your main account area with your username and password and click on the Product Merchandising API tab. There, click on the link to become started using the API.

Yous will need to sign up for Amazon Web Services (aws.amazon.com), if yous accept not done then already. In the AWS console, under Security Credentials, you can generate an access cardinal and cloak-and-dagger cardinal for making API requests. (Note: it is important to go along these credentials individual and secure. Never betrayal them publicly on GitHub or anywhere else online.)

Setting Up Our PHP Helper Class

For the purposes of this example and to continue things relatively simple, we'll implement the Singleton design blueprint to create a static helper course called AmazonAssocHelper .Information technology will include a public method that connects to the API, searches the catalog, and returns product data using certain parameters that we pass. Here is how I set it up:

The first couple of lines declare a namespace for our class and include a third-party class that we'll demand to brand a signed request to the API with our credentials. The three constants I've defined are our all-important affiliate ID, which we obtained later signing upwards, and the AWS access key and secret key. When we make our API requests, the affiliate ID automatically gets inserted into the product link we recall and so that purchases can be appropriately traced to our account and nosotros get paid! Exist sure to fill in all iii of these values for yourself.

The iii private variables refer to search parameters that nosotros'll supply for every asking. I am using "ItemSearch" as our operation choice to look upwardly results. "2013-08-01" is the engagement of the latest API version, which nosotros also need to supply to our signed request, and lastly, nosotros must designate which response groups we would like returned. There are 55 choices birthday, and they vary in size and type of data returned. For our purposes, nosotros are looking for the full title of the movie and the total URL for the detail folio, both of which are in the "Small" response group. Nosotros besides demand a thumbnail image from the "Images" response group, and the everyman new price from the "OfferSummary" group.

The fetch_product_data() function is our publicly exposed method that takes 2 parameters:

  1. a specific key-phrase referring to the proper noun of the product nosotros want to search for
  2. an accustomed Amazon product category

Information technology will ultimately return an array of data pertaining to the top search result parsed from an XML response. (In many cases, the first consequence will exist the product we want, assuming that the key-phrase we supply is specific enough. Equally an alternative, yous may make up one's mind to modify this example to search by the specific ASIN or ID number of the product instead, merely there are pros and cons to this method. If y'all accept a big database of article pages for unlike movies, using a name-based approach volition most likely prove more efficient, as it will permit you to automatically generate product links for all of your manufactures instantly, and save you the actress fourth dimension and attempt of having to manually await up and insert IDs for each i.)

Generating a Signed Asking

The side by side step is to add a helper class that will make the signed request to the product API. I used a third-party office written by Ulrich Mierendorff and wrapped information technology in its ain static course calledAWSSignedRequest. It takes several parameters, including the region (for the U.S. shop, we use "com"), an array of request parameters, our AWS keys, response groups, and the API version that we've already divers. Theget_signed_request() method substantially builds and returns a full URL request cord from all of these pieces.

The final signed request URL volition look like this:

In the AmazonAssocHelper class, place the call to get_signed_request() in a method chosen get_search_results() and pass in an array containing four search parameters ($params) along with the other arguments every bit shown below:

Our $params array includes the operation and the response that we've already divers, as well as values for 'Championship' and 'SearchIndex'. In this case, the SearchIndex is simply the product category we are searching on. Now, nosotros tin can invoke PHP's built-in file_get_contents() part to generate a response from the request, and since the response is an XML document, we utilise some other built-in part,simplexml_load_string(), to load it as an object that nosotros can parse.

Testing the Response and Previewing XML Data

At this indicate, we'll want to be able to endeavour out our API request with some real product values then we can see an bodily example of what our returned XML data looks like before parsing it. Every bit shown above, add together a few test lines to set the header to application/XML and impress out the $response before it gets returned.

Now, create a file that will serve as the main folio where the product link will be shown. I have decided to call information technologyindex.php. At the top, add the following chip of code:

The first two lines declare our namespace and include a global part that allows our class files to exist auto-loaded, since we are not using a PHP framework. The next line is the important one. We call the fetch_product_data() public method on ourAmazonAssocHelper class and assign information technology to an array variable called $product_data, passing in a specific pic name as the central-phrase (I chose "Jurassic World" from the current list of best sellers) and "Movies" equally the category.

When you lot load your folio, the beginning of your XML response should look similar this:

If you lot scroll and scan the output, you lot should be able to see all of the data that will be useful to our demo, including the <DetailPageURL>, <Championship>, <LargeImage>, and <LowestNewPrice>. In that location are the nodes we volition focus on parsing.

Parsing the Response Object

In theAmazonAssocHelper class, create some other method calledget_top_result_data() that takes our XML response object as the parameter. Nosotros can now outset reading the nodes that contain the information that we desire to capture, simply before we go there, allow's program on incorporating some mistake checking. I've added a couple lines at the top of our part to invoke a method that will accept care of parsing Error nodes for us, and I'll go over that in more detail toward the end of this tutorial.

As yous can run into in the lawmaking to a higher place, nosotros start by retrieving the first item node (Detail[0]) from the XML object and storing it in a variable ($first_item). Then, we operate on each of its children to collect the pieces of information we want ($item_title, $item_link, $item_image, $item_price). Finally, we package it all into an assortment with named attributes and return the assortment.

Handling Errors

Create a method called handle_errors() and laissez passer the same XML object. Based on the way this API is set upward, multiple fault nodes with specific codes and messages are set up to appear in either the <OperationRequest> node or the Items <Asking> node. You can test for them by setting an invalid search index or response group. The following code loops through each of the nodes and pushes the fault messages into an array that we return:

Populating the Data in an HTML Template

At this point, you can remove the XML testing calls as we are ready to look at the final data output. In index.php, print the returned $product_data array and load the page. You should run across something similar this:

In one case y'all've verified that the data looks correct for each of the four properties nosotros are interested in, you lot can try running the phone call on other movies or products for comparison. Note that the affiliate ID (in this case "envtut-20") has automatically been inserted into the 'link' equally we should wait.

As a final step, permit'south code a unproblematic block of HTML to brandish our movie data and make information technology link to the purchase page. In alphabetize.php, add the following underneath the PHP block:

Note that in the consequence of an mistake being returned, I've opted to hide the display altogether, simply alternatively, you could display the appropriate error message in its identify.

Now, with CSS styles added, the final output would look something like this:

Amazon Affiliate Link Demo

And there you accept it! Once you lot've launched your chapter module into the earth, you can track all of the purchases and earnings by signing in to your business relationship.

Determination

In this tutorial, we covered all of the steps required for a PHP developer to build a scalable code solution that instantly generates a custom chapter link for virtually whatever production in the Amazon Shop. Based on your needs or preferences, you lot can make up one's mind to change or extend this example with dissimilar parameters.

You may likewise explore the API documentation in more detail on your own to discover even more of what is possible. The real ability in using the Production Merchandising API lies in the flexibility information technology provides for arranging and displaying a full range of real-time information about a production or list of products. With Amazon's default link generator (no coding knowledge required), you do not get most the same amount of command, and your options are express.

The API actually shines on web pages that are generated dynamically and on pages where you need a higher level of command over the appearance of your links, so if you are working on a website or blog forth these lines and looking to incorporate monetization, I hope that you have constitute this tutorial useful.

Did you discover this postal service useful?

clemonswarl1994.blogspot.com

Source: https://code.tutsplus.com/tutorials/build-a-custom-affiliate-link-with-the-amazon-product-merchandising-api--cms-25193

0 Response to "How to Upload Variable Products Into My Amazon Affiliate Account"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel