Unauthorised 401 when creating invoice


#1

Hi all,

I receive a 401 Unauthorized response when trying to create an new invoice with the JSON at the bottom. The URI’s used are valid/exist. I am using https://developers.google.com/oauthplayground/ to send the POST request to https://api.sandbox.freeagent.com/v2/invoices. Other POST or GET requests I have tried work but not this one. Anybody has an idea what the problem might be? What puzzles me particularly is that the response is 401.

{

"contact":"https://api.sandbox.freeagent.com/v2/contacts/72538",
"dated_on":"2011-08-29",
"due_on":"2011-09-28",
"reference":"001",
"currency":"GBP",
"exchange_rate":"1.0",
"net_value":"0.0",
"sales_tax_value":"0.0",
"total_value": "200.0",
"paid_value": "50.0",
"due_value": "150.0",
"status":"Draft",
"comments":"An example invoice comment.",
"omit_header":false,
"always_show_bic_and_iban": false,
"send_thank_you_emails":false,
"send_reminder_emails":false,
"send_new_invoice_emails": false,
"bank_account": "https://api.sandbox.freeagent.com/v2/bank_accounts/4956",
"payment_terms_in_days":30,
"category":"https://api.sandbox.freeagent.com/v2/categories/450",
"ec_status":"EC Goods",
"payment_methods": {
  "paypal": true,
  "stripe": false
},
"created_at":"2011-08-29T00:00:00Z",
"updated_at":"2011-08-29T00:00:00Z",
"invoice_items":[
  {
    "description":"Test InvoiceItem",
    "item_type":"Hours",
    "price":"0.0",
    "quantity":"0.0"
  }
]

}


#2

Hi @thei :wave:

Peter here from the Engineering team at FreeAgent - sorry to hear you’re having trouble.

I’ve had a quick look here for you, and it looks like you’re not wrapping your params in an invoice key, like so:

{
  "invoice": {
    "url": "https://api.sandbox.freeagent.com/v2/invoices/88390",
    "contact": "https://api.sandbox.freeagent.com/v2/contacts/72540",
    ....
  }
}

From the docs:

“Payload should have a root invoice element, containing elements listed under Invoice Attributes.”

Sorry about the 401 error - in this case it’s the wrong thing to return, and is a bit misleading; I’ll raise it internally to see if we can try to improve our error responses in the future.

For now though, I hope this gets you back on track!

All the best,
Peter


#3

Ah fantatsic, thanks for the quick answer Peter!