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!
Solved! Go to Solution.
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
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
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:
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