HubSpot / hubspot-api-php

HubSpot API PHP Client Libraries for V3 version of the API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authentication error on getById() call after Factory::createWithAccessToken() execution

yoshidasendai115 opened this issue · comments

I found a bug-like section.

$client = Factory::createWithAccessToken(env("HUBSPOT_PRIVATE_APP_TOKEN_IMPORT"));
$resJobCreate = $client->crm()->imports()->coreApi()->create($csvFileObj, json_encode($import_request));
...
$client->crm()->imports()->coreApi()->getById($resJobCreate->getId());

Authentication error occurs in getById().
I have checked the SDK code.

getById() -> getByIdWithHttpInfo() -> getByIdRequest()

Within getByIdRequest()

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('hapikey');
        if ($apiKey ! == null) {
            $queryParams['hapikey'] = $apiKey;
        }

The above code retrieves the API key, but does not seem to handle the case where an access token is set.

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('hapikey');
        if ($apiKey ! == null) {
            $queryParams['hapikey'] = $apiKey;
        }
        // this endpoint requires OAuth (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

I modified the SDK as above and it authenticated.

composer.json

"hubspot/api-client":"^8.3"

Please confirm.

commented

Hi @yoshidasendai115 .
Private app access token was add to crm()->imports()->coreApi()->getById() only in 9.0.0 version of the SDK.

@ksvirkou-hubspot
I see.
So you use the SDK for 9.x or later?
Thank you very much.

commented

I maintain the SDK.