Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to retrieve contacts #45

Open
Duncan-dev1 opened this issue May 5, 2021 · 13 comments
Open

Error when trying to retrieve contacts #45

Duncan-dev1 opened this issue May 5, 2021 · 13 comments

Comments

@Duncan-dev1
Copy link

Duncan-dev1 commented May 5, 2021

Hello,i am new to Xero and i am trying to get my head around how to go about things,i am asking this here because i have exhausted my options .So i did everything well since i can get my app to request and get access tokens and tenant ID and choose an app from xero,thanks to a flawless documentation.When i got to the usage section,i created a route ;'about' just to test things and pasted this to its controller
`public function about()
{
$user = auth()->user();

$xero = new XeroApp(
new AccessToken(json_decode($user->xero_oauth_2_access_token)),
$user->xero_tenant_id
);
$contacts = $xero->contacts()->get();
dd($contacts);
}`
trying to access the about page,i get this error: Argument 1 passed to League\OAuth2\Client\Token\AccessToken::__construct() must be of the type array, null given, called in C:\xampp\htdocs\foodiez\app\Http\Controllers\HomeController.php on line 88
what could i be doing wrong.
Also to anyone who will respond to this,how do we add a contact to xero with the syntax offered by this package

@abhimanusharma
Copy link

I am also facing error while getting a single contact.

I have scopes accounting.transactions accounting.contacts added in my request.

My $this->xero is returning the xero object successfully.
but code
$contact = $this->xero->contacts()->find($xero_auth->contact_id);

is returning error.

XeroPHP\Remote\Exception\ForbiddenException: You are not permitted to access this resource in /var/www/html/project_dev/vendor/calcinai/xero-php/src/XeroPHP/Remote/Response.php:127
Stack trace:
#0 /var/www/html/project_dev/vendor/calcinai/xero-php/src/XeroPHP/Remote/Request.php(119): XeroPHP\Remote\Response->parse()
#1 /var/www/html/project_dev/vendor/calcinai/xero-php/src/XeroPHP/Application.php(200): XeroPHP\Remote\Request->send()
#2 /var/www/html/project_dev/vendor/langleyfoxall/xero-laravel/src/Wrappers/QueryWrapper.php(102): XeroPHP\Application->loadByGUID('\\XeroPHP\\Models...', 'xxxxxxxx-xxxx-x...')

@seanmccabe
Copy link

$contact = $this->xero->contacts()->find($xero_auth->contact_id);

Is never going to work.
You are asking $xero_auth to provide the contact id, which it doesn't have as you are asking it to find one.
Need to change the text inside find to a valid Xero contact UUID the organisation has access too.

@seanmccabe
Copy link

Hello,i am new to Xero and i am trying to get my head around how to go about things,i am asking this here because i have exhausted my options .So i did everything well since i can get my app to request and get access tokens and tenant ID and choose an app from xero,thanks to a flawless documentation.When i got to the usage section,i created a route ;'about' just to test things and pasted this to its controller
`public function about()
{
$user = auth()->user();

$xero = new XeroApp(
new AccessToken(json_decode($user->xero_oauth_2_access_token)),
$user->xero_tenant_id
);
$contacts = $xero->contacts()->get();
dd($contacts);
}`
trying to access the about page,i get this error: Argument 1 passed to League\OAuth2\Client\Token\AccessToken::__construct() must be of the type array, null given, called in C:\xampp\htdocs\foodiez\app\Http\Controllers\HomeController.php on line 88
what could i be doing wrong.
Also to anyone who will respond to this,how do we add a contact to xero with the syntax offered by this package

Issue here is refreshing the token, start on that first.
Then the second issue is the code you are using is for getting a contact, not adding one.

@Duncan-dev1
Copy link
Author

Hello,i am new to Xero and i am trying to get my head around how to go about things,i am asking this here because i have exhausted my options .So i did everything well since i can get my app to request and get access tokens and tenant ID and choose an app from xero,thanks to a flawless documentation.When i got to the usage section,i created a route ;'about' just to test things and pasted this to its controller
public function about() { $user = auth()->user(); $xero = new XeroApp( new AccessToken(json_decode($user->xero_oauth_2_access_token)), $user->xero_tenant_id ); $contacts = $xero->contacts()->get(); dd($contacts); }
trying to access the about page,i get this error: Argument 1 passed to League\OAuth2\Client\Token\AccessToken::__construct() must be of the type array, null given, called in C:\xampp\htdocs\foodiez\app\Http\Controllers\HomeController.php on line 88
what could i be doing wrong.
Also to anyone who will respond to this,how do we add a contact to xero with the syntax offered by this package

Issue here is refreshing the token, start on that first.
Then the second issue is the code you are using is for getting a contact, not adding one.

Thank you,but how does a refresh code look like on the default,because i havent done anything myself,just the configuration as per the guidelines.I got the error while trying to get contacts.Sorry to bother you

@seanmccabe
Copy link

seanmccabe commented May 5, 2021

Its literaaly on the front page as a function in the code block where you got the first part.
here

The token lasts 30 minutes, so you need to ensure you are refreshing the token to maintain access.

@Duncan-dev1
Copy link
Author

Duncan-dev1 commented May 5, 2021 via email

@seanmccabe
Copy link

Yes you need to call that function, safest is to call it before every Xero connection so ensure you have an active token.

No it doesn't.
It just gives you an easy way to handle that stuff, rather than re-inventing the wheel everytime. You need to sort the storing of the token and tenant id etc. (i.e. in a database or something) to call later.

All the code you need is on the frontpage, and it assumes you have a basic knowledge of laravel and PHP to then know how to store the data you've gotten.

@Duncan-dev1
Copy link
Author

Duncan-dev1 commented May 5, 2021 via email

@abhimanusharma
Copy link

@seanmccabe My system has the correct contact id in $xero_auth as it is object of my db modal getting contact id from database.

@seanmccabe
Copy link

@seanmccabe My system has the correct contact id in $xero_auth as it is object of my db modal getting contact id from database.

The error says you dont have permission to access that resource. So are you sure that contact uuid is within the tenant you have authorised and are passing through?

@abhimanusharma
Copy link

@seanmccabe My system has the correct contact id in $xero_auth as it is object of my db modal getting contact id from database.

The error says you dont have permission to access that resource. So are you sure that contact uuid is within the tenant you have authorised and are passing through?

Yes I have added that contact using that tanant and with package only but when I am trying to access that contact to add the invoice it is giving me the error I mentioned above.

@Duncan-dev1
Copy link
Author

I am also facing error while getting a single contact.

I have scopes accounting.transactions accounting.contacts added in my request.

My $this->xero is returning the xero object successfully.
but code
$contact = $this->xero->contacts()->find($xero_auth->contact_id);

is returning error.

XeroPHP\Remote\Exception\ForbiddenException: You are not permitted to access this resource in /var/www/html/project_dev/vendor/calcinai/xero-php/src/XeroPHP/Remote/Response.php:127
Stack trace:
#0 /var/www/html/project_dev/vendor/calcinai/xero-php/src/XeroPHP/Remote/Request.php(119): XeroPHP\Remote\Response->parse()
#1 /var/www/html/project_dev/vendor/calcinai/xero-php/src/XeroPHP/Application.php(200): XeroPHP\Remote\Request->send()
#2 /var/www/html/project_dev/vendor/langleyfoxall/xero-laravel/src/Wrappers/QueryWrapper.php(102): XeroPHP\Application->loadByGUID('\\XeroPHP\\Models...', 'xxxxxxxx-xxxx-x...')

Did you manage to solve your errors?can i email you to help me a little?

@seanmccabe
Copy link

The errors aren't code related, you are trying to access a resource you don't have permission to view.
It is connecting to Xero, or you wouldnt get that error.

So either:

  1. You have the wrong tenant or contact ID
  2. You are not passing the tenance or contact ID correctly

This may be of help:
calcinai/xero-php#753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants