Jobs: reports, email and links
Email a job report with a specified invoice
/a/Job_emailReportInvoice
Use the legacy combined job-report and explicitly selected invoice mail path.
When to use this endpoint
This older helper accepts an invoice ID independently of the job’s stored link. Current CRM email dialogs use Job_emailReport for reports and Invoice_sendEmail for invoice-only mail; prefer those workflows when they fit.
Authentication and permissions
Requires signed API-key or CRM-session authentication, an active job and an active directly/legacy-linked invoice in the authenticated tenant. crm_access bit 64 blocks this finance operation before mail.
The dispatcher also applies user/account and IP restrictions. CRM sessions carrying a CSRF token must supply X-FMCSRF or _csrf; missing or incorrect tokens can be rejected before the handler runs.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer string | Yes | Positive decimal job ID. The job must be active in the authenticated tenant. |
invoice_id | Integer string | Yes | Positive decimal invoice ID. Must identify an active invoice directly or legacy-linked to this job; Paid status is not prohibited for sending. |
emailsTo | String | Yes | Recipients separated by commas or newlines. Trims addresses, keeps only valid email addresses, and rejects a list with no valid address. |
email_subject | String | No | Truthy value forwarded as mail metadata; blank/omitted is not added. |
email_template | Integer string | No | Truthy value forwarded as mail metadata; no template existence check. |
email_body | String | No | Truthy message forwarded as mail body through Core_mail normalization. |
job_id | Integer string | No | Legacy input ignored in the effective metadata: overwritten with the job found through id. |
user_id | Integer string | No | Legacy input overwritten with the authenticated acting user. |
Example request
$result = FM_api('Job_emailReportInvoice', [
'id' => '1042',
'invoice_id' => '501',
'emailsTo' => 'engineer@example.com, office@example.com',
'email_subject' => 'Job report and invoice',
'email_body' => 'Please review both documents.',
]);
Example response
null
There is no explicit success return; the dispatcher serializes null. Do not treat this as an empty object, an ok envelope or proof of delivery.
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error":"Missing parameter id"} | id is absent. |
{"error":"Missing parameter invoice_id"} | invoice_id is absent. |
{"error":"Missing parameter emailsTo"} | emailsTo is absent. Blank or wholly invalid recipient lists later return no email address. |
{"error":"Job not found!"} | Active job query found no row. |
{"error":"Job email queue response was not confirmed. Check mail history before retrying."} | Mail failed or returned an ambiguous acknowledgement. Earlier recipients may already be queued; do not repeat automatically. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Attempts type-6 Core_mail with the job’s customer_id without resolving an asset owner. Splits commas/newlines, trims valid recipients and rejects an empty usable list.
- After a positive mail acknowledgement, stamps the selected active linked invoice email_sent and job meta.report_sent/pdf_sent; uncertain mail does not trigger these CRM writes.
- Finance-restricted users (crm_access bit 64) are rejected; IDs must be positive decimal strings. No completion requirement, recipient limit or paging applies.
Side effects
- After confirmed mail, commits the invoice email_sent, linked-job invoice_sent and this job’s report/pdf markers together. A failed marker transaction returns ok with warning because the email has already been queued.
See it in Fieldmotion
CRM1
No direct caller of this route was found. The current jobMail Report tab calls Job_emailReport; the Invoice tab calls Invoice_sendEmail.
CRM2
No direct caller was found. The current email widget uses Job_emailReport and separate invoice mail rather than this legacy combined helper.
Related endpoints
Job_emailReportsupports the current report-mail and attachment selection workflow.Job_invoiceLinkvalidates an active job and open invoice before linking.