2

I want to build a Salesforce Marketing Cloud HubExchange app. The app will schedule a task periodically to process recent event tracking data for each user in the installed base.

How do I access event data for a specific user? What tokens or FuelSDK::Client parameters (I am using the Ruby FuelSDK, ideally) do I need to set?

I think I need to refresh the token from the JWT, but the FuelSDK::Client seems to want a JWT, not an oauth token.

Is there a code example or description for this process?

Relevant links:

2

My current solution is painful and complex, but I have nothing better. Not sure why this isn't well-trod ground, but... here goes.

  • Build a database table to user store token data.

  • Use my fork of FuekSDK-Ruby that supports a callback when the client chooses to refresh the token, and another when the refresh fails.

  • Initialize the database data from data in the JWT passed by the user.

  • Create the FuelSDK client with callback (and cache it, so you don't keep remaking them) and make it retry a few times if it ever has problems because someone else refreshed first.

See the attached gist for an implementation: https://gist.github.com/ses4j/6b38cd7bb391e8f41912

1

The Fuel Ruby SDK will create a client using:

myClient = FuelSDK::Client.new {'client' => { 'id' => CLIENTID, 'secret' => SECRET }}

The jwt is optional if you have it, for distributed apps - you would need to store the access token, and the refresh token in a data store to allow your app to grab the data it needs without a user login required during the update.

  • So, can/should I store the whole JWT in a database field so I can use it later? Are there pieces of it I should store, or need to refresh before storing? – Scott Stafford May 12 '15 at 13:48
  • You could store the entire jwt, or the current access token and refresh token. Refresh tokens don't expire so if access token is expired just refresh. – Kelly J Andrews May 12 '15 at 13:50
  • The API I need (get/set subscriber info) seems to use the legacyOauthtoken rather than the "main" access token. Does that also need refresh? Or can I just store that token indefinitely, and stuff it onto the myClient like myClient.internal_token = exacttarget_internal_oauth_token? – Scott Stafford May 12 '15 at 13:52
  • kellyjandrews.com/2014/02/20/… will help you use the access token, and not the legacy token. – Kelly J Andrews May 12 '15 at 13:55
  • Updated my answer to account for my misreading your question. – Kelly J Andrews May 12 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.