0

I am trying to post the JSON data to Pardot. I have used the info from here to call the Pardot API and currently using Pardot form handler to post the data. I want to know if i could the data via Pardot API call by using CREATE or UPSERT instead of using a form handler. Below is my code

class SendingDataToPardot
    {
        public string Login()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

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


            var loginInfo = new Dictionary<string, string>
            {
                {"email", "xx"},
                {"password", "xxx"},
                {"user_key", "xxx"}
            };

            var httpContent = new FormUrlEncodedContent(loginInfo);

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

                if (response.IsSuccessStatusCode)
                {
                    string resultValue = response.Content.ReadAsStringAsync().Result;
                    apiKey = XDocument.Parse(resultValue).Element("rsp").Element("api_key").Value;


                    return apiKey;

                }
                else
                {
                    return null;
                }


            }
        }

        public string POST()
        {
            string Api_Key = Login();
            var url = "form handler url";

            var contactFormData = new Dictionary<string, string>
            {
                {"email", "test@test.com"},
                {"FirstName", "xxx"},
                {"LastName", "xxxxx"},
                {"Comments", "this is a test"}

            };

            var data= new FormUrlEncodedContent(contactFormData);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Api_Key);
                HttpResponseMessage response = client.PostAsync(url, data).Result;
                string result = response.Content.ReadAsStringAsync().Result;
                return result;
            }

        }
    }
}
John Smith
  • 1,027
  • 15
  • 31

1 Answers1

0

For most of the APIs Pardot exposes, you need to do XML work with it.

Looks like you are using Java, so you might have luck using a public library, even if just for understanding communication patterns (we had to rewrite it for our purposes, but it did serve as a great blueprint).

Have a look at the https://github.com/Crim/pardot-java-client project and see if it helps you out.

Adam Erstelle
  • 2,454
  • 3
  • 21
  • 35