SOLVED

Alternative to expiring tokens for a routine process

Go to solution
Highlighted
Anonymous
Not applicable

Alternative to expiring tokens for a routine process

Hi,

I'm attempting to automate a weekly update of lead data from our internal servers to Marketo.

using CURL to is pretty cool, but the example is using a token, which expires (found out the hard way) after X hours.

is there a way to use a id/pass/secret to use curl ?

or another alternative?  Im not a programmer,  so PHP or Java isn't really a solution.   Powershell would be tolerable.

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Marketo Employee

Re: Alternative to expiring tokens for a routine process

Powershell can help you here.  A naive implementation to get a token would look like this.  This assumes you're only using the token for a single, very infrequent(>1 hour) call:

$url = '<Identity Service URL>/oauth/token?grant_type=client_credentials&client_id=<Custom Service Client Id>&client_secret=<Custom Service Client Secret>' 
$access_token = (irm $url).access_token

View solution in original post

3 REPLIES 3
Highlighted
Marketo Employee

Re: Alternative to expiring tokens for a routine process

Powershell can help you here.  A naive implementation to get a token would look like this.  This assumes you're only using the token for a single, very infrequent(>1 hour) call:

$url = '<Identity Service URL>/oauth/token?grant_type=client_credentials&client_id=<Custom Service Client Id>&client_secret=<Custom Service Client Secret>' 
$access_token = (irm $url).access_token

View solution in original post

Highlighted
Level 10 - Community Moderator

Re: Alternative to expiring tokens for a routine process

Alex, for those working exclusively from the command line, an invaluable tool is jq.  It's a command-line JSON parser, a function that (due to the nature of time and space) isn't supported in Windows batch files.  Parsing JSON responses from cURL is key to safely creating cURL-based REST connections that use use a separate auth/token step.

With cURL and jq, you can build a simple batch file that:

  1. Runs cURL to the REST authentication endpoint and saves the JSON response
  2. Runs jq to read the access_token and set it to a variable
  3. Runs cURL again to the REST getLead (etc.) endpoint using the access_token variable
Highlighted
Anonymous
Not applicable

Re: Alternative to expiring tokens for a routine process

Powershell 3 (has to be 3 or greater) solution to get a token.

$hostw ="marketo rest url"  # example:  "ABC-DEF-123.mktorest.com"

$file = "filepath.ext"

$format = "csv"

# client_secret is the encryption key in marketo.   

$url = "$hostw/identity/oauth/token?grant_type=client_credentials&client_id=<clientid>&client_secret=<secret>"

#if you need a proxy.....

$proxyUri = [Uri]$null

$proxy = [System.Net.WebRequest]::GetSystemWebProxy()

if ($proxy)

{

    $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials

    $proxyUri = $proxy.GetProxy("$url")

}

$data = Invoke-RestMethod $url -Proxy $proxyUri -ProxyUseDefaultCredentials

$token = $data.access_token