Invalid JSON trying to create an invoice

I’ve tried to create an invoice using your documentation and used the exact format being specified on this page:

https://dev.freeagent.com/docs/invoices

I’ve managed to successfully create a contact but so far no luck with invoices.

I’ve tried to create an invoice as follows (replacing the contact url with a valid one) and it’s exactly the same format as the one in the documentation but getting this returned:

{
“error”: “Invalid JSON”
}

Please kindly provide resolution.

{ “invoice”:
{
“contact”:“https://api.freeagent.com/v2/contacts/2”,
“dated_on”:“2019-01-01”,
“due_on”:“2019-02-01”,
“reference”:“003”,
“currency”:“GBP”,
“exchange_rate”:“1.0”,
“net_value”:“0.0”,
“total_value”: “200.0”,
“paid_value”: “0.0”,
“due_value”: “200.0”,
“status”:“Draft”,
“omit_header”:false,
“always_show_bic_and_iban”: false,
“send_thank_you_emails”:false,
“send_reminder_emails”:false,
“send_new_invoice_emails”: false,
“bank_account”: “https://api.freeagent.com/v2/bank_accounts/1”,
“payment_terms_in_days”:5,
“payment_methods”: {
“paypal”: false,
“stripe”: false,
},
“created_at”:“2011-08-29T00:00:00Z”,
“updated_at”:“2011-08-29T00:00:00Z”,
“invoice_items”:[
{
“description”:“Test InvoiceItem”,
“item_type”:“Hours”,
“price”:“0.0”,
“quantity”:“0.0”
}
]
}
}

Thanks

Hello,

First of all, your JSON is invalid. You can’t have a comma without a new key/value pair after it. So the comma after “stripe”:false is invalid. You can check your JSON here: https://jsonlint.com/

Second, I was able to use the corrected JSON (replacing the contact and bank account with my own) to make one successfully.

And third, if you are getting any error messages, let us know.

Hope that helps,

Pat George, FreeAgent

Thanks Pat George,

I’ve retested and it works fine. Just so you know, I copied and pasted from the below link which appears to be incorrect and it may be worth fixing.

https://dev.freeagent.com/docs/invoices

Good spot, Hassan. I’ll get it checked out.

Just a quick follow up, Hassan. I’ve updated the docs and will push it live Monday morning. Thanks again for letting us know.

Ok, the docs have been updated to have correct JSON (as far as I can find, at least).

Thanks Pat,

I’ve managed to build my program to create invoices in the backend. Works quite well after a lot of pain!