I’m doing some development work in a staging version of my company’s website. I believe we’re using the Infusionsoft PHP SDK to connect, although I remain unsure of a lot of things (I didn’t write this code & I’m kind of feeling my way along). I’ve had some trouble with Keap authentication, but at the moment it seems to be working, or at least it isn’t throwing any code errors. However, when I attempt to authenticate to Keap like so:
public function request()
{
// 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->authenticationType === AuthenticationType::OAuth2AccessToken && $this->isTokenExpired()) {
throw new TokenExpiredException;
}
$params = func_get_args();
$method = array_shift($params);
// Some older methods in the API require a key parameter to be sent
// even if OAuth is being used. This flag can be made false as it
// will break some newer endpoints.
if ($this->needsEmptyKey) {
$params = array_merge(array('key' => 'backwards-compatability'), $params);
}
// Reset the empty key flag back to the default for the next request
$this->needsEmptyKey = true;
$options = $this->setOptionsForRequest([]);
$client = $this->getSerializer();
return $client->request($method, $this->getUrl(), $params, $this->getHttpClient($options));
}
The constructor in my version of the Infusionsoft class is simpler than the one at your link: mine is missing lines 108-120.
The request() function you post looks similar to the one my site has in file _scripts\vendor\infusionsoft\php-sdk\src\Infusionsoft\Infusionsoft.php. However, there are some differences. This is the source code my site is using:
public function request()
{
// 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;
}
$url = $this->url . '?' . http_build_query(array('access_token' => $token->getAccessToken()));
$params = func_get_args();
$method = array_shift($params);
// Some older methods in the API require a key parameter to be sent
// even if OAuth is being used. This flag can be made false as it
// will break some newer endpoints.
if ($this->needsEmptyKey) {
$params = array_merge(array('key' => $token->getAccessToken()), $params);
}
// Reset the empty key flag back to the default for the next request
$this->needsEmptyKey = true;
$client = $this->getSerializer();
$response = $client->request($method, $url, $params, $this->getHttpClient());
return $response;
}
This looks like an older version of the code you posted. I don’t think this was modified on my end - the developer who wrote this app added his functionality by adding Wordpress hooks and actions. I think it’s just old code. We’re very reluctant to do any upgrades because of the risk of blowing up some piece of our custom-written code. Unfortunately, I don’t have the option of including any kind of user controls: this particular code runs from a number of places and does a couple of things based on whether the current customer has certain Keap tags. So it needs to be invisible to the user (customer). My problem right now is that this needsEmptyKey error is blocking me from querying Keap to see if the customer has those tags.
I’ve figured this out. Sort of. I’ve been getting this error while testing some changes in the staging copy of the company website. Staging and production are essentially identical at this time. I tried checking on another and very similar function that I know is working in production, which contains the same code for retrieving tags from Keap. The similar function works in production but fails in the staging copy, in exactly the same way: queries for a contact’s tags return an object with only the “NeedsEmptyKey” property set. I have no idea why this problem would only show up in the staging version, but it seems that’s what is happening.
Still, thank you for your help; I’ve learned a few things as a result of this thread.
I took a look to see if anyone else had the same issue with the “needsEmptyKey”, but I am only seeing debug entries for it. It is particular to the SDK.
As @Marion_Dorsett2 pointed out, there is a new SDK that has come into operation. You could migrate to that if you want to play it safe.