I was able to program the solution to call the Marketo Rest API and make OAuth. The following is a practical guide. The code below shows basic information, but cleaning requires cleaning, logging, and error handling.
You need to get the Rest api URL for your Marketo instance. To do this, go to marketo and go to Admin \ Integration \ Web Services and use the URLs in the Rest API section.
You need to get your user ID and secret from marketo - go to Admin \ Integration \ Launch Pont. View holiday information for an identifier and secret. If you do not have the service, follow these instructions http://developers.marketo.com/documentation/rest/custom-service/ .
Finally, you need a list id for the list of leads you want to receive. You can get this by going to your list and copying the numeric part of the id from the URL. Example: https://XXXXX.marketo.com/#ST1194B2 → List 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; } }
source share