[SalesForce] Exact Target Rest Auth API

I'm trying to call the exact target auth api for the first time. I'm getting a 407 Proxy Authentication Required. Can you please let me know where I'm going wrong.

I'm using the following call

https://auth.exacttargetapis.com/v1/requestToken Content-Type: application/json{"ClientId":"myClientID","ClientSecret":"myClientSecret"}

With the above as requestUrl:

   HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
            request.Method = "POST";
            request.Timeout = 1000;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

I've also tried the following:

with https://auth.exacttargetapis.com/v1/requestToken in url
and "{\"ClientId\":\"myClientIDInHere\",\"ClientSecret\":\"MyclientSecretInHere\"}" in postdata.

It gets as far getRequestStream, but also get a 407 Proxy Authentication Exception
public static string WebRequestinJson(string url, string postData)
{
string ret = string.Empty;

        StreamWriter requestWriter;

        var webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
        try
        {
            if (webRequest != null)
            {
                webRequest.Method = "POST";
                webRequest.ServicePoint.Expect100Continue = false;
                webRequest.Timeout = 20000;

                webRequest.ContentType = "application/json";
                //POST the data.
                using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
                {
                    requestWriter.Write(postData);
                }
            }

            HttpWebResponse resp = (HttpWebResponse) webRequest.GetResponse();
            Stream resStream = resp.GetResponseStream();
            StreamReader reader = new StreamReader(resStream);
            ret = reader.ReadToEnd();
        }
        catch (Exception e)
        {
            var msg = e.ToString(); 
        }
        return ret;

Best Answer

I have created a Postman Collection which shows you how to use requestToken method correctly; download Collection here. Note that I'm using raw data in my POST request (but form-data also works) and the request includes a Content-Type header with value application/json.

Related Topic