Let’s say you want to change a lead’s score in Marketo using the APIs. This is possible to do with the REST API using the Create/Update Lead endpoint.
Below is a code sample in Ruby that shows how to make this call.
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" endpoint = "/rest/v1/leads.json" #Replace with your access token auth_token = "?access_token=" + "ac756f7a-d54d-41ac-8c3c-f2d2a39ee325:ab" request_url = marketo_instance + endpoint + auth_token #Build request body data = { "action" => "updateOnly", "input" => [ { "email" => "example@email.com", "leadScore" => "30" } ] } #Make request response = RestClient.post request_url, data.to_json, :content_type => :json, :accept => :json #Returns Marketo API response puts response |
In the JSON body of the request, we specify updateOnly as the action. This means the request will only work if the lead exists, otherwise it will fail. If you want to create a lead if one does not exist, then specify createOrUpdate as the action.
We use the lead’s email as the primary identifier to find the lead record in Marketo. Finally, we specify the value for the lead’s score using the key leadScore.
It possible to update 300 leads at time using this method. For more information, please see the Create/Update Lead endpoint.