I’m trying to automate some of my book-keeping by creating invoices
programmatically. I’m having trouble setting the category of an invoice
item. Here’s an example request, which I’m POSTing the
https://api.irisopenbooks.co.uk/v2/invoices endpoint as JSON (Note that the
category_id of “299087” corresponds to a category I’ve created in my
FreeAgent account):
{
"invoice": {
"contact": "https://api.freeagent.com/v2/contacts/3549849",
"dated_on": "16-11-2015",
"payment_terms_in_days": "29",
"ec_status": "UK/Non-EC",
"invoice_items": [
{
"description": "Test InvoiceItem",
"item_type": "Hours",
"price": "1.0",
"quantity": "1.0",
"category_id": "299087"
}
]
}
}
Here’s the response that I get back:
{
"invoice": {
"reference": "VAT EC BUSINESS (SWEDEN) 007",
"always_show_bic_and_iban": false,
"send_reminder_emails": false,
"updated_at": "2015-11-17T18:16:00.199Z",
"involves_sales_tax": false,
"exchange_rate": "1.0",
"due_on": "2015-12-15",
"is_interim_uk_vat": false,
"payment_terms_in_days": 29,
"net_value": "1.0",
"invoice_items": [
{
"category":
“https://api.irisopenbooks.co.uk/v2/categories/001”,
“description”: “Test InvoiceItem”,
“url”:
“https://api.irisopenbooks.co.uk/v2/invoice_items/28692688”,
“price”: “1.0”,
“item_type”: “Hours”,
“position”: 1,
“quantity”: “1.0”
}
],
“status”: “Draft”,
“total_value”: “1.0”,
“send_thank_you_emails”: false,
“paid_value”: “0.0”,
“bank_account”:
“https://api.irisopenbooks.co.uk/v2/bank_accounts/236086”,
“dated_on”: “2015-11-16”,
“omit_header”: false,
“currency”: “GBP”,
“url”: “https://api.irisopenbooks.co.uk/v2/invoices/14130568”,
“created_at”: “2015-11-17T18:16:00.180Z”,
“send_new_invoice_emails”: false,
“contact”: “https://api.irisopenbooks.co.uk/v2/contacts/3549849”,
“due_value”: “1.0”
}
}
The invoice item does not use the category_id that I supplied, but has
apparently defaulted to a category_id of 001. I’ve also tried specifying
the category as a hyperlink:
{
"invoice": {
"contact": "https://api.freeagent.com/v2/contacts/3549849",
"dated_on": "16-11-2015",
"payment_terms_in_days": "29",
"ec_status": "UK/Non-EC",
"invoice_items": [
{
"description": "Test InvoiceItem",
"item_type": "Hours",
"price": "1.0",
"quantity": "1.0",
"category":
“https://api.irisopenbooks.co.uk/v2/categories/299087”
}
]
}
}
This causes a 400 response with the error message:
{
"errors": {
"error": {
"message": "Invalid nominal code 299087"
}
}
}
I’m out of ideas. What should I try next?
Thanks,
Drew