0

I am trying to update the invoice template of an Xero invoice. My issue is that I get a 400 error and a response saying:

NoDataProcessedException No data has been processed for this endpoint. This endpoint is expecting Invoice data to be specifed in the request body

So my authentication works perfectly but its claiming that I have no data in the body of my post request. As you can see in my code below I have specified data in the body of the request. So have I just formatted it wrong or am I doing something else wrong?

$xeroInvoiceId = '7b601c90-642b-4b6c-9a21-3969ff339cb0';

$updateInvoiceArgs = array(
    'headers' => array(
        'xero-tenant-id' => $tenantId,
         'Authorization' => 'Bearer ' . $refreshTokenBody->access_token,
     ),
     'body' => array(
         'InvoiceID' => $xeroInvoiceId,
         'BrandingThemeID' => '5d4dd402-c851-497e-aae1-9ff265c0d15a'
      )
); 

            
$res = wp_remote_post('https://api.xero.com/api.xro/2.0/Invoices/' . $xeroInvoiceId, $updateInvoiceArgs);

var_dump($res);
Reece
  • 2,581
  • 10
  • 42
  • 90
  • 1
    Is there some other code that is formatting the body data in either XML or JSON format? I'm not familiar with Wordpress so I don't know whether that's handled for you. – droopsnoot Dec 23 '20 at 09:00
  • @droopsnoot No there's no formatting done on the body data. The only thing missing from my example code is how I generate the access_token. But this shouldn't interfere with my post – Reece Dec 23 '20 at 10:48
  • 1
    As I understand it (and I may be wrong), any data posted to a Xero endpoint must be in either XML or JSON format, so maybe that's the problem. It says "XML or JSON formatted requests are accepted." in this page, when talking about requests and responses, which suggests that anything else is not: https://developer.xero.com/documentation/api/requests-and-responses – droopsnoot Dec 23 '20 at 11:07
  • @droopsnoot You're correct. I did try format my data as json before but I stupidly tried formatting it all and not just the body. If you add your comment as an answer I will accept it as the correct one. Thanks for your help. – Reece Dec 23 '20 at 11:31

1 Answers1

0

You are trying to post template or invoice data?

Nathan
  • 1
  • 2