6

I struggled for about a day trying to authenticate against the Pardot API. It didn't like how I was trying to post the message body. So I wanted to post the solution that worked for me. If you have any tips or alternatives I'd like to hear them.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

var url = "https://pi.pardot.com/api/login/version/3";

//(Edit) Shorter way to pass the parameters below
//var postData = new List<KeyValuePair<string, string>>
//{
//    new KeyValuePair<string, string>("email", "<value>"),
//    new KeyValuePair<string, string>("password", "<value>"),
//    new KeyValuePair<string, string>("user_key", "<value>")
//};

var postData = new Dictionary<string, string>
{
    {"email", "<value>"},
    {"password", "<value>"},
    {"user_key", "<value>"}
};

var httpContent = new FormUrlEncodedContent(postData);

using (var client = new HttpClient())
{
    HttpResponseMessage response = client.PostAsync(url, httpContent).Result;

    if (response.IsSuccessStatusCode)
    {
        string resultValue = response.Content.ReadAsStringAsync().Result;
    }
}

Thanks!

3
  • Unclear about what is the issue. You say your solution worked. What is your question?
    – Nkosi
    Commented Jun 1, 2016 at 21:34
  • Not so much a question as publishing a solution to a problem/question I had. Since i had struggled and couldn't find a quick fix i wanted to save someone else the trouble. that was all. If you have anything to add to the solution please contribute.
    – pwDev
    Commented Jun 1, 2016 at 21:59
  • @pwDev SO follows a Q&A format. Could you add an answer, accept it, and edit your question instead? stackoverflow.blog/2011/07/01/…
    – galdin
    Commented Jan 21, 2019 at 11:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.