Setting the category of an invoice item

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

Hi Drew,

When specifying a category in the API you need to use the API for the
resource as it appears in the list of categories, which you can get using GET
https://api.freeagent.com/v2/categories as explained in the API docs
https://dev.freeagent.com/docs/categories. For categories, the nominal
code is used, not the ID that you may be seeing in your browser. For
example, if you wanted to use the Accommodation and Meals admin expenses
category, you would use the URL https://api.freeagent.com/v2/categories/285.

Regards,
Harry MillsOn Tue, Nov 17, 2015 at 1:33 PM, Drew Neil andrew.jr.neil@gmail.com wrote:

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
Log in to your FreeAgent account 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”: "
Log in to your FreeAgent account”,
“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”: "
Log in to your FreeAgent account",
“dated_on”: “2015-11-16”,
“omit_header”: false,
“currency”: “GBP”,
“url”: “Log in to your FreeAgent account”,
“created_at”: “2015-11-17T18:16:00.180Z”,
“send_new_invoice_emails”: false,
“contact”: “Log in to your FreeAgent account”,
“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": "

Log in to your FreeAgent account"
}
]
}
}

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


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/d/optout.

Thanks Harry, I’ve got this to work now. I was using the category id as it
appeared in the browser, rather than the nominal code. I found out via the
API that the nominal code for the category I want is 005, and now when I
POST to the invoices endpoint with this data it has the effect that I want:

{
  "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/005"
      }
    ]
  }
}

Cheers,
DrewOn Tuesday, November 17, 2015 at 6:50:38 PM UTC, Harry wrote:

Hi Drew,

When specifying a category in the API you need to use the API for the
resource as it appears in the list of categories, which you can get using GET
https://api.freeagent.com/v2/categories as explained in the API docs
https://dev.freeagent.com/docs/categories. For categories, the nominal
code is used, not the ID that you may be seeing in your browser. For
example, if you wanted to use the Accommodation and Meals admin expenses
category, you would use the URL https://
api.freeagent.com/v2/categories/285.


Regards,
Harry Mills

On Tue, Nov 17, 2015 at 1:33 PM, Drew Neil <andrew....@gmail.com <javascript:>> wrote:

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
Log in to your FreeAgent account 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": "

Log in to your FreeAgent account",
“description”: “Test InvoiceItem”,
“url”: "
Log in to your FreeAgent account",
“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”: "
Log in to your FreeAgent account",
“dated_on”: “2015-11-16”,
“omit_header”: false,
“currency”: “GBP”,
“url”: “Log in to your FreeAgent account”,
“created_at”: “2015-11-17T18:16:00.180Z”,
“send_new_invoice_emails”: false,
“contact”: "Log in to your FreeAgent account
",
“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": "

Log in to your FreeAgent account"
}
]
}
}

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


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_ap...@googlegroups.com <javascript:>.
To post to this group, send email to freeag...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/d/optout.