dcblogdev / laravel-xero

Laravel package for working with Xero API
Other
43 stars 26 forks source link

Undefined array key "id_token" #13

Closed emotec closed 2 years ago

emotec commented 2 years ago

When trying to create a new contact I am getting this error. My site connects to Xero correctly and stores the token data in the database. Screenshot from 2022-07-15 11-27-57

emotec commented 2 years ago

the very simple Xero::get('contacts'); also falls over with the same error.

Xero::getTenantName(); works correctly!

dcblogdev commented 2 years ago

Thanks for raising this, I'll look into this and come back to you.

emotec commented 2 years ago

image

getAccessToken() function 'invalid_grant' is returned from Xero ?

is the grant type wrong? 'grant_type' => 'refresh_token',

also this line if ($token->expires <= $now) {

I cant find $token->expires anywhere in the code?

If I take this 'if' statement out of the code then the API call works correctly. So perhaps there is a problem with the token expiry check?

emotec commented 2 years ago

Also I have a very similar website using the same Xero API. This works perfectly. The laravel-xero code is a little earlier though. Before the multitenancy additions.

dcblogdev commented 2 years ago

I've identified the issue I'll push up a fix.

dcblogdev commented 2 years ago

I've released v1.1.0 can you check if this works for you now?

emotec commented 2 years ago

Hi David

I'm now getting this msg image

Also there are now 2 tokens in the database image the first one is missing some data

image

if ($tenantData != null) { $data = array_merge($data, $tenantData); }

Seems to be a repeated if statement here? Is that right?

thx Mark

dcblogdev commented 2 years ago

that's a duplicate line, I'll remove it.

Can you clear out the 2 rows and re-connect

emotec commented 2 years ago

Hi David... that didnt make any difference unfortunately. I deleted the token data from the database and commented out the repeated lines.

Same result... same error and 2 tokens

thx Mark

dcblogdev commented 2 years ago

okay, I'll do further testing after work.

emotec commented 2 years ago

thx David!

emotec commented 2 years ago

Hi David I removed the extra token in the database and chnaged the id of the remaining token from 3 to 1!... Now its working again.

robinhoodxuk commented 2 years ago

Hi,

I am having the same issue, using multi tenant, and after a short time a new record is added to the database with ID of 1, again with missing tenant ID/Name etc.. only the tokens populated.

Assuming it must be being created in storeToken but not sure why it's doing it, if you have any idea's would be appreciated! On first connect to Xero it works perfectly then about 20mins later it creates a second record.

Thanks Robin