Unable to add invoice_items to existing invoice

I’ve been trying to add a line item to an invoice that already exists as a
draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items[] = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but the item
is not added.

Any ideas?

This isn’t possible at the moment, so you will have to keep track of the
deletions at least. Then you can just send DELETE requests to
/v2/invoice_items/xxx for each line item you wish to delete.

Cheers,
IoanOn Wednesday, 31 July 2013 14:36:56 UTC+1, Nic Wise wrote:

While you are there Ioan, is there a nice way to say “here’s an
invoice (which already exists). Make the invoice lines look like
this…”

If I have an invoice with 3 lines, and update it (download the
invoice, make changes, upload it (PUT?)) to only have 2 (eg, remove 2,
add one), then I have 4 lines (the original 3, plus the new one)

I “solved it” by deleting the old invoice and creating a new one,
which feels wrong. Tracking each line isn’t really practical.

On 31 July 2013 14:11, Ioan Serban <io...@freeagent.com <javascript:>> wrote:

Hi Jeremy,

Sorry for the unclear documentation. The ‘invoice_items’ array needs to
be a
property on an ‘invoice’ object, so you need something like:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);
$items = array();
$items = $line;
$invoice = array(‘invoice’);
$invoice[‘invoice_items’] = $invoice;

Regards,
Ioan

On Wednesday, 31 July 2013 13:24:31 UTC+1, Jeremy Gimbel wrote:

I’ve been trying to add a line item to an invoice that already exists
as a
draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but the
item
is not added.

Any ideas?


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/groups/opt_out.


Nic Wise
t. +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/

Thanks. I actually saw that and tried it, which returned a 500. Is there
anything else that needs to be included in the invoice array, or in the
line items that I’m missing?On Wednesday, July 31, 2013 9:11:41 AM UTC-4, Ioan Serban wrote:

Hi Jeremy,

Sorry for the unclear documentation. The ‘invoice_items’ array needs to be
a property on an ‘invoice’ object, so you need something like:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);
$items = array();
$items = $line;
$invoice = array(‘invoice’);
$invoice[‘invoice_items’] = $invoice;

Regards,
Ioan

On Wednesday, 31 July 2013 13:24:31 UTC+1, Jeremy Gimbel wrote:

I’ve been trying to add a line item to an invoice that already exists as
a draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but the
item is not added.

Any ideas?

Thanks. I have it working now so that it deletes all the old lines and
posts the invoice as an update (with lines)

mobileAgent 2.1.1 I think :slight_smile:

BTW, the docs for the invoice page is all over the place. refers to
estimates in one URL, the “id” property for each invoice_line is
actually “url”, tho you can’t ever SEND one (appears to have to be
without url when posting the parent invoice)…On 31 July 2013 15:37, Ioan Serban ioan@freeagent.com wrote:

This isn’t possible at the moment, so you will have to keep track of the
deletions at least. Then you can just send DELETE requests to
/v2/invoice_items/xxx for each line item you wish to delete.

Cheers,
Ioan

On Wednesday, 31 July 2013 14:36:56 UTC+1, Nic Wise wrote:

While you are there Ioan, is there a nice way to say “here’s an
invoice (which already exists). Make the invoice lines look like
this…”

If I have an invoice with 3 lines, and update it (download the
invoice, make changes, upload it (PUT?)) to only have 2 (eg, remove 2,
add one), then I have 4 lines (the original 3, plus the new one)

I “solved it” by deleting the old invoice and creating a new one,
which feels wrong. Tracking each line isn’t really practical.

On 31 July 2013 14:11, Ioan Serban io...@freeagent.com wrote:

Hi Jeremy,

Sorry for the unclear documentation. The ‘invoice_items’ array needs to
be a
property on an ‘invoice’ object, so you need something like:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);
$items = array();
$items = $line;
$invoice = array(‘invoice’);
$invoice[‘invoice_items’] = $invoice;

Regards,
Ioan

On Wednesday, 31 July 2013 13:24:31 UTC+1, Jeremy Gimbel wrote:

I’ve been trying to add a line item to an invoice that already exists
as a
draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but the
item
is not added.

Any ideas?


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.
To post to this group, send email to freeag...@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Nic Wise
t. +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/


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/groups/opt_out.

Nic Wise
t. +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/

Jeremy:

I think my example was wrong. Doing:

$invoice = array();
$invoice[‘invoice’][‘invoice_items’] = $items;

should however work. Basically your JSON needs to be in the format:

{“invoice”: {“invoice_items”: [{…item1…}, {…item2…}]}}

Nic: I’m going to have a thorough look at the documentation in the
following weeks and bring it up to date with the current behaviour of the
API, so it’s going to be clearer soon and save some sweat :slight_smile:

Cheers,
IoanOn Wednesday, 31 July 2013 16:27:54 UTC+1, Nic Wise wrote:

Thanks. I have it working now so that it deletes all the old lines and
posts the invoice as an update (with lines)

mobileAgent 2.1.1 I think :slight_smile:

BTW, the docs for the invoice page is all over the place. refers to
estimates in one URL, the “id” property for each invoice_line is
actually “url”, tho you can’t ever SEND one (appears to have to be
without url when posting the parent invoice)…

On 31 July 2013 15:37, Ioan Serban <io...@freeagent.com <javascript:>> wrote:

This isn’t possible at the moment, so you will have to keep track of the
deletions at least. Then you can just send DELETE requests to
/v2/invoice_items/xxx for each line item you wish to delete.

Cheers,
Ioan

On Wednesday, 31 July 2013 14:36:56 UTC+1, Nic Wise wrote:

While you are there Ioan, is there a nice way to say “here’s an
invoice (which already exists). Make the invoice lines look like
this…”

If I have an invoice with 3 lines, and update it (download the
invoice, make changes, upload it (PUT?)) to only have 2 (eg, remove 2,
add one), then I have 4 lines (the original 3, plus the new one)

I “solved it” by deleting the old invoice and creating a new one,
which feels wrong. Tracking each line isn’t really practical.

On 31 July 2013 14:11, Ioan Serban io...@freeagent.com wrote:

Hi Jeremy,

Sorry for the unclear documentation. The ‘invoice_items’ array needs
to
be a
property on an ‘invoice’ object, so you need something like:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);
$items = array();
$items = $line;
$invoice = array(‘invoice’);
$invoice[‘invoice_items’] = $invoice;

Regards,
Ioan

On Wednesday, 31 July 2013 13:24:31 UTC+1, Jeremy Gimbel wrote:

I’ve been trying to add a line item to an invoice that already
exists
as a
draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but
the
item
is not added.

Any ideas?


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.
To post to this group, send email to freeag...@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Nic Wise
t. +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/


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/groups/opt_out.


Nic Wise
t. +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/

Hi Jeremy,

Sorry for the unclear documentation. The ‘invoice_items’ array needs to be
a property on an ‘invoice’ object, so you need something like:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);
$items = array();
$items = $line;
$invoice = array(‘invoice’);
$invoice[‘invoice_items’] = $invoice;

Regards,
IoanOn Wednesday, 31 July 2013 13:24:31 UTC+1, Jeremy Gimbel wrote:

I’ve been trying to add a line item to an invoice that already exists as a
draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but the item
is not added.

Any ideas?

While you are there Ioan, is there a nice way to say “here’s an
invoice (which already exists). Make the invoice lines look like
this…”

If I have an invoice with 3 lines, and update it (download the
invoice, make changes, upload it (PUT?)) to only have 2 (eg, remove 2,
add one), then I have 4 lines (the original 3, plus the new one)

I “solved it” by deleting the old invoice and creating a new one,
which feels wrong. Tracking each line isn’t really practical.On 31 July 2013 14:11, Ioan Serban ioan@freeagent.com wrote:

Hi Jeremy,

Sorry for the unclear documentation. The ‘invoice_items’ array needs to be a
property on an ‘invoice’ object, so you need something like:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);
$items = array();
$items = $line;
$invoice = array(‘invoice’);
$invoice[‘invoice_items’] = $invoice;

Regards,
Ioan

On Wednesday, 31 July 2013 13:24:31 UTC+1, Jeremy Gimbel wrote:

I’ve been trying to add a line item to an invoice that already exists as a
draft.

From the docs, I’m sending a PUT to
https://api.sandbox.freeagent.com/v2/invoices/xxx

I’ve constructed an item array:

$line = array(
‘position’ => ‘1000’,
‘quantity’ => ‘1’,
‘item_type’ => ‘Expenses’,
‘price’ => ‘14.97’,
‘description’ => ‘Credit card convenience fee’

);

Then an items array, and add the item to it.
$items = array();
$items = $line;

Then the parameter array has the invoice items added:

array(‘invoice_items’ => $items);

This gets PUT to the endpoint, and I get a 200 response back, but the item
is not added.

Any ideas?


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/groups/opt_out.

Nic Wise
t. +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/

Ah never mind me. I was using an OAUTH client which wasn’t sending the data
as a JSON string.

Thanks for the help!