Search code examples
phpapiobjectinfusionsoft

I have an object, but error says I'm making a function call on a non-object


I'm working with the Infusionsoft SDK. I've reached a roadblock in trying to make some API calls.

Any call that I make ends up with the same Call to a member function getRefreshToken() on a non-object error (not always getRefreshToken() though).

When I var_dump, I see that it is an object.. So, what gives?

object(Infusionsoft\Infusionsoft)#182 (13) { ["url":protected]=> string(42) "https://api.infusionsoft.com/crm/xmlrpc/v1" ["auth":protected]=> string(51) "https://signin.infusionsoft.com/app/oauth/authorize" ["tokenUri":protected]=> string(34) "https://api.infusionsoft.com/token" ["clientId":protected]=> string(24) "actual client ID" ["clientSecret":protected]=> string(10) "actual secret key" ["redirectUri":protected]=> string(65) "http://benjamin_redden.dev/wp-content/plugins/ajaxIsForm/auth.php" ["apis":protected]=> array(0) { } ["debug":protected]=> bool(false) ["httpClient":protected]=> NULL ["httpLogAdapter":protected]=> NULL ["serializer":protected]=> NULL ["needsEmptyKey"]=> bool(true) ["token":protected]=> string(24) "actual token" } Fatal error: Call to a member function getRefreshToken() on a non-object in /Users/Krsna/Sites/benjamin_redden/wp-content/plugins/ajaxIsForm/vendor/infusionsoft/php-sdk/src/Infusionsoft/Infusionsoft.php on line 261

that is the error that I get from running a call like...

var_dump($infusionsoft); $infusionsoft->refreshAccessToken();

or

function get_those_ids($infusionsoft){
  var_dump($infusionsoft);
  // get the form IDS
  $formIDS = $infusionsoft->webForms()->getMap();

  // make the dropdown
  echo '<select name="infusionsoft_forms_which_form_would_you_like_to_use_" id="infusionsoft_forms_which_form_would_you_like_to_use_">';
  foreach($formIDS as $formID => $formName){
    echo '<option value="'. $formID .'">'. $formName .'</option>';
  }
  echo '</select>';
}

Solution

  • Figured it out!

    I was setting the token as the actual string that contains the token, but apparently it would rather have the entire object token (containing the refresh token, redirect uri, end of life, and everything)

    So, it ended up being something like $infusionsoft->setToken($unserializedToken);

    instead of something like $infusionsoft->setToken($tokenString);

    Which worked great, until I tried saving some information to a custom post type in WP, and now all I get is Guzzle errors... =(