How to use Commission Junction REST API with .Net

by Admin 30. July 2010 05:10

This code sample shows how to use Commission Junction REST API using .Net. The code is very straight forward. Only thing that you need to pay attention to is that you will be passing your user credentials through request header named Authorization. The value for this header is the Developer Key that was assigned to you when you signed up for Commission Junction web services account. This is a mile long string that was sent to you in your mail box as well when you signed up for CJ Web Service access.


class Program
{
 const string ADVERTISERS_LOOKUP_JOINED = 
 "https://advertiser-lookup.api.cj.com/v3/advertiser-lookup?advertiser-ids=joined";
 static void Main(string[] args)
 {
  var reqUrl = string.Format("{0}", ADVERTISERS_LOOKUP_JOINED);
  var webReq = WebRequest.Create(reqUrl) as HttpWebRequest;
  webReq.Headers.Add("Authorization", App.Default.DEVKEY);
  var resp = webReq.GetResponse() as HttpWebResponse;
  // Get the stream associated with the response.
  var receiveStream = resp.GetResponseStream();
  var readStream = new StreamReader(receiveStream, Encoding.UTF8);
  var respText = readStream.ReadToEnd();
  resp.Close();
  readStream.Close();
  if (resp.StatusCode == HttpStatusCode.OK)
  {
   // Parse response.
   Console.WriteLine(respText);
  }
  else
  {
   // what is the error??
  }
  }
}

Views: 2332

Tags: ,

Advertising

Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli