How do I find/create my code to exchange for a token?

(Thomas Theimer) #1

I have the example addWithDupCheck.php running but each time it requires that I log into my Infu account and allow it to authorize. I want my production server to routinely exchange data with my Infu CRM via the API. Where to I find or create the code so that this can run without manual intervention?

(John Borelli) #2

The only way to do this at present is to store your access and refresh tokens and then run a service that, before the 24 hour expiration runs out, refreshes and then replaces the old tokens with the new ones.

(Thomas Theimer) #3

Thanks John. But I am left with two quesitons

  1. Is there a feature (i.e. a menu option) that will give me the serialized token or do I need to programmatically capture it?
  2. Assuming I have to capture the token using a script, how do I create/expose the refresh token? I see in the sample code that there is a method to refresh (refreshAccessToken()). Do you know of any samples or docs that show how to expose and use a refresh token?
    Thanks again.

(John Borelli) #4

the refresh token is sent with the access token. The returned json string looks similar to this:


(These tokens have long since expired)

It’s a 3 legged process no matter how you slice it so there is no set it and forget it option in IS directly. It has to be managed with code and in that way SSO can be simulated.

(Thomas Theimer) #5

John - When I view my serialized token I see a structure like your example. Do I need to somehow extract the refresh token to use it or can I store the whole serialized token and run the following two functions every 21 hours or so? (after creating the $infusionsoft instance)

(John Borelli) #6

That would be dealer’s choice. The important part is that you store it and then handle it in whatever way you see fit. I convert json to an object and then write the properties to a db table myself, but you can easily just store the json string and then pull the information from it on the back side too. The only thing I would add is that it would be much more straight forward to deal with the time to live value if you convert it and then write to fields rather than doing all that every time you check if it’s time to refresh.