500 Error when Creating an Invoice

Hi all, Im not sure what I’m doing wrong. I’m trying to use the sandbox to
create an invoice against the contact, but whenever I include
the invoice_items it always throws a 500 error:

500 Internal Server Error

If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.

Its not a particularly helpful error and shouldn’t really be in HTML.

Heres a sample of the invoice im trying to create:

POST https://api.freeagent.com/v2/invoices

{
“invoice”:{
“reference”:“JL-INV-201401242345”,
“contact”:“https://api.sandbox.freeagent.com/v2/contacts/28444”,
“dated_on”:“2015-01-31”,
“payment_terms_in_days”:30,
“currency”:“EUR”,
“ec_status”:“EC Services”,
“invoice_items”:[
{
“description”:“Enterprise Subscription”,
“item_type”:“Services”,
“price”:“100”,
“quantity”:“1.0”
}
]
}
}

I have tried various combinations inside the invoice items and cant seem to
get anything to work at all. I’ve even tried creating the invoice and then
PUT’ing the invoice_items afterwards, but nothing seems to work.

The request was sent around 1421060820.

Can anyone help?

Hi David,

Thanks for getting back to me. It turns out I was being an idiot and the
PHP library I was using was sending the data as form fields
(application/x-www-form-urlencoded) instead of JSON. Looks like that works
for other API calls that dont use arrays.

All is good now, Thanks :)On Monday, 12 January 2015 12:02:39 UTC, David Jones wrote:

The only thing worse than spotting a typo in a response is spotting 2
typos in a response :slight_smile:

We know we need to work on our errors, including returning them in a
non-http format, watch this space :slight_smile:
We know we need to work on our errors, including returning them in a
non-html format, watch this space :slight_smile:

Here’s what we’re receiving (once marshalled into a ruby array)
Here’s what we’re receiving (once marshalled into a ruby hash)

On Monday, 12 January 2015 11:46:43 UTC, David Jones wrote:

Hi Adam,

Thanks for your message and apologies for the less than helpful 500 error
you’re receiving.
We know we need to work on our errors, including returning them in a
non-http format, watch this space :slight_smile:

I’ve had a search through our logs and it looks like there’s a slight
problem with the array of invoice_items you’re sending.
Here’s what we’re receiving (once marshalled into a ruby array)

“invoice_items”=>{
“0”=>{
“description”=>“Enterprise Subscription”,
“item_type”=>“Services”,
“price”=>“100”,
“quantity”=>“1.0”
}
}

The unexpected “0” key is an issue, as is the fact that everything should
be wrapped inside an array.

Here’s the JSON needed to successfully create your invoice item:

“invoice_items”:[
{
“description”:“Enterprise Subscription”,
“item_type”:“Services”,
“price”:“100”,
“quantity”:“1.0”
}
]

To help track down problems like this, you might want to try POSTing your
request to HTTPBin http://httpbin.org/:
This service takes your POST request and simply echoes it back to you, so
you can take a close look at the params you’re sending.

Hope this helps!

Hi Adam,

Thanks for your message and apologies for the less than helpful 500 error
you’re receiving.
We know we need to work on our errors, including returning them in a
non-http format, watch this space :slight_smile:

I’ve had a search through our logs and it looks like there’s a slight
problem with the array of invoice_items you’re sending.
Here’s what we’re receiving (once marshalled into a ruby array)

“invoice_items”=>{
“0”=>{
“description”=>“Enterprise Subscription”,
“item_type”=>“Services”,
“price”=>“100”,
“quantity”=>“1.0”
}
}

The unexpected “0” key is an issue, as is the fact that everything should
be wrapped inside an array.

Here’s the JSON needed to successfully create your invoice item:

“invoice_items”:[
{
“description”:“Enterprise Subscription”,
“item_type”:“Services”,
“price”:“100”,
“quantity”:“1.0”
}
]

To help track down problems like this, you might want to try POSTing your
request to HTTPBin http://httpbin.org/:
This service takes your POST request and simply echoes it back to you, so
you can take a close look at the params you’re sending.

Hope this helps!

The only thing worse than spotting a typo in a response is spotting 2
typos in a response :slight_smile:

We know we need to work on our errors, including returning them in a
non-http format, watch this space :slight_smile:
We know we need to work on our errors, including returning them in a
non-html format, watch this space :slight_smile:

Here’s what we’re receiving (once marshalled into a ruby array)
Here’s what we’re receiving (once marshalled into a ruby hash)On Monday, 12 January 2015 11:46:43 UTC, David Jones wrote:

Hi Adam,

Thanks for your message and apologies for the less than helpful 500 error
you’re receiving.
We know we need to work on our errors, including returning them in a
non-http format, watch this space :slight_smile:

I’ve had a search through our logs and it looks like there’s a slight
problem with the array of invoice_items you’re sending.
Here’s what we’re receiving (once marshalled into a ruby array)

“invoice_items”=>{
“0”=>{
“description”=>“Enterprise Subscription”,
“item_type”=>“Services”,
“price”=>“100”,
“quantity”=>“1.0”
}
}

The unexpected “0” key is an issue, as is the fact that everything should
be wrapped inside an array.

Here’s the JSON needed to successfully create your invoice item:

“invoice_items”:[
{
“description”:“Enterprise Subscription”,
“item_type”:“Services”,
“price”:“100”,
“quantity”:“1.0”
}
]

To help track down problems like this, you might want to try POSTing your
request to HTTPBin http://httpbin.org/:
This service takes your POST request and simply echoes it back to you, so
you can take a close look at the params you’re sending.

Hope this helps!