0

我正在尝试将 JSON 数据发布到 Pardot。我已使用此处的信息来调用 Pardot API,并且当前使用 Pardot 表单处理程序来发布数据。我想知道我是否可以通过 Pardot API 调用使用 CREATE 或 UPSERT 而不是使用表单处理程序来获取数据。下面是我的代码

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;
            }

        }
    }
}
4

1 回答 1

0

对于 Pardot 公开的大多数 API,您需要使用它进行 XML 工作。

看起来您正在使用 Java,因此您可能会很幸运地使用公共库,即使只是为了理解通信模式(为了我们的目的,我们不得不重写它,但它确实是一个很好的蓝图)。

查看https://github.com/Crim/pardot-java-client项目,看看它是否对您有帮助。

于 2020-03-10T03:17:42.543 回答