3 Replies Latest reply on Oct 1, 2015 7:48 AM by bb695b98d6ca97757add46dcb5e5929b043b2ab3

    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!

        • Re: Alternative to expiring tokens for a routine process
          Kenny Elkington

          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
          • Re: Alternative to expiring tokens for a routine process
            Sanford Whiteman

            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
            • 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