intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
238 stars 240 forks source link

Getting null back when querying customers #246

Closed Boggimedes closed 4 years ago

Boggimedes commented 4 years ago

I am just trying to get a list of customer: "select * from Customer". I feel like I must be missing something obvious. I know the tokens are correct because I am able to successfully refresh my access token. Here is the response log:

RESPONSE URI FOR SEQUENCE ID 00037

==================================

https://sandbox-quickbooks.api.intuit.com/v3/company//query?minorversion=36

RESPONSE HEADERS

================

date: Sun, 18 Aug 2019 21:19:49 GMT

content-type: application/xml

content-length: 462

connection: close

server: nginx

strict-transport-security: max-age=15552000

intuit_tid: 95d4a457-4e21-470c-90fb-d3c9d2fd789f

set-cookie: qboeuid=346e9aaf.5906ac88b4167; path=/; expires=Mon, 17-Aug-20 21:19:49 GMT; domain=.intuit.com

x-xss-protection: 1; mode=block

RESPONSE BODY

=============

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

http://schema.intuit.com/finance/v3" time="2019-08-18T14:19:49.204-07:00">

Unsupported Operation Operation Could not find resource for relative : /v3/company/query of full path: https://c50.sandbox.qbo.intuit.com/qbo50/v3/company/query?minorversion=36 is not supported.
Boggimedes commented 4 years ago

So I read the documentation some more and found last error method which got me a little more information. I'm apparently having auth issues, despite the fact that the auth token is refreshing correctly and successfully. Now I'm getting this error:

QuickBooksOnline\API\Core\HttpClients\FaultHandler Object
    (
        [context:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 
        [httpStatusCode:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 401
        [responseBody:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => <?xml  version="1.0" encoding="UTF-8" standalone="yes"?>
    <IntuitResponse time="2019-08-23T11:58:02.016-07:00"    xmlns="http://schema.intuit.com/finance/v3">
        <Fault type="AUTHENTICATION">
            <Error code="3200">
                <Message>message=AuthenticationFailed; errorCode=003200; statusCode=401</Message>
                <Detail>Malformed bearer token: too short or too long</Detail>
            </Error>
        </Fault>
    </IntuitResponse>

        [helpMsg:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => Invalid auth/bad    request (got a 401, expected HTTP/1.1 20X or a redirect)
        [intuit_tid:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 22341584-f94d-40fa-  ae2c-1b125e18b7c9
        [intuitErrorType:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 
        [intuitErrorCode:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 0
        [intuitErrorElement:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 
        [intuitErrorMessage:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 
        [intuitErrorDetail:QuickBooksOnline\API\Core\HttpClients\FaultHandler:private] => 
    )

Here is the related code:

    $iHelper = new IntuitHelper(env('INTUIT_CLIENT_ID'),env('INTUIT_CLIENT_SECRET'));
    $accessToken = $iHelper->refreshAccessTokenWithRefreshToken($oAuth->refresh_token);
    $error = $iHelper->getLastError();
    if($error){
        \Log::error($error);
        return;
    }

    //Refresh Token is called successfully
    $oAuth->last_refresh_token = $oAuth->refresh_token;
    $oAuth->last_auth_token = $oAuth->auth_token;
    $oAuth->refresh_token = $accessToken->getRefreshToken();
    $oAuth->auth_token = $accessToken->getAccessToken();
    $oAuth->last_success = Carbon::now();
    $oAuth->save();
    $oAuth->refresh();

    // Prep Data Services
    $dataService = Intuit::Configure(array(
        'auth_mode' => 'oauth2',
        'ClientID' => env('INTUIT_CLIENT_ID'),
        'ClientSecret' => env('INTUIT_CLIENT_SECRET'),
        'refreshTokenKey' => $oAuth->refresh_token,
        'accessTokenKey' => $oAuth->auth_token,
        'QBORealmID' => "4620816365009229850",
        'scope' => "com.intuit.quickbooks.accounting",
        'baseUrl' => "development"
    ));
Boggimedes commented 4 years ago

I figured it out. My issue was the database field where I was storing the access token was set to 255 characters. :/