This article was written for a client due to the fact that we were unable to test the Affiliate Window API with the documentation available at the time
Affiliate Window offer a tracking and management solutions for maintaining an affiliate program. This works by directing sales to a merchant from an affiliates’ website. In exchange for displaying the merchants’ advertising the affiliate receives commission for sales that originate from the affiliate site. Affiliate Window are one of the market leaders in providing a tracking and management solution.
In order to exchange information between merchant and the affiliate there is an API for exchange of data via XML and SOAP over HTTP(S). AffiliateWindow provide a comprehensive description of the API1 to their clients and a PHP example2,3 on how to access this information. This example is very powerful for those organisations that have PHP development resources and is very easy to integrate with PHP based websites however there are limited resources for those who may wish to use other development tools,4 test file structures from the command line, store requests and responses for audit purposes, etc.
This document describes a way to use the interface from a Linux or Mac OS X command line.
In order to use this script the Linux server must have curl installed (available on Debian based systems with “apt-‐get install curl” and on RedHat based systems with “rpm –Uvh curl” or “yum install curl”.
Mac OS X 10.6 (Snow Leopard) and potentially earlier versions have curl pre-‐ installed so no further installation is required.
In addition to the software a username and password are required. These are available from AffiliateWindow. It is also useful to have a copy of the API to hand.
There are two files. The first, request.xml, contains the request in XML format as per the API. The second, request.sh, reads request.xml and writes response.xml in the current working directory. Debugging can be assisted by changing the line “curl \” to be “curl –-‐verbose \”.
In this example we are fetching affiliate transaction data using the example from the API5.
<?xml version=”1.0″ encoding=”UTF-8″?>
Figure 1 - request.xml
Since we are fetching affiliate data from the version 3 API the correct URL is to call is http://api.affiliatewindow.com/v3/AffiliateService. To fetch merchant data the URL is http://api.affiliatewindow.com/v3/MerchantService. Note that the path (v3/AffiliateService and v3/MerchantService) is case sensitive.
–user YOUR_USERNAME_HERE:YOUR_PASSWORD_HERE \
–data @request.xml \
-H “Content-Type: application/soap+xml” \
–output response.xml \
Figure 2 - request.sh (curl version)
The curl command line can have many options. In this example the important things to note are:
- The @ before the data file that instructs curl not to escape the payload data.
- -‐H “ContentType:” adds a header that is essential for the input to be treated as a SOAP request by the server.
It is also possible to use the wget command6 on Linux systems:
–header=“Content-Type: application/soap+xml” \
–output-document=“response.xml” \ http://api.affiliatewindow.com/v3/AffiliateService
Figure 3 - request.sh (wget version)
Debugging can be added by changing “wget \” to “wget -‐-‐debug \”.
Note that these scripts have only been tested with version 3 of the API and this may change in the future with new releases.
It took some time to make this work. In the end WireShark was run to packet sniff a working PHP version of the code. The important aspect of making this work appears to be the content type of application/soap+xml in the header.