Skip to content

Write a Policy

This guide builds two Policies: a Belgian baseline, and a Policy for one client that builds on it. It then checks what applies at a Workplace and changes a Policy safely.

Use an API key with account:read and account:write, and install curl and jq. Run the commands in order in the same shell. This example uses Belgian construction rules; choose the packages and requirements that apply to your work.

A base Policy holds shared rules. A client Policy builds on that base and adds its differences. An override changes a package rule within the limits Dockt allows. A Policy job groups requirements for a role, such as a welder.

Set the API base URL and key:

Terminal window
export DOCKT_API_BASE_URL='https://api.dockt.com'
export DOCKT_API_TOKEN='REPLACE_WITH_API_KEY'

Policies are built from catalogues:

Call Returns
GET /v1/compliance-packages Packages with their current release and rules.
GET /v1/compliance-packages/{code}/versions/{version} A release’s rules: what each accepts, whom it is about, and the overrides it allows.
GET /v1/document-types Document types a rule can accept, marked readable when Dockt reads them.
GET /v1/qualifications Qualifications that rules and jobs can require.

List the Belgian construction package’s rules and the overrides they allow:

Terminal window
package_version="$(
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
"$DOCKT_API_BASE_URL/v1/compliance-packages/social_construction_be_v1" | jq -r '.data.version'
)"
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
"$DOCKT_API_BASE_URL/v1/compliance-packages/social_construction_be_v1/versions/$package_version" \
| jq '.data.rules[] | {rule_code, title, applies_to, accepts, allowed_overrides}'

The base Policy selects the package and adds rules for every worker. Only a Policy without a base can select packages.

Terminal window
export DOCKT_BASE_POLICY_ID="$(
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policies" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: policy-belgium' \
--data '{ "name": "Belgium" }' | jq -r '.data.id'
)"
base_version_id="$(
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policies/$DOCKT_BASE_POLICY_ID/versions" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: policy-belgium-version-1' \
--data "$(jq -n --arg version "$package_version" '{
definition: {
packages: [{ code: "social_construction_be_v1", version: $version }],
rules: [{
rule_code: "vca_for_every_worker",
label: "VCA certificate",
applies_when: { kind: "always" },
expectation: { kind: "uploaded_document", document_types: ["vca"] },
enforcement: "required"
}],
recheck_interval_days: 7
}
}')" | jq -r '.data.id'
)"
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policy-versions/$base_version_id/activate" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" | jq '.data | {id, number, status}'

A new version is a draft. Activation validates it and makes it active.

The client Policy holds only what differs. Here it accepts an A1 request acknowledgement as temporary proof of social security for 60 days, and adds a welder job:

Terminal window
export DOCKT_CLIENT_POLICY_ID="$(
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policies" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: policy-belgium-client-x' \
--data "$(jq -n --arg base "$DOCKT_BASE_POLICY_ID" '{ name: "Belgium, client X", base_policy: { id: $base } }')" \
| jq -r '.data.id'
)"
client_version_id="$(
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policies/$DOCKT_CLIENT_POLICY_ID/versions" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: policy-belgium-client-x-version-1' \
--data '{
"definition": {
"overrides": [{
"target": { "source": "compliance_package", "source_id": "social_construction_be_v1", "rule_code": "social_security_coverage" },
"accept_also": [{ "kind": "uploaded_document", "document_types": ["a1_request_acknowledgement"] }],
"reason": "Client X accepts an A1 request as temporary proof."
}],
"document_validity": [{ "document_type": "a1_request_acknowledgement", "days_after_issue": 60 }],
"jobs": [{
"codes": ["welder", "WLD-01"],
"title": "Welder",
"rules": [{
"rule_code": "welder_certificate",
"label": "Welding certificate",
"applies_when": { "kind": "always" },
"expectation": { "kind": "uploaded_document", "document_types": ["technical_certificate"] },
"enforcement": "required"
}],
"proof_required": true
}]
}
}' | jq -r '.data.id'
)"
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policy-versions/$client_version_id/activate" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" | jq '.data | {id, number, status}'

An override must use an operation the package rule lists in allowed_overrides. A rule takes one override across a Policy and its base.

When a draft isn’t valid, activation returns 422 with type policy-invalid. Each issue names the failing item and why:

{
"type": "https://docs.dockt.com/errors/policy-invalid",
"title": "Policy invalid",
"status": 422,
"detail": "The Policy version cannot be activated: 1 item(s) failed validation.",
"instance": "req_example1042",
"errors": {
"issues": [
{ "path": ["document_validity", "0", "document_type"], "message": "unknown_document_type: Document type a1_request_ack is not in the catalogue." }
]
}
}

Fix the draft with PATCH /v1/policy-versions/{policyVersionId} and activate again. The draft stays a draft until activation succeeds.

Point each Workplace at the Policy that applies there:

Terminal window
export DOCKT_WORKPLACE_ID="$(
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/workplaces" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg policy "$DOCKT_CLIENT_POLICY_ID" '{
external_ref: "client-x-ghent",
name: "Client X Ghent",
country: "BE",
policy: { id: $policy }
}')" | jq -r '.data.id'
)"

To move an existing Workplace to another Policy, send PATCH /v1/workplaces/{workplaceId} with the new policy. Its open work is evaluated again.

Read the combined active rules at the Workplace:

Terminal window
curl --fail-with-body --silent --show-error \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
"$DOCKT_API_BASE_URL/v1/workplaces/$DOCKT_WORKPLACE_ID/effective-policy" | jq '.data | {
policy_versions,
rules: [.rules[] | {rule_code, source, adjustments}],
jobs: [.jobs[] | {codes, title, rules: [.rules[].rule_code]}]
}'

social_security_coverage now shows an accept_also adjustment with your reason, and welder_certificate appears under the welder job. Assignments with the role welder or WLD-01 get it.

Active versions never change. To change a Policy, copy its active version into a new draft, edit the draft, and activate it:

Terminal window
draft_id="$(
curl --fail-with-body --silent --show-error \
-X POST "$DOCKT_API_BASE_URL/v1/policies/$DOCKT_BASE_POLICY_ID/versions" \
-H "Authorization: Bearer $DOCKT_API_TOKEN" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg from "$base_version_id" '{ copy_from: { id: $from } }')" | jq -r '.data.id'
)"

PATCH /v1/policy-versions/$draft_id replaces the draft’s definition. Send the whole definition, not only the part you change.

Activating the new version retires the old one and evaluates again all open work at the Workplaces that use the Policy. For a base Policy, that includes the Workplaces of every Policy built on it. Expect a decision.created for each Assignment or Engagement whose result, requirements, findings, or input requests change.

To adopt a new package release, create a new version of the base Policy that selects it.