best ways to use the shareasale api

Post on 14-May-2015

8.031 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Slides from my presentation at ShareASale's Think Tank 2013 held in Denver, CO on how to use ShareASale's Affiliate API

TRANSCRIPT

Best Ways to Use the APIShareASale Think Tank 2013Eric Nageleric@ericnagel.com

What is the ShareASale API?

● API = Application Programming Interface○ An application programming interface (API) specifies

how some software components should interact with each other.

○ It’s a way for your website to talk directly to the ShareASale system

● Affiliate API● Merchant API

Where to find the ShareASale API

Affiliate API Under Tools

Merchant API Under Tools

Affiliate API: AuthenticationThe Authentication HashAuthentication Hash : SHA-256 Hash in 64 character Hex format of the string "YourAPIToken:CurrentDateInUTCFormat:APIActionValue:YourAPISecret" (without quotes)

For example, for following values:Token: NGc6dg5e9URups5o

API Secret: ATj7vd8b7CCjeq9yQUo8cc2w3OThqe2e

String to Hash: NGc6dg5e9URups5o:Thu, 14 Apr 2011 22:44:22 GMT:bannerList:ATj7vd8b7CCjeq9yQUo8cc2w3OThqe2e

UTC Date: Thu, 14 Apr 2011 22:44:22 GMT

API Action: bannerList

The correct HTTP Headers would be:x-ShareASale-Date: Thu, 14 Apr 2011 22:44:22 GMT

x-ShareASale-Authentication: 78D54A3051AE0AAAF022AA2DA230B97D5219D82183FEFF71E2D53DEC6057D9F1

Affiliate API: Authentication

IP RestrictionsThese are the IPs that will be accessing the data. Since the script will reside on your server, use your server’s IP.

Start > Runcmdping domain.com

Gives you the IP

Affiliate API: Authentication

HUH????Don’t worry.1. Click “View Sample code in PHP”2. Copy3. Paste4. Change values

Affiliate API: Sample<?php

$myAffiliateID = '';

$APIToken = "";

$APISecretKey = "";

$myTimeStamp = gmdate(DATE_RFC1123);

$APIVersion = 1.8;

$actionVerb = "activity";

$sig = $APIToken.':'.$myTimeStamp.':'.$actionVerb.':'.$APISecretKey;

$sigHash = hash("sha256",$sig);

$myHeaders = array("x-ShareASale-Date: $myTimeStamp","x-ShareASale-Authentication: $sigHash");

Get these values from the API page

We’ll get to this

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://shareasale.com/x.cfm?affiliateId=$myAffiliateID&token=$APIToken&version=$APIVersion&action=$actionVerb");

curl_setopt($ch, CURLOPT_HTTPHEADER,$myHeaders);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_HEADER, 0);

$returnResult = curl_exec($ch);

Affiliate API: Sample

Nothing todo here.

Affiliate API: Sampleif ($returnResult) {

//parse HTTP Body to determine result of request

if (stripos($returnResult,"Error Code ")) {

// error occurred

trigger_error($returnResult,E_USER_ERROR);

}

else{

// success

echo $returnResult;

}

}

else{

// connection error

trigger_error(curl_error($ch),E_USER_ERROR);

}

curl_close($ch);

?>

This is where you take over and put in your custom coding to do whatever you want with the data.

Affiliate API● Activity Details● Activity Summary● Merchant Timespan Report● Today's Stats● Monthly Summary● Void Trail● Traffic● API Token Count● Get Products● Invalid Links

● Datafeed Merchants● Coupon/Deal Merchants● Merchant Status● Merchant Creatives● Merchant Gift Cards● Edit Trail● Payment Summary● Merchant Search● Merchant Search by Product● Ledger Report

Example

Use Activity Details to download transaction data daily and store in your tracking system or email you your commissions.

Trans ID|User ID|Merchant ID|Trans Date|Trans Amount|Commission|Comment|Voided|Pending Date|Locked|Aff Comment|Banner Page|Reversal Date|Click Date|Click Time|Banner Id

37697968|132296|8723|10/16/2012 11:41:05 AM|323.7|71.21|Sale - 620946||||WCG-45500|http://www.wineclubreviewsandratings.com/cellars-wine-club/sparkling-champagne-club-review||2012-10-16 00:00:00.0|11:34:11 AM|43027

Example

Use Coupon / Deal Merchants to download coupons to show on your website

Deal Id|Merchant Id|Merchant|Start Date|End Date|Publish Date|Title|Image(big)|Tracking URL|Image(small)|Category|Description|Restrictions|Keywords|Coupon Code|Edit Date

12104|8684|Checks Unlimited|2009-06-15 00:00:00.0|2050-12-31 00:00:00.0|2008-08-23 18:09:10.0|Personal checks, additional 10% off reorder check pricing.|http://|http://www.shareasale.com/u.cfm?d=12104&m=8684&u=132296|http://||Personal checks only - additional 10% off reorder check pricing default online.|||PJKA|2009-06-18 12:26:34.0

Other Affiliate API Uses

● Get Products○ Search by keyword

to return products for a datafeed site

● Invalid Links○ Make sure you’re not

wasting your traffic

● Merchant Status○ Be alerted when

merchants go offline● Merchant Creatives

○ Get the latest banners from merchants who run seasonal offers

What Do I Do Now?

● Process the data○ See fgetcsv(), split(), explode()○ Save to database○ Send an email

● Automate your script○ Set up a “cron” to have the script run on a regular basis

● More help?○ http://www.ericnagel.com/how-to-tips/shareasale-api.html

■ 4 years old, but it still works.○ http://www.ericnagel.com/how-to-tips/shareasale-prosper202.html

■ If you use Prosper202

Tips

● You have limited API calls. Use them wisely.○ 200 / month = less than 7 per day

i. Activity Detailsii. Trafficiii. Get Productsiv. Invalid Linksv. Coupon / Deal Merchantsvi. Merchant Status

Tips

● While you’re writing your script to process the data, download the data once, then use the local file for processing. This way, only 1 API call will be used.○ $cURL = 'https://shareasale.com/x.cfm?

action=couponDeals&affiliateId=132296&token=az7bFTu3LwioXNRA&XMLFormat=0';// $cURL = 'sas.csv';$fp = fopen($cURL, "r");

TipsSince we’re talking about APIs, why not combine a merchant’s direct API with the ShareASale API?● Get data from merchant’s own API● Change links to ShareASale Deeplinks● …● Profit

http://www.wyzant.com/AffiliateProgram/

Resources● http://blog.shareasale.com/author/ryan/

○ Ryan Frey writes about using all the ShareASale techie things

● http://www.ericnagel.com/tag/shareasale○ I have a few blog posts about ShareASale - keep digging

● http://www.programmableweb.com/api/shareasale-affiliate○ Programmable Web is all things API

Questions?

Eric Nagel

Email: eric@ericnagel.comWebsite: www.ericnagel.comTwitter: @ericnagel

top related