Add a business rule
/v1/projects/{project}/business-rules in the Business Rules API.
curl -X POST https://api.example.test/v1/projects/$PROJECT_ID/business-rules \ -H "Authorization: Bearer $TOKEN" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "name": "Platinum tier threshold", "type": "inference", "statement": "<p>A member whose spend over the last twelve months reaches 5,000 is a platinum member.</p>", "condition": "When a member'"'"'s rolling twelve-month spend reaches 5,000", "action": "then the member moves to the platinum tier on the first of the next month", "examples": [ { "input": "Spend 4,999 on 30 November", "expected": "Stays gold" }, { "input": "Spend 5,000 on 30 November", "expected": "Platinum from 1 December" } ], "priority": "must" }'Only name is required. The rule takes the next number of the rules' sequence and the reference spelled from the project's key, starts as a draft unless status says otherwise, a constraint unless type does and should unless priority does. The dates in force must be in order, the authority stakeholder must be a stakeholder of the project and the owner a member of the team. The save writes version one.
Answers 201 with the rule and emits business_rule.created.
Requires ability
The token must hold this ability, or the call is refused with 403.
Fires one event
Delivered to every endpoint subscribed to it once the change is made.
MCP tool
Runs the same action from an agent, behind the same ability.
Idempotent
Send the header on every call; the same key replays the original response for 24 hours.
Authorization
bearerToken A personal access token minted in the app under Account Settings, then API Tokens, sent as Authorization: Bearer zg_live_…. The token carries the abilities each endpoint lists under Requires ability and is frozen to one team, and optionally to one project, at mint time.
In: header
Path Parameters
The project, bound by the middleware.
uuidHeader Parameters
A key unique to this operation, such as a fresh UUID. The same key replays the original 2xx response for 24 hours (with Idempotent-Replay: true), so a retry after a timeout never repeats the write; the same key with a different body is refused with 409.
uuidRequest body
JSONWhat the request carriesOptionalapplication/json
A business rule to add or change. Only name is required on a create; the kind defaults to constraint, the priority to should and the status to draft. On an update, a field left out keeps its value and a field sent as null is cleared; examples, when sent, replaces the list; the status moves through its own endpoint.
Responses
201Createdapplication/json
The rule, 201.
400Bad requestIDEMPOTENCY_KEY_MISSINGapplication/json
Every write needs an Idempotency-Key header. Send a fresh UUID per distinct operation.
401UnauthorizedAUTHENTICATION_REQUIREDapplication/json
The request carries no bearer token, or one that is revoked, malformed, or minted for another environment (a zg_test_ token on production).
403ForbiddenTOKEN_MISSING_ABILITYapplication/json
The token is valid but does not carry the ability this endpoint requires; error.context.required_ability names the one to grant. An endpoint that also checks who registered a row answers FORBIDDEN with the same status, and says so in its own description.
On this endpoint: FORBIDDEN: when the token holder's role on the project does not carry business-rule:create.
404Not foundRESOURCE_NOT_FOUNDapplication/json
An id in the path names nothing the token can see. TENANT_MISMATCH: the project sits outside the token's scope:project: allow-list, or the token carries no team scope. Both answer 404 rather than 403 so that existence outside the token's scope cannot be inferred.
409ConflictIDEMPOTENCY_KEY_REUSEDapplication/json
The key was already used in the last 24 hours with a different request body.
422Validation failedVALIDATION_FAILEDapplication/json
The payload broke a rule, and error.fields maps each offending key to its messages. A refusal from the domain, such as a role code already taken or a team the caller does not own, uses the same code with error.message saying why and no fields.
On this endpoint: VALIDATION_FAILED: when a field is malformed, when an example has no input, when the rule would stop applying before it comes into force, when the authority is not a stakeholder of the project, or when the owner is not a member of the team.
425Too earlyIDEMPOTENCY_REPLAY_IN_PROGRESSapplication/json
The first request with this key is still running; retry in a few seconds and the original response is replayed.
429Too many requestsRATE_LIMITEDapplication/json
The token has spent its 300 requests a minute or 10,000 an hour; Retry-After says when the next one is accepted.
How is this guide?
Last updated on