When to use this endpoint

Use Customers_countJobs to warn before a bulk customer deletion or another action whose impact depends on linked jobs.

The endpoint returns only counts. Use Customer_listJobs when you need job identities or status details for one customer.

Authentication and permissions

The request must authenticate with signed API-key fields or a logged-in CRM session. The handler performs no additional page or role-permission check.

The lookup and any write use the authenticated tenant; an ID from another tenant cannot be addressed through this call.

Parameters

ParameterTypeRequiredDescription
idsJSON array stringYesCustomer IDs to count. Values are converted to integers before being placed in the query.

Example request

$counts = FM_api('Customers_countJobs', [
	'ids' => json_encode(['1042', '1088']),
]);

Example response

[
  {
    "customer_id": "1042",
    "cnt": "3"
  }
]

Customers with zero matching jobs are omitted rather than returned with cnt: "0". Database aggregate values are serialized as strings.

Errors and unusual responses

ResponseCondition
{"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: ids"}ids is absent.
{"error":"invalid parameter: ids"}ids does not decode to an array.
Database error or unusual responseAn empty array reaches a legacy IN () query instead of returning an explicit empty result.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • Only rows with customer_type=0 are counted, so an asset whose numeric ID happens to match a customer ID is not included.
  • Soft-deleted jobs are excluded. The customer row itself is not joined or checked, so inactive, deleted, and nonexistent customer IDs are treated the same for counting purposes.
  • Duplicate input IDs collapse into one grouped result. The query does not define result order.
  • There is no pagination or explicit ID-count limit.

See it in Fieldmotion

CRM1

On Customers, select records and choose the delete bulk action. Before confirmation, CRM1 calls Customers_countJobs and lists only selected customers that have jobs.

CRM2

On Customers, select records and choose the permanent-delete action after they are archived. CRM2 calls Customers_countJobs to build the warning list; filter Network requests by the function name.

Related endpoints