Let’s say you want to get all leads that were added to a list this month. Using the Get Lead Activities REST API, you can get this data.
Before calling the Get Lead Activities API, it is necessary to get an access token from the Authentication API and also get a starting date token from the Get Paging Token API.
Below is example code in Ruby that walks through the individual API endpoints you would have to call to return all leads added to a list this month.
Step One: Get Access Token
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
require 'rest_client' require 'json' #Build request URL #Replace AAA-BBB-CCC with your Marketo instance marketo_instance = "https://AAA-BBB-CCC.mktorest.com/identity/oauth/token?grant_type=client_credentials" #Relace with your client id client_id = "99985d09-22a9-3jl2-84av-f5baae7c3a45" #Replace with your your client secret client_secret = "tZPVrKiEmUDezE18yZfeaPlTJ2vKn2fw" request_url = marketo_instance + "&client_id=" + client_id + "&client_secret=" + client_secret #Make request response = RestClient.get request_url #Parse reponse and return only access token results = JSON.parse(response.body) access_token = results["access_token"] puts access_token |
Step Two: Get Paging Token
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
require 'rest_client' require 'json' #Build request URL #Replace AAA-BBB-CCC with your Marketo instance marketo_instance = "https://AAA-BBB-CCC.mktorest.com" endpoint = "/rest/v1/activities/pagingtoken.json" #Replace with your access token auth_token = "?access_token=" + "ac756f7a-d54d-41ac-8c3c-f2d2a39ee325:ab" #Specify date since_date_time = "&sinceDatetime=2015-01-01T00:00:00-08:00" request_url = marketo_instance + endpoint + auth_token + since_date_time #Make request response = RestClient.get request_url #Returns Marketo API response puts response |
Step Three: Get Activity Data
To determine the Activity Type Id needed for this call, query the Get Activity Types API. The Get Activity Types API will return a schema with all activity types and associated ids. For example, it will return id 12 for new leads created and id 1 for webpage visit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
require 'rest_client' require 'json' #Build request URL #Replace AAA-BBB-CCC with your Marketo instance marketo_instance = "https://AAA-BBB-CCC.mktorest.com" endpoint = "/rest/v1/activities.json" #Replace with your access token auth_token = "?access_token=" + "ac756f7a-d54d-41ac-8c3c-f2d2a39ee325:ab" #Specify datetime needed as nextPageToken since_date_time = "&nextPageToken=GIYDAOBNGEYS2MBWKQYDAORQGA5DAMBOGAYDAKZQGAYDALBQ" #Specify activities needed activity_type_ids = "&activityTypeIds=24" request_url = marketo_instance + endpoint + auth_token + since_date_time + activity_type_ids #Make request response = RestClient.get request_url #Returns Marketo API response puts response |
Step Four: The Get Lead Activites API will return a paging token with each response that you can use to paginate through the results set.
For more information, please see the REST API documentation.