我正在尝试将JSON数据发布到Pardot。我已经使用来自here的信息来调用Pardot API,并且当前使用Pardot表单处理程序来发布数据。我想知道是否可以使用CREATE或UPSERT而不是使用表单处理程序通过Pardot API调用来获取数据。下面是我的代码
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;
}
}
}
}发布于 2020-03-10 11:17:43
对于Pardot公开的大多数API,您都需要使用它进行XML工作。
看起来您正在使用Java,所以您可能会幸运地使用公共库,即使只是为了理解通信模式(我们必须重写它才能达到我们的目的,但它确实是一个很好的蓝图)。
看一看https://github.com/Crim/pardot-java-client项目,看看它是否对您有帮助。
https://stackoverflow.com/questions/60039183
复制相似问题