Weble / ZohoBooksApi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weble\ZohoClient\Exception\GrantCodeNotSetException

ibmgeniuz opened this issue · comments

Hello @Skullbock Thanks for the package. I have a question here. I have set up the refresh token, etc. But then When I make a request, I get this.

Weble\ZohoClient\Exception\GrantCodeNotSetException:  in file /Path/to/application/vendor/weble/zohoclient/src/OAuthClient.php on line 307

#0 /Path/to/application/vendor/weble/zohoclient/src/OAuthClient.php(164): Weble\ZohoClient\OAuthClient->generateTokens()
#1 /Path/to/application/vendor/webleit/zohobooksapi/src/Client.php(210): Weble\ZohoClient\OAuthClient->getAccessToken()
#2 /Path/to/application/vendor/webleit/zohobooksapi/src/Client.php(184): Webleit\ZohoBooksApi\Client->getHttpClientOptions(Array, Array)
#3 /Path/to/application/vendor/webleit/zohobooksapi/src/Client.php(122): Webleit\ZohoBooksApi\Client->call('invoices', 'get', Array, Array)
#4 /Path/to/application/vendor/webleit/zohobooksapi/src/Modules/Module.php(47): Webleit\ZohoBooksApi\Client->getList('invoices', Array)
#5 /Path/to/application/Modules/Zoho/ZohoBooks/ZohoBooks.php(37): Webleit\ZohoBooksApi\Modules\Module->getList()
#6 /Path/to/application/Modules/Zoho/Routes/web.php(77): Modules\Zoho\ZohoBooks\ZohoBooks->getInvoices()
#7 /Path/to/application/vendor/laravel/framework/src/Illuminate/Routing/Route.php(230): Illuminate\Routing\RouteFileRegistrar->

I checked the file Weble\ZohoClient\Exception\GrantCodeNotSetException.php and saw it was empty so there's no extra information to debug the code. What do you thing it is and how do I fix this?
Thank you

Hi @ibmgeniuz thanks for the kind words.

Did you by any chance set offlineMode in the client? It's the standard required version for server to server communication.
From the error you're getting, it seems you're using the online mode, that's used with the on-browser with user interaction mode.

More here: https://github.com/Weble/ZohoClient#example-usage-offline-mode

Cheers!

Hello @Skullbock , thank you for the response. I'm trying to set offlineMode, I will write in few mins for you to know how it goes. However, setting offline mode by the link you send makes my IDE show an error for this $zohoBooks = new \Webleit\ZohoBooksApi\ZohoBooks($client);

Expected parameter of type '\Webleit\ZohoBooksApi\Client', '\Weble\ZohoClient\OAuthClient' provided 

I have changed my client to suit the requirement.
However, I think maybe the documentation could be adjusted to take both scenarios (online/offline) mode into consideration. What do you think?

@Skullbock , thank you. It works perfectly now. I made a hybrid of what was in the docs and the link you sent and got everything working perfectly. Thank you so much. This package is so amazing. In case anyone gets such an issue, I'm posting an example of my code below:

public function __construct()
    {

        $oAuthClient = new OAuthClient(config('zoho.books.client_id'), config('zoho.client_secret'));
        $oAuthClient->setRefreshToken(config('zoho.books.refresh_token'));
        $oAuthClient->setRegion(Region::us());
        $oAuthClient->offlineMode();
//        $client->useCache($yourPSR6CachePool);

//        Done!
        $this->accessToken = $oAuthClient->getAccessToken();

//        Check if it's expired
        $this->isExpired = $oAuthClient->accessTokenExpired();

        // setup the zoho books client
        $client = new Client($oAuthClient);
        $client->setOrganizationId(config('zoho.books.organization_id'));

//        Create the main class
        $this->zohoBooks = new \Webleit\ZohoBooksApi\ZohoBooks($client);
    }

Thanks for the comments!

Can you please send a PR to the README so we can improve the docs on this?
You can also check our zoho crm package that should have the same examples, and also our zoho client one where you got the code from

Thanks again!

@Skullbock, definitely. I can do that. You are welcome :) . I will check the other packages too. I think combining both will be the best bridge between CRM and Books.

Thanks for the great job. I will be glad to contribute anytime I find anything because I work with Zoho actively in my daily work.

Thanks, that would be great since we use zoho books less frequently recently due to changes to the fiscal laws here in italy :)