Sono stato in grado di codificare una soluzione per chiamare un'API Marketo Rest e fare l'OAuth. Di seguito è riportato un how-to Il codice seguente mostra le nozioni di base, ma necessita di pulizia, registrazione e gestione degli errori per garantire la produzione.
È necessario ottenere gli URL di Rest api per l'istanza di Marketo. Per fare ciò, accedere a marketo e navigare su Admin \ Integration \ Web Services e utilizzare gli URL nella Sezione API Rest.
È necessario ottenere l'ID utente e il segreto da marketo - accedere a Admin \ Integration \ Launch Pont. Visualizza i dettagli del tuo servizio di Rest per ottenere identità e segreti. Se non si dispone di un servizio, quindi seguire queste istruzioni http://developers.marketo.com/documentation/rest/custom-service/.
Infine, è necessario il proprio ID elenco per l'elenco di lead che si desidera ottenere. Puoi ottenerlo navigando al tuo elenco e copiando la parte numerica dell'ID dall'URL. Esempio: https://XXXXX.marketo.com/#ST1194B2 -> Lista 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; }
}
Non ci sono veramente esempi o documentazione sulla chiamata alle API di Market REST usando .net/C#. Non sono sicuro del motivo per cui a qualcuno non è piaciuta la domanda. – Cameron
Perché è stato downvoted? Questa è una domanda valida. –