在 Marketo 开发团队的 Kenny Elkington 的帮助下,我解决了这个问题!
我发现的第一件事是,要使用 REST 方法,我首先需要按照此处的说明进行操作 -
http://developers.marketo.com/blog/quick-start-guide-for-marketo-rest-api/
为了能够生成身份验证令牌。
然后我可以使用 -
private String getToken()
{
String url = host + "/identity/oauth/token?grant_type=client_credentials&client_id=" + clientId + "&client_secret=" + clientSecret;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
String json = reader.ReadToEnd();
Dictionary<String, String> dict = JsonConvert.DeserializeObject<Dictionary<String, String>>(json);
return dict["access_token"];
}
然后,一旦我获得了访问令牌,我就能够对自己进行身份验证,这使我能够创建如下潜在客户 -
private String host = "" //host of your marketo instance, https://AAA-BBB-CCC.mktorest.com
String url = host + "/rest/v1/leads.json?access_token=" + getToken();
String requestBody = "----JSON INPUT----";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Accept = "application/json";
StreamWriter wr = new StreamWriter(request.GetRequestStream());
wr.Write(requestBody);
wr.Flush();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
String responseString = reader.ReadToEnd();
然后我可以使用响应字符串来确定是否成功创建了潜在客户,或者我可以将错误消息输出给用户。