Emailing Invoices using the Contact's email address

I am wanting to email an invoice using the APIs.
https://dev.freeagent.com/docs/invoices#email-an-invoice
This is all working for me provided that I specify the email address that I want to send it to.

However, I’d prefer to be able to just use the default email address that is held against the FreeAgent contact.
If I send a blank email address then the error that I am seeing is:
api.freeagent.com returned (422) Unprocessable Entity and said “to can’t be blank”

So my question is, is there anything (possibly undocumented) that I can specify that satisfies the “to” field having a value but that would pick up the associated email address and send the email to that address?

Thanks

Hello @tony1,

Thank you for your question. There is one way of using the contact email as the default, when using the send_email endpoint of the API, in order to not provide it again in the body. What you need to do to is create an invoice template. Here is the article of our knowledge base explaining how you can do that https://support.freeagent.com/hc/en-gb/articles/115001219010-Automatic-emails-for-new-invoices .
Once you have your invoice template saved, you can use the parameter use_template in the email hash of your POST request.

Best regards,
Eva

Thanks for that Eva.

I’m not an expert with these API’s and I did struggle with this for quite a while.
While trying to get this to work, I found another way of achieving the same thing.

Not to be beaten, I did get “use_template” working (at least using the Google OAuth 2.0 Playground).
So the answer following Eva’s suggestion was to use the following in the request body (I wasn’t including the true part):

{
“invoice”:{
“email”:{ “use_template”: true
}
}
}

The other method I found was to use the placeholders from the template…which I was already using in the subject (and body but not shown)

{
“invoice”:{
“email”:{
“body”:"…",
“from”:"verified.address@company.co.uk",
“to”:"[billing_or_contact_email]",
“subject”:"invoice [reference] "
}
}
}