简体   繁体   中英

Getting 401 Unauthorized Xero oAuth 2.0 -

I am trying to create a new contact using Xero oAuth 2.0 and getting this error:

[401] Client error: `PUT https://api.xero.com/api.xro/2.0/Contacts?summarizeErrors=true` resulted in a `401 Unauthorized` response: 

I have got my scopes as:

'scopes'   => [
            'openid',
            'email',
            'profile',
            'offline_access',
            'accounting.settings',
            'accounting.contacts',
            'accounting.reports.read',
        ],

I am able to connect to Xero (using this code ) and I get message The App is connected to Xero but when I use the following code:-

public function xeroTest(OauthCredentialManager $xeroCredentials) {

        $apiInstance  = resolve(\XeroAPI\XeroPHP\Api\AccountingApi::class);
        $contact = resolve( \XeroAPI\XeroPHP\Models\Accounting\Contact::class);
        $contact->setName('Abcdef');
        $contact->setContactId('6d42f03b-181f-43e3-93fb-2025c0hjhe92');

        $apiResponse = $apiInstance->createContacts($xeroCredentials->getTenantId() ,$contact,true);
        $message = 'New Contact Name: ' . $apiResponse->getContacts()[0]->getName();

        return $message;
    }

Error: [401] Client error: PUT https://api.xero.com/api.xro/2.0/Contacts?summarizeErrors=true resulted in a 401 Unauthorized response:

I don't see all your code but you likely just have to set the valid access_token on the PHP client.

https://github.com/XeroAPI/xero-php-oauth2#callbackphp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM