Create Invoice through API - PHP cURL - Sandbox

Hi Fari,

There’s a few changes to your JSON needed:

  • For invoices presently only one can be created at a time, so remove
    the array surrounding the hash
  • dated_on needs to be a date and not a time, so remove the time stamp
  • You have status twice (although this doesn’t cause a problem).
    Invoices can only be created as “Draft” and then have to be marked as sent
  • You can’t set net_value etc. Instead, create a nested array of
    invoice items with price and quantity and the API will fill out net_value,
    etc for you. Invoices are created in the same way as in the main app.

For example, using Curl:

curl https://api.sandbox.freeagent.com/v2/invoices
-H “Authorization: Bearer XXXXXXX”
-H “Accept: application/xml”
-H “Content-Type: application/json”
-X POST
-d ‘{
“invoice”: {
“contact”: “https://api.sandbox.freeagent.com/v2/contacts/1”,
“status”: “Draft”,
“dated_on”: “2012-08-16”,
“currency”: “GBP”,
“exchange_rate”: “1.0”,
“comments”: “Added by api”,
“omit_header”: false,
“payment_terms_in_days”: 30,
“invoice_items”: [
{
“description”: “Test InvoiceItem”,
“item_type”: “Hours”,
“price”: “112.0”,
“quantity”: “1.0”
}
]
}
}’

Kind regards,

GraemeOn 24 July 2012 15:34, Fari farahmand.moslemi@gmail.com wrote:

Hi,

I want to create an invoice for an existing contact, but I can’t. I can
create a project for that contact.

$post_cars = ‘{“invoice”:[{“contact”:"
https://api.sandbox.freeagent.com/v2/contacts/385",“status”:“Draft”,“dated_on”:"2012-08-16
10:40
GMT",“currency”:“GBP”,“exchange_rate”:“1.0”,“net_value”:“112.0”,“sales_tax_value”:“22.4”,“total_value”:“134.4”,“paid_value”:“0.0”,“due_value”:“134.4”,“status”:“Open”,“comments”:“Added
by api”,“omit_header”:false,“payment_terms_in_days”:30}]}’;

I’ve also tried “/v2/contacts/385”, but no success.

Any help, please?

Thank you,
Fari


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/hXLuxitoEN8J.
To post to this group, send email to freeagent_api@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.

Graeme Boyd
Senior Software Engineer

Web. freeagent.com http://www.freeagent.com/ Blog. freeagent.com/blog
Twitter. @freeagent https://twitter.com/#!/freeagent Facebook.
facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774