I'm trying to integrate my Company's online store (written in php/Laravel) with Xero such that I can create an invoice for each order. For this I have created a Private Xero application, generated the certificate necessary for Oauth authentication and added it to the Xero App such that I now have my consumer key and secret.
I had a look at the official php wrapper and have found it to be very outdated and unsuitable for integration into my app so, given the amount of Xero interaction is small I thought I'd try and call the API directly.
I am using Guzzle and the Guzzle Oauth subscriber but am struggling to send a properly authenticated request.
Given my Xero app is private the following paragraph should apply to my request (as mentioned in the Xero dev area):
Note, For Private applications, the consumer token and secret are also used as the access token and secret.
So I build up the request like so:
$stack = HandlerStack::create();
$middleware = new Oauth1([
'consumer_key' => config('services.xero.key'),
'consumer_secret' => config('services.xero.secret'),
'signature_method' => Oauth1::SIGNATURE_METHOD_RSA,
]);
$stack->push($middleware);
$client = new Client([
'base_uri' => 'https://api.xero.com/api.xro/2.0/',
'handler' => $stack,
]);
$res = $client->request('GET', 'Contacts');
dd($res);
However I get the following exception thrown:
[GuzzleHttp\Exception\ClientException]
Client error:GET https://api.xero.com/api.xro/2.0/Contacts
resulted in a401 Unauthorized
response:
oauth_problem=consumer_key_unknown&oauth_problem_advice=Consumer%20key%20was%20not%20recognised
As far as I can tell I have properly set up the Xero app and generated the consumer key and secret but I can't seem to debug this.
Any advice on how to make a proper request?