1

I need to access infusionsoft api without user interaction. I do not want let user to click on a click so I can get a tocken. Is it possible?

$infusionsoft = new Infusionsoft\Infusionsoft(array(
    'clientId'     => '...',
    'clientSecret' => '...',
    'redirectUri'  => '...',
));

// If the serialized token is available in the session storage, we tell the SDK
// to use that token for subsequent requests.
if (isset($_SESSION['token'])) {
    $infusionsoft->setToken(unserialize($_SESSION['token']));
}

// If we are returning from Infusionsoft we need to exchange the code for an
// access token.
if (isset($_GET['code']) and !$infusionsoft->getToken()) {
    $infusionsoft->requestAccessToken($_GET['code']);
}

if ($infusionsoft->getToken()) {
    // Save the serialized token to the current session for subsequent requests
    $_SESSION['token'] = serialize($infusionsoft->getToken());

    // MAKE INFUSIONSOFT REQUEST
} else {
    echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>';
}
user3351236
  • 2,488
  • 10
  • 29
  • 52

2 Answers2

0

If you're looking to interact with the API and not get access via the newer oAuth methods, you'll need to use the depreciated legacy API which uses an API key from the actual Infusionsoft application. The upside is that unless the user changes their API key, you don't need to "renew" or "refresh" the token and you don't need the user to click through an authorize their app.

The big downside, of course, is that this older API has been depreciated and all new applications need to use oAuth.

What is the use case where you can't walk the users through an oAuth authentication flow?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jeremy
  • 60
  • 5
  • I am in same situation. Our use case is that we need to retrieve our orders so we can manage them through our own centralized admin. – cyberwombat Dec 28 '16 at 19:40
0

Make 3 files

  1. Request_new_token.php. It is similar to your code(Need to run one time only), but you will have to save the token to database or txt file.

    //Convert object to string
    $token = serialize($infusionsoft->requestAccessToken($_GET['code']));
    //Update the token in database.
    $update = new Update("systemsettings");
    $update->addColumn('systemsettings_strvalue', $token);
    $update->run(1);
    exit;    
    
  2. Refresh_token.php. With saved token, you will need to refresh it within 21 hours. I suggest to use cronjob to auto run it on server back-end.

  3. General_request.php(Up to your system preference). Whenever you need to make single request to GET/PUT/POST, you just need to initiate infusionsoft object and set token to the new object from database.

Good luck!

Ming Zhang
  • 11
  • 2