Sending an Invoice by email

Hi,

I’m trying to sent an invoice via email through the API.

Unfortunately there isn’t an example call in the documentation, just the fields required, which I believe I have put in place.

Also, can anyone confirm if sending the invoice via email also sets the invoice to sent status automatically?

The following POST goes to api.freeagent.com/v2/invoices/XXXX/send_email

{
“invoice”: {
“email”: {
“to”: “myemail”,
“from”: “myemail”,
“subject”: “Invoice for”,
“body”: "Hi,\r\n\r\n Please find attached an invoice for a recent Order: 00808179-111120.\r\n \r\n Payment can be made via BACS or on card via the below payment link\r\n \r\n [online_payment_link]\r\n \r\n If you have any problems just get in touch.\r\n \r\n Many Thanks,\r\n \r\n "
}
}
}

I’m getting the error:

<?xml version="1.0" encoding="UTF-8"?> Format not recognised. Set accept http header to application/json or application/xml

Hi John,

Thanks for your message and welcome to our API forum :wave: My name is Ewa and I’m one of the engineers here at FreeAgent; hopefully I’ll be able to help.

Also, can anyone confirm if sending the invoice via email also sets the invoice to sent status automatically?

That’s right, once the invoice is successfully sent via the API, its status will automatically change to Sent.

I’m getting the error:

<?xml version="1.0" encoding="UTF-8"?> Format not recognised. Set accept http header to application/json or application/xml

I don’t see anything obviously wrong with your request body, however judging by the error message you received, it might be the headers that are at fault here – did you try setting the Accept header as suggested?

Best wishes,

Ewa

Hi Ewa,
Thanks for the fast reply.

The call I made was using the exact same settings I use to create an invoice which works fine (in Postman and PHP)

However I’ve done as suggested and it’s made a difference, I now get

{
“errors”: {
“error”: {
“message”: “Resource not found”
}
}
}

The call is being made to
https://api.freeagent.com/v2/invoices/39553XXX/send_email

Probably a silly mistake somewhere…

Ah, interesting! Are you able to query the invoice individually using GET https://api.freeagent.com/v2/invoices/:id, just to make sure an invoice with this id definitely exists?

I’ve had a look in our application logs to see if I can spot your requests, and I think I might have found the problem – it looks like you’re including a newline character (%0A) at the end of the endpoint path, which has confused our API as it couldn’t find an endpoint that would match /v2/invoices/39553XXX/send_email%0A and hence returned a 404. If you remove the stray newline, I believe everything should work as expected!

Best wishes,

Ewa

Bingo!

Thanks for your help :slight_smile:

1 Like