curl --request PATCH \
--url https://api.tryhamsa.com/v2/voice-agents/functions-macros/{functionMacroId} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"code": "return /\\d{12,19}/.test(text.replace(/[\\s-]/g, ''));"
}
EOF{
"success": true,
"message": "success",
"data": {
"id": "9c1d2e3f-4a5b-4c6d-8e7f-0a1b2c3d4e5f",
"projectId": "fbb9e8b2-2dbb-40f9-a051-9404624e3247",
"userId": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"createdBy": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"updatedBy": null,
"name": "has_card_number",
"notes": "Matches 13 to 19 digits in a row",
"type": "JAVASCRIPT_FUNCTION",
"usedAs": "CHECK",
"code": "return /\\d{13,19}/.test(text.replace(/[\\s-]/g, ''));",
"params": null,
"requiredParams": [
"name"
],
"createdAt": "2026-10-20T09:15:00.000Z",
"updatedAt": "2026-10-20T09:15:00.000Z"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}Update Function or Macro
Changes the fields you send. New code, a new type, usedAs or name is compiled before it is saved. A HELPER’s params follow its code, and its code must still define {% macro <name>(...) %} with the (new) name: rename it in the code too. The change applies to every agent and guardrail using it.
curl --request PATCH \
--url https://api.tryhamsa.com/v2/voice-agents/functions-macros/{functionMacroId} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"code": "return /\\d{12,19}/.test(text.replace(/[\\s-]/g, ''));"
}
EOF{
"success": true,
"message": "success",
"data": {
"id": "9c1d2e3f-4a5b-4c6d-8e7f-0a1b2c3d4e5f",
"projectId": "fbb9e8b2-2dbb-40f9-a051-9404624e3247",
"userId": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"createdBy": "b7d9e979-4a16-437b-8571-4ed92a94faa8",
"updatedBy": null,
"name": "has_card_number",
"notes": "Matches 13 to 19 digits in a row",
"type": "JAVASCRIPT_FUNCTION",
"usedAs": "CHECK",
"code": "return /\\d{13,19}/.test(text.replace(/[\\s-]/g, ''));",
"params": null,
"requiredParams": [
"name"
],
"createdAt": "2026-10-20T09:15:00.000Z",
"updatedAt": "2026-10-20T09:15:00.000Z"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}{
"code": 8404,
"message": "Policy not found!",
"messageKey": "PolicyNotFound",
"params": {
"reason": "NO_DRAFT"
}
}Authorizations
Path Parameters
Body
Send at least one field. Fields you leave out keep their value. Changing type or usedAs is refused while a guardrail uses it in a slot the change would no longer fit.
Name (1-255 characters), unique in the project. A HELPER macro's name must be an identifier: letters, digits and underscores, not starting with a digit (FunctionMacroHelperNameInvalid), and its code must define {% macro <name>(...) %} with this name. For any macro written as definitions, the one named like the record runs (else the first).
1 - 255The code (1-20,000 characters), compiled when you save it.
Function: the body of function (text, vars) { ... }. text is what was said, as said; vars are the call's variables, as text unless a value is JSON. A CHECK returns true to match. An ACTION returns a string (the new text) or an object (the variables to set). JavaScript built-ins only (no console, fetch or timers); 50 ms and 16 MiB per run.
Macro: a template with text, vars and args, or a {% macro <name>(...) %} definition (required for HELPER, named like the record). A CHECK matches unless it renders empty, false, 0, none or no. An ACTION sets variables when it renders a JSON object; anything else is the new text. 50 ms and 64 KiB of output.
1 - 20000HELPER macros only, and optional: the parameters that the {% macro <name>(...) %} in code declares, in order. Hamsa reads them from the code; if you send them they must match it (FunctionMacroParamsMismatch). Leave out or null for CHECK and ACTION.
2064^[A-Za-z_][A-Za-z0-9_]*$Was this page helpful?