Invalid access token oauth

I am using the php library to make the calls.
the oauth call is successful and correct, but when I try to make a call with the library it returns Invalid access token

example php:
$data = $account_infusionsoft->restfulRequest(“get”,‘https://api.infusionsoft.com/crm/rest/v1/contacts’,$query);

error:

[message:protected] => Client error: GET https://api.infusionsoft.com/crm/rest/v1/contacts?access_token=xxxxxxxxxxxxxxxxxx&email=xxxxxxx%40m3rgroup.com resulted in a 401 Unauthorized response:
{“fault”:{“faultstring”:“Invalid access token”,“detail”:{“errorcode”:“oauth.v2.InvalidAccessToken”}}}

the error appeared since 14/02 even if I’m using oauth as library, what has been changed that there are no changes for oauth?

Hi @Massimo_Romanello,

The only changes recently announced was that the Legacy API Key was finally deprecated on February 14th.

What I noticed in the REST API Request is that the Access Token is being passed as an URL Parameter for the Endpoint. That has been discouraged, and possible that it may have been removed on the same date as well.

You need to pass the Access Token in the HTTP Header for the request.

Authorization: Bearer <ACCESS TOKEN>

https://developer.infusionsoft.com/getting-started-oauth-keys/

Have you updated the library to the newer version?

I presume your Access Token renewal is working all okay?

Hope that helps.

the problem with updating the library is that it is only compatible with PHP 8.1+. is it possible to still use the 1.5.4 library and pass the token through the header? I don’t think everyone is ready to switch to php 8.1, also because guzzle 7 is trivially compatible from 7.2+, so it would be useful to have a library that is still compatible with php7

I made a change to the existing library 1.5.4, maybe it is useful to others and fixes the problem completely while continuing to use php 7.2+.
just change the function “public function restfulRequest” in the Infusionsoft.php file

path : infusionsoft-php/vendor/infusionsoft/php-sdk/src/Infusionsoft/Infusionsoft.php

public function restfulRequest($method, $url, $params = array())
    {
        // Before making the request, we can make sure that the token is still
        // valid by doing a check on the end of life.
        $token = $this->getToken();
        if ($this->isTokenExpired()) {
            throw new TokenExpiredException;
        }

        $client      = $this->getHttpClient();
        $full_params = [];

        if (strtolower($method) === 'get' || strtolower($method) === 'delete') {
           // $params = array_merge(array('access_token' => $token->getAccessToken()), $params);
            $url    = $url . '?' . http_build_query($params);
        } else {
           // $url                 = $url . '?' . http_build_query(array('access_token' => $token->getAccessToken()));
            $full_params['body'] = json_encode($params);
        }

        $full_params['headers'] = array(
            'Content-Type' => 'application/json',
			'Authorization'=> 'Bearer '.$token->getAccessToken(),
        );

        $response = (string)$client->request($method, $url, $full_params);

        return json_decode($response, true);
    }
1 Like

Thank you supplying a fix to the PHP SDK, that will help out other developers that use older versions of PHP


I do not use Keap SDK due to several reasons. When it came out years ago to replace the original iSDK, I noticed it was bloated and relied on several third party dependencies. Unfortunately, the reliance on those third party dependencies is what causes the progression issues with the SDK.

It says it supports versions above PHP v8.1, that is incorrect as well. Someone else tried to go above v8.1, but ran into problems. It may not fully support v8.2, v8.3, or v8.4, unless developers have made tweaks to the SDK? Keap has to wait for the third party developers to update their code to support newer versions of PHP, which could take months or a year(s) before an update is done. But if one of those third party developers stops maintaining their code, then the SDK will get trapped on an older version of PHP.

It would be better off for Keap to produce a SDK with zero third party dependency reliance. The original iSDK only relied on the the PHP XML-RPC Library, which thankfully is still being kept up to date with newer versions of PHP.