1

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:

Kunal Parekh
  • 380
  • 6
  • 24

1 Answers1

0

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

SerKnight
  • 2,502
  • 1
  • 16
  • 18
  • I have updated my question and added the complete function. How do I add a callback using a laravel framework. can u please point me to the right direction. Thanks – Kunal Parekh Oct 01 '20 at 00:16
  • Hi @user10345537 - i think your best bet is to file an issue with that repo you are using. You need to set the access token on the client somehow but I am not familiar with that code. – SerKnight Oct 01 '20 at 21:44