Weble / ZohoBooksApi

40 stars 39 forks source link

Unable to update or create 'ChartOfAccount' using API. #103

Closed kmott closed 9 months ago

kmott commented 1 year ago

Summary

Hello, I am using a recent version of the ZohoBooksApi (thank you by the way--I really enjoy using it!), and I noticed a peculiar issue when I go to create or update a ChartOfAccount entry.

My best guess is that the returned data from the Zoho API does not have a JSON payload with chartofaccount anywhere in it, so ZohoBooksApi is unable to parse the response and return it to the caller?

Example

// Initialize zohoBooks API as you normally would with your credentials, etc.

// Now, try to create a `chartOfAccounts` entry:
                $this->zohoBooks->chartofaccounts->create([
                    'account_name' => 'test123',
                    'account_code' => 'TEST_123_CODE',
                    'account_type' => 'income',
                    'description' => 'My test123 description',
                    'parent_account_id' => '< some existing parent account_id value >',
                ]);

// Or, try to update an existing `chartOfAccounts` entry:
                $this->zohoBooks->chartofaccounts->update('< my existing chart of account account_id value >', [
                    'account_name' => 'test123',
                    'account_code' => 'TEST_123_CODE',
                    'account_type' => 'income',
                    'description' => 'My test123 description',
                    'parent_account_id' => '< some existing parent account_id value >',
                ]);

Error

This is the exception I am getting when I run the above code:

2023-06-17 21:25:46 [172.21.0.1][2][-][error][yii\base\ErrorException:2] yii\base\ErrorException: Undefined array key "chartofaccount" in /src/vendor/webleit/zohobooksapi/src/Modules/Module.php:115
Stack trace:
#0 /src/vendor/webleit/zohobooksapi/src/Modules/Module.php(115): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/src/vendor/web...', 115)
#1 /src/common/traits/ZohoBooksTrait.php(215): Webleit\ZohoBooksApi\Modules\Module->update('417511700000007...', Array)
#2 /src/frontend/controllers/ClientController.php(639): frontend\controllers\ClientController->zohoBooksUpsertQueues(Array)
#3 [internal function]: frontend\controllers\ClientController->actionEmailInvoice('186', '11763', 'client')
#4 /src/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /src/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#6 /src/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('email-invoice', Array)
#7 /src/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('client/email-in...', Array)
#8 /src/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest(Object(yii\web\Request))
#9 /src/frontend/web/index.php(17): yii\base\Application->run()
#10 {main}

Note: I forgot to mention that the create or update is processed successfully by the Zoho API (e.g., my data is updated or created), but it just throws the error above when trying to parse the response from Zoho API.

Skullbock commented 1 year ago

Hi! thanks for the report. Are you able to send a PR for a fix? Should be pretty straightfoward. The problem is the "key" set in the module related to the chart of accounts, where it's probably set as singular instead of plural. You can check other modules where we've similar fixes in places.

I'm away from the computer in these days so i can't take a quick fix at this at the moment

Thanks!

midweste commented 9 months ago

Hi! thanks for the report. Are you able to send a PR for a fix? Should be pretty straightfoward. The problem is the "key" set in the module related to the chart of accounts, where it's probably set as singular instead of plural. You can check other modules where we've similar fixes in places.

I'm away from the computer in these days so i can't take a quick fix at this at the moment

Thanks!

I used chartofaccounts without issue over the last few days, so this must have been fixed

Skullbock commented 9 months ago

Great! Will cose this then!