Marketo Rest API를 호출하고 OAuth를 수행 할 수있는 솔루션을 코딩 할 수있었습니다. 아래는 방법입니다 아래 코드는 기본 사항을 보여줍니다. 그러나 정리 작업, 로깅 및 오류 처리가 필요합니다.
Marketi 인스턴스의 나머지 API URL을 가져와야합니다. 이렇게하려면 marketo에 로그인하고 Admin \ Integration \ Web Services로 이동 한 다음 Rest API 섹션의 URL을 사용하십시오.
마켓에서 사용자 ID와 비밀번호를 가져와야합니다. Admin \ Integration \ Launch Pont으로 이동하십시오. 귀하의 휴식 서비스의 세부 사항을보고 신분과 비밀을 얻으십시오. 서비스가없는 경우 다음 지침을 따르십시오 http://developers.marketo.com/documentation/rest/custom-service/.
마지막으로 얻으려는 리드 목록의 목록 ID가 필요합니다. 귀하의 목록으로 이동하여 URL 밖의 ID의 숫자 부분을 복사하면됩니다. 예 : https://XXXXX.marketo.com/#ST1194B2 -> 목록 ID = 1194
private void GetListLeads()
{
string token = GetToken().Result;
string listID = "XXXX"; // Get from Marketo UI
LeadListResponse leadListResponse = GetListItems(token, listID).Result;
//TODO: do something with your list of leads
}
private async Task<string> GetToken()
{
string clientID = "XXXXXX"; // Get from Marketo UI
string clientSecret = "XXXXXX"; // Get from Marketo UI
string url = String.Format("https://XXXXXX.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id={0}&client_secret={1}",clientID, clientSecret); // Get from Marketo UI
var fullUri = new Uri(url, UriKind.Absolute);
TokenResponse tokenResponse = new TokenResponse();
using (var client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(fullUri);
if (response.IsSuccessStatusCode)
{
tokenResponse = await response.Content.ReadAsAsync<TokenResponse>();
}
else
{
if (response.StatusCode == HttpStatusCode.Forbidden)
throw new AuthenticationException("Invalid username/password combination.");
else
throw new ApplicationException("Not able to get token");
}
}
return tokenResponse.access_token;
}
private async Task<LeadListResponse> GetListItems(string token, string listID)
{
string url = String.Format("https://XXXXXX.mktorest.com/rest/v1/list/{0}/leads.json?access_token={1}", listID, token);// Get from Marketo UI
var fullUri = new Uri(url, UriKind.Absolute);
LeadListResponse leadListResponse = new LeadListResponse();
using (var client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(fullUri);
if (response.IsSuccessStatusCode)
{
leadListResponse = await response.Content.ReadAsAsync<LeadListResponse>();
}
else
{
if (response.StatusCode == HttpStatusCode.Forbidden)
throw new AuthenticationException("Invalid username/password combination.");
else
throw new ApplicationException("Not able to get token");
}
}
return leadListResponse;
}
private class TokenResponse
{
public string access_token { get; set; }
public int expires_in { get; set; }
}
private class LeadListResponse
{
public string requestId { get; set; }
public bool success { get; set; }
public string nextPageToken { get; set; }
public Lead[] result { get; set; }
}
private class Lead
{
public int id { get; set; }
public DateTime updatedAt { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public DateTime datecreatedAt { get; set; }
public string firstName { get; set; }
}
.net/C#을 사용하여 Market REST API를 호출하는 것에 대한 예제 또는 문서는 없습니다. 왜 누군가가 그 질문을 좋아하지 않았는지 모르겠습니다. – Cameron
왜 이것을 다운 그레이드 했습니까? 이것은 유효한 질문입니다. –