Marketo Integration

Import Users to Marketo

To import your Auth0 users into Marketo:

Create a User Data File

Start by navigating to the Extensions section of the Dashboard and open the User Import / Export Extension. On the extension page, select Export from the menu.

Next, set the Export Format to the required file format. Adobe Campaigns accepts file imports in CSV format so choose the Tab Separated Value file (*.csv) option.

User Import/Export Extension Format

At the top in the Fields section, provide a User Field and Column Name for each user attribute to include in the export. For example:

User Field Column Name
email Email Address
created_at Created At
given_name First Name
family_name Last Name

User Import/Export Extension Fields

After adding the user fields, click on the Export Users button to start the export. Once the export is complete, download the CSV file to use in the following section.

Import a User Data File

To import the user data file to Marketo, perform a POST request to the Bulk Leads endpoint. Set the content-type header of the request to multipart/form-data and include a file parameter with your exported CSV file as well as format parameter set to csv. For example:


curl --request POST \
  --url https://marketo_rest_api_base_url/bulk/v1/leads.json \
  --header 'authorization: Bearer {MARKETO_ACCESS_TOKEN}' \
  --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
  --form file=@auth0_users.csv \
  --form format=csv
var client = new RestClient("https://marketo_rest_api_base_url/bulk/v1/leads.json");
var request = new RestRequest(Method.POST);
request.AddHeader("authorization", "Bearer {MARKETO_ACCESS_TOKEN}");
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"auth0_users.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\nContent-Type: text/plan\r\n\r\ncsv\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://marketo_rest_api_base_url/bulk/v1/leads.json"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"auth0_users.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\nContent-Type: text/plan\r\n\r\ncsv\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
	req.Header.Add("authorization", "Bearer {MARKETO_ACCESS_TOKEN}")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://marketo_rest_api_base_url/bulk/v1/leads.json")
  .header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
  .header("authorization", "Bearer {MARKETO_ACCESS_TOKEN}")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"auth0_users.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\nContent-Type: text/plan\r\n\r\ncsv\r\n-----011000010111000001101001--\r\n")
  .asString();
var form = new FormData();
form.append("file", "auth0_users.csv");
form.append("format", "csv");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://marketo_rest_api_base_url/bulk/v1/leads.json",
  "method": "POST",
  "headers": {
    "authorization": "Bearer {MARKETO_ACCESS_TOKEN}"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var fs = require("fs");
var request = require("request");

var options = { method: 'POST',
  url: 'https://marketo_rest_api_base_url/bulk/v1/leads.json',
  headers: 
   { authorization: 'Bearer {MARKETO_ACCESS_TOKEN}',
     'content-type': 'multipart/form-data; boundary=---011000010111000001101001' },
  formData: 
   { file: 
      { value: 'fs.createReadStream("auth0_users.csv")',
        options: { filename: 'auth0_users.csv', contentType: 'text/csv' } },
     format: { value: 'csv' } } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"authorization": @"Bearer {MARKETO_ACCESS_TOKEN}" };
NSArray *parameters = @[ @{ @"name": @"file", @"fileName": @"auth0_users.csv", @"contentType": @"text/csv" },
                         @{ @"name": @"format", @"value": @"csv", @"contentType": @"text/plan" } ];
NSString *boundary = @"---011000010111000001101001";

NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
    [body appendFormat:@"--%@\r\n", boundary];
    if (param[@"fileName"]) {
        [body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
        [body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
        [body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
        if (error) {
            NSLog(@"%@", error);
        }
    } else {
        [body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
        [body appendFormat:@"%@", param[@"value"]];
    }
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://marketo_rest_api_base_url/bulk/v1/leads.json"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://marketo_rest_api_base_url/bulk/v1/leads.json",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"auth0_users.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\nContent-Type: text/plan\r\n\r\ncsv\r\n-----011000010111000001101001--\r\n",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer {MARKETO_ACCESS_TOKEN}",
    "content-type: multipart/form-data; boundary=---011000010111000001101001"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("marketo_rest_api_base_url")

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"auth0_users.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\nContent-Type: text/plan\r\n\r\ncsv\r\n-----011000010111000001101001--\r\n"

headers = { 'authorization': "Bearer {MARKETO_ACCESS_TOKEN}" }

conn.request("POST", "/bulk/v1/leads.json", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://marketo_rest_api_base_url/bulk/v1/leads.json")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer {MARKETO_ACCESS_TOKEN}'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"auth0_users.csv\"\r\nContent-Type: text/csv\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\nContent-Type: text/plan\r\n\r\ncsv\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
import Foundation

let headers = ["authorization": "Bearer {MARKETO_ACCESS_TOKEN}"]
let parameters = [
  [
    "name": "file",
    "fileName": "auth0_users.csv",
    "contentType": "text/csv"
  ],
  [
    "name": "format",
    "value": "csv",
    "contentType": "text/plan"
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: NSUTF8StringEncoding, error: &error)
    if (error != nil) {
      println(error)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent!
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

var request = NSMutableURLRequest(URL: NSURL(string: "https://marketo_rest_api_base_url/bulk/v1/leads.json")!,
                                        cachePolicy: .UseProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.HTTPMethod = "POST"
request.allHTTPHeaderFields = headers
request.HTTPBody = postData

let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    println(error)
  } else {
    let httpResponse = response as? NSHTTPURLResponse
    println(httpResponse)
  }
})

dataTask.resume()

The response should look something like this:

{
    "requestId": "e42b#14272d07d78",
    "success": true,
    "result": [{
        "batchId": 1234,
        "status": "Importing"
    }]
}

You can check the status of your import using the Get Import Lead Status API and your import job's batchId. For example:


curl --request GET \
  --url https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json \
  --header 'authorization: Bearer {MARKETO_ACCESS_TOKEN}'
var client = new RestClient("https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json");
var request = new RestRequest(Method.GET);
request.AddHeader("authorization", "Bearer {MARKETO_ACCESS_TOKEN}");
IRestResponse response = client.Execute(request);
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("authorization", "Bearer {MARKETO_ACCESS_TOKEN}")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json")
  .header("authorization", "Bearer {MARKETO_ACCESS_TOKEN}")
  .asString();
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json",
  "method": "GET",
  "headers": {
    "authorization": "Bearer {MARKETO_ACCESS_TOKEN}"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var request = require("request");

var options = { method: 'GET',
  url: 'https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json',
  headers: { authorization: 'Bearer {MARKETO_ACCESS_TOKEN}' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"authorization": @"Bearer {MARKETO_ACCESS_TOKEN}" };

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer {MARKETO_ACCESS_TOKEN}"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("marketo_rest_api_base_url")

headers = { 'authorization': "Bearer {MARKETO_ACCESS_TOKEN}" }

conn.request("GET", "/bulk/v1/leads/batch/BATCH_ID.json", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)
request["authorization"] = 'Bearer {MARKETO_ACCESS_TOKEN}'

response = http.request(request)
puts response.read_body
import Foundation

let headers = ["authorization": "Bearer {MARKETO_ACCESS_TOKEN}"]

var request = NSMutableURLRequest(URL: NSURL(string: "https://marketo_rest_api_base_url/bulk/v1/leads/batch/BATCH_ID.json")!,
                                        cachePolicy: .UseProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.HTTPMethod = "GET"
request.allHTTPHeaderFields = headers

let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    println(error)
  } else {
    let httpResponse = response as? NSHTTPURLResponse
    println(httpResponse)
  }
})

dataTask.resume()

And the response:

{
    "requestId": "8136#146daebc2ed",
    "success": true,
    "result": [{
        "batchId": 1234,
        "status": "Complete",
        "numOfLeadsProcessed": 123,
        "numOfRowsFailed": 0,
        "numOfRowsWithWarning": 0
    }]
}

That's it! You successfully imported your Auth0 users to Marketo.