I have been using a GET request to api/v1/invoices/[id]/email for over a year to send emails. Today I first noticed that request returning this error:
Exception: Request failed for https://invoicing.co returned code 400. Truncated server response: {"message":"The requested action email is not available."}
I’m not sure, I wouldn’t expect to be able to send an email using a GET request.
I believe you can use the bulk action route to send an email. I suggest sending an email in the app and using the network tab in the browser console to see a sample API request.
I wouldn’t expect to be able to send an email using a GET request
Perhaps, but it had previously worked for hundreds of emails!
Using the web app was a great suggestion. The invoicing.co/api/v1/emails route is used there and I was able to replicate that request with the same payload.
One suggestion is to update the API docs for api/v1/emails to provide more information on the required template field. It is difficult to find the available template values and snooping in the web app seemed the only way to find a valid value (in this case template: "email_template_invoice",).
When I was testing this endpoint the values that are now in the enum for the docs site returned errors. How would one learn what the possible template values are?
@david “invoice” fails but “email_template_invoice” succeeds.
const data = {
template: "invoice", // the value "email_template_invoice" works here
entity: "invoice",
entity_id: "5eVA5lqodE",
};
const options = {
payload: JSON.stringify(data),
method: "post",
headers: getInvoiceNinjaRequestHeadersJson(),
};
const emailUrl = getInvoiceNinjaApiPath() + "/emails";
UrlFetchApp.fetch(emailUrl, options);
Exception: Request failed for https://invoicing.co returned code 422. Truncated server response: {"message":"The given data was invalid.","errors":{"template":["The template field is required."]}} (use muteHttpExceptions option to examine full response)