Authenticating a request to a private application for the Xero API using PHP/Guzzle
<p>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.</p>

<p>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.</p>

<p>I am using Guzzle and the Guzzle Oauth subscriber but am struggling to send a properly authenticated request.</p>

<p>Given my Xero app is private the following paragraph should apply to my request (as mentioned in the Xero dev area):</p>

<blockquote>
  <p>Note, For Private applications, the consumer token and secret are also used as the access token and secret.</p>
</blockquote>

<p>So I build up the request like so:</p>

<pre><code>$stack = HandlerStack::create();

$middleware = new Oauth1([
    'consumer_key'    =&gt; config('services.xero.key'),
    'consumer_secret' =&gt; config('services.xero.secret'),
    'signature_method' =&gt; Oauth1::SIGNATURE_METHOD_RSA,
]);

$stack-&gt;push($middleware);

$client = new Client([
    'base_uri' =&gt; 'https://api.xero.com/api.xro/2.0/',
    'handler'  =&gt; $stack,
]);

$res = $client-&gt;request('GET', 'Contacts');

dd($res);
</code></pre>

<p>However I get the following exception thrown:</p>

<blockquote>
  <p>[GuzzleHttp\Exception\ClientException]<br>
  Client error: <code>GET https://api.xero.com/api.xro/2.0/Contacts</code> resulted
  in a <code>401 Unauthorized</code> response:<br>
  oauth_problem=consumer_key_unknown&amp;oauth_problem_advice=Consumer%20key%20was%20not%20recognised</p>
</blockquote>

<p>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.</p>

<p>Any advice on how to make a proper request?</p>