Management API Reference
All other concepts within the Knock notification engine are accessed through the Knock API, which you use to trigger workflows, identify users, and manage preferences.
The Knock management API provides you with a programmatic way to interact with the resources you create and manage in your Knock dashboard, including workflows, templates, layouts, translations and commits. It's separate from the Knock API and only provides access to a limited subset of resources.
You can use the Knock management API to:
- Create, update, and manage your Knock workflows and the notification templates within those workflows.
- Create, update and manage your email layouts.
- Create and manage the translations used by your notification templates.
- Create, update, and manage your partials.
- Commit and promote changes between your Knock environments.
1
https://control.knock.app/v1
Authentication
The management API authenticates with a Bearer authentication mechanism using a service token generated on your account.
Note: environment-level API keys should never be used to authenticate with the management API. To authenticate with the management API, generate a service token.
1
Authorization: Bearer knock_st_12345
Errors
Knock uses standard HTTP response codes to indicate the success or failure of your API requests.
2xx
success status codes confirm that your request worked as expected.4xx
error status codes indicate an error caused by incorrect or missing request information (e.g. providing an incorrect API key).5xx
error status codes indicate a Knock server error.
Postman
You can use our Management API Postman collection to quickly get started testing our Management API.
Workflows
To define a logical flow of your notifications, you create a workflow consisting of workflow steps. Workflow steps can be functions or channels, and can have conditional logic that determines whether to execute that step when the workflow is triggered.
You can retrieve, update, or create a workflow as well as list all workflows in a given environment. Workflows are identified by their unique workflow key.
Workflow definition
Attributes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
{ "active": false, "categories": ["marketing", "black-friday"], "conditions": { "all": [ { "variable": "recipient.role", "operator": "equal_to", "argument": "admin" } ] }, "created_at": "2022-12-16T19:07:50.027113Z", "description": "This is a dummy workflow for demo purposes.", "environment": "development", "key": "december-16-demo", "name": "december-16-demo", "sha": "f7e9d3b2a1c8e6m4k5j7h9g0i2l3n4p6q8r0t1u3v5w7x9y", "settings": { "override_preferences": true }, "steps": [ { "channel_key": "in-app-feed", "description": "Main in-app feed", "name": "In-app step", "ref": "in_app_feed_1", "template": { "action_url": "{{ vars.app_url }}", "markdown_body": "Hello **{{ recipient.name }}**" }, "type": "channel" } ], "trigger_data_json_schema": { "properties": { "name": { "type": "string" } }, "required": ["name"], "type": "object" }, "trigger_frequency": "every_trigger", "updated_at": "2023-02-08T22:15:19.846681Z", "valid": true }
WorkflowSettings definition
1 2 3
{ "override_preferences": true }
WorkflowStep definition
All workflow steps, regardless of its type, share a common set of core attributes.
Common attributes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{ "type": "delay", "ref": "delay_1", "name": "Delay step", "description": null, "conditions": { "all": [ { "variable": "recipient.role", "operator": "equal_to", "argument": "admin" } ] } }
ChannelStep definition
Contains all properties of the WorkflowStep
and additionally:
Attributes
Email template attributes
In-app template attributes
SMS template attributes
Push template attributes
Chat template attributes
Webhook template attributes
By default, a webhook step will use the request settings you configured in
your webhook channel. You can override this as you see fit on a per-step basis
in the template
field.
1 2 3 4 5 6 7 8 9 10 11 12
{ "channel_key": "email-postmark", "ref": "email_2", "template": { "html_body": "<p>Hello world!</p>", "settings": { "layout_key": "default" }, "subject": "New activity" }, "type": "channel" }
1 2 3 4 5 6 7 8 9 10 11
{ "channel_key": "in-app-feed", "description": "Some description", "name": "In-app step", "ref": "in_app_feed_1", "template": { "action_url": "{{ vars.app_url }}", "markdown_body": "Hello **{{ recipient.name }}**." }, "type": "channel" }
1 2 3 4 5 6 7 8
{ "channel_key": "twilio", "ref": "sms_1", "template": { "text_body": "Hello {{ recipient.name }}." }, "type": "channel" }
1 2 3 4 5 6 7 8 9 10 11 12
{ "channel_key": "fcm", "ref": "push_2", "template": { "settings": { "delivery_type": "content" }, "text_body": "Hi {{ actor.name }} completed an activity.", "title": "New activity" }, "type": "channel" }
1 2 3 4 5 6 7 8 9
{ "channel_key": "whatsapp", "ref": "chat_2", "template": { "summary": "A short summary of the message", "markdown_body": "Hello **{{ recipient.name }}**." }, "type": "channel" }
ChannelSettings definition
Contains all settings that are applied to a channel integration. Used to override a channel's default settings at the ChannelStep
level in a workflow.
Chat channel settings attributes
Email channel settings attributes
In-app feed channel settings attributes
SMS channel settings attributes
1 2 3
{ "link_tracking": true }
1 2 3 4 5 6 7 8 9 10
{ "from_address": "noreply@example.com", "from_name": "Acme", "reply_to_address": "support@example.com", "cc_address": "cc@example.com", "bcc_address": "bcc@example.com", "link_tracking": true, "open_tracking": true, "json_overrides": "{\"custom\": \"value\"}" }
1 2 3
{ "link_tracking": true }
1 2 3
{ "link_tracking": true }
SendWindow definition
Attributes
1 2 3 4 5 6
{ "day": "monday", "type": "send", "from": "09:00:00", "until": "17:00:00" }
1 2 3 4 5
{ "day": "tuesday", "type": "send", "from": "10:15:00" }
1 2 3 4
{ "day": "saturday", "type": "do_not_send" }
Delay step definition
Contains all properties of the WorkflowStep
and additionally:
Attributes
Must set either settings.delay_for
or settings.delay_until_field_path
.
1 2 3 4 5 6 7 8 9 10
{ "ref": "delay_1", "settings": { "delay_for": { "unit": "seconds", "value": 30 } }, "type": "delay" }
Batch step definition
Contains all properties of the WorkflowStep
and additionally:
Attributes
Must set either settings.batch_window
or settings.batch_until_field_path
.
1 2 3 4 5 6 7 8 9 10 11
{ "ref": "batch_1", "settings": { "batch_order": "asc", "batch_window": { "unit": "seconds", "value": 30 } }, "type": "batch" }
Branch step definition
Contains all properties of the WorkflowStep
, but cannot have conditions
and additionally:
Attributes
WorkflowBranch definition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
{ "ref": "branch_1", "branches": [ { "name": "Pro plan", "terminates": false, "steps": [], "conditions": { "all": [ { "variable": "recipient.role", "operator": "equal_to", "argument": "admin" } ] } }, { "name": "Default", "terminates": false, "steps": [], "conditions": null } ], "type": "branch" }
Fetch step definition
Contains all properties of the WorkflowStep
and additionally:
Attributes
1 2 3 4 5 6 7 8 9
{ "ref": "http_fetch_1", "settings": { "headers": [{ "key": "foo", "value": "bar" }], "method": "get", "url": "https://example.com/" }, "type": "http_fetch" }
List all workflows
Returns a paginated list of workflows available in a given environment. The workflows are returned in alpha sorted order by its key.
Endpoint
Query parameters
Returns
A paginated list of workflows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
{ "entries": [ { "active": false, "created_at": "2022-11-07T21:45:43.086960Z", "environment": "development", "key": "sample-workflow-1", "name": "My first sample workflow", "steps": [ { "channel_key": "sendgrid", "ref": "email_1", "template": { "html_body": "<p>Hello world!</p>", "settings": { "layout_key": "default" }, "subject": "Hello world" }, "type": "channel" } ], "updated_at": "2022-12-20T00:31:24.189381Z", "valid": true } ], "page_info": { "after": null, "before": null, "page_size": 50 } }
Get a workflow
Retrieve a workflow by its key and namespace, in a given environment.
Endpoint
Path parameters
Query parameters
Returns
A complete workflow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
{ "active": false, "created_at": "2023-02-02T02:52:36.054397Z", "environment": "development", "key": "sample-workflow-1", "name": "My first sample workflow", "steps": [ { "channel_key": "sendgrid", "ref": "email_1", "template": { "html_body": "<p>Hello world!</p>", "settings": { "layout_key": "default" }, "subject": "New activity" }, "type": "channel" } ], "updated_at": "2023-02-06T17:58:51.331103Z", "valid": true }
Upsert a workflow
Updates a workflow of a given key, or creates a new one if it does not yet exist.
Note: this endpoint only operates on workflows in the development
environment.
Endpoint
Path parameters
Query parameters
Body parameters
Returns
An upserted workflow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
// Success { "workflow": { "active": false, "created_at": "2023-02-02T02:52:36.054397Z", "environment": "development", "key": "sample-workflow-1", "name": "My first sample workflow", "steps": [ { "channel_key": "sendgrid", "ref": "email_1", "template": { "html_body": "<p>Hello world!</p>", "settings": { "layout_key": "default" }, "subject": "New activity" }, "type": "channel" } ], "updated_at": "2023-02-06T17:58:51.331103Z", "valid": true } } // Failure { "errors": [ { "field": "name", "message": "must be a string" } ] }
Run a workflow
Runs the latest version of a saved workflow.
Endpoint
Rate limitTier 2
Path parameters
Body parameters
Returns
A workflow run ID
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Success { "workflow_run_id": "aa6f6fb8-d8a7-45d2-aa2a-d593764adc92" } // Failure { "errors": [ { "field": "recipients", "message": "is invalid", "type": "cast" } ], }
Validate a workflow
Validates a workflow payload without persisting it.
Note: Validating a workflow is only done in the development environment context.
Endpoint
Path parameters
Body parameters
Returns
A validated workflow object, if valid. Note: some read-only fields will be empty as they are generated by the system when persisted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
// Valid { "workflow": { "active": null, "created_at": null, "environment": "development", "key": "sample-workflow-1", "name": "My first sample workflow", "steps": [ { "channel_key": "sendgrid", "ref": "email_1", "template": { "html_body": "<p>Hello world!</p>", "settings": { "layout_key": "default" }, "subject": "New activity" }, "type": "channel" } ], "updated_at": null, "valid": null } } // Invalid { "errors": [ { "field": "name", "message": "must be a string" } ] }
Activate a workflow
Activates (or deactivates) a workflow in a given environment.
Note: This immediately enables or disables a workflow in a given environment without needing to go through environment promotion.
Endpoint
Path parameters
Body parameters
Returns
workflow
A workflow object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// Valid { "workflow": { "active": true, "created_at": "2023-02-02T02:52:36.054397Z", "environment": "development", "key": "sample-workflow-1", "name": "My first sample workflow", "steps": [ { "channel_key": "sendgrid", "ref": "email_1", "template": { "html_body": "<p>Hello world!</p>", "settings": { "layout_key": "default" }, "subject": "New activity" }, "type": "channel" } ], "updated_at": "2023-02-06T17:58:51.331103Z", "valid": true } }
Preview a workflow template
Generates a rendered template for a given channel step in a workflow.
Endpoint
Path parameters
Body parameters
Returns
A rendered template or a template error.
1 2 3 4 5 6 7
{ "environment": "development", "recipient": "user-id", "data": { "name": "John Doe" } }
1 2 3 4 5 6 7
{ "channel_type": "email", "result": "success", "template": { // ... see below } }
1 2 3 4 5 6 7
{ "channel_type": "email", "result": "error", "error": { // details about the error } }
Email layouts
Email layouts wrap email message templates to share consistent design components between the email notifications that your recipients receive.
You can retrieve, update, and create email layouts as well as listing all in a given environment. Email layouts are identified by their unique key.
EmailLayout definition
Attributes
EmailLayoutFooterLink Attributes
1 2 3 4 5 6 7
{ "key": "default", "name": "Default", "html_content": "<html>{{ content }}</html>", "text_content": "{{ content }}", "footer_links": [{ "text": "My link", "url": "https://example.com" }] }
List all email layouts
Returns a paginated list of email layouts available in a given environment.
Endpoint
Query parameters
Returns
A paginated list of email layouts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
{ "entries": [ { "key": "default", "name": "Default", "html_content": "<html>{{ content }}</html>", "text_content": "{{ content }}", "footer_links": [{ "text": "My link", "url": "https://example.com" }] } ], "page_info": { "after": null, "before": null, "page_size": 50 } }
Get an email layout
Retrieve an email layout by its key, in a given environment.
Endpoint
Path parameters
Query parameters
Returns
An email layout object
1 2 3 4 5 6 7
{ "key": "default", "name": "Default", "html_content": "<html>{{ content }}</html>", "text_content": "{{ content }}", "footer_links": [{ "text": "My link", "url": "https://example.com" }] }
Upsert an email layout
Updates an email layout, or creates a new one if it does not yet exist.
Note: this endpoint only operates in the “development” environment.
Endpoint
Path parameters
Query parameters
Body parameters
Returns
An email layout.
1 2 3 4 5 6 7
{ "key": "default", "name": "Default", "html_content": "<html>{{ content }}</html>", "text_content": "{{ content }}", "footer_links": [{ "text": "My link", "url": "https://example.com" }] }
Validate an email layout
Validates an email layout payload without persisting it.
Note: this endpoint only operates in the “development” environment.
Endpoint
Path parameters
Body parameters
Returns
An email layout
1 2 3 4 5 6 7
{ "key": "default", "name": "Default", "html_content": "<html>{{ content }}</html>", "text_content": "{{ content }}", "footer_links": [{ "text": "My link", "url": "https://example.com" }] }
Translations
Translations support localization in Knock. They hold the translated content for a given locale, which you can reference in your message templates with the t
Liquid function filter.
You can retrieve, update, and create translations as well as list all translations in a given environment. Translations are identified by their locale code + an optional namespace.
Translation definition
Attributes
1 2 3 4 5 6 7 8
{ "content": "{\"welcome\":\"Hello, {{ name }}\"}", "created_at": "2023-05-08T02:10:29.880485Z", "environment": "development", "format": "json", "locale_code": "en-CA", "updated_at": "2023-05-08T02:10:29.880961Z" }
List all translations
Returns a paginated list of translations available in a given environment. The translations are returned in alpha-sorted order by locale code.
Endpoint
Query parameters
Returns
A paginated list of translations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{ "entries": [ { "content": "{\"welcome\":\"Hello, {{ name }}\"}", "created_at": "2023-05-08T02:10:29.880485Z", "environment": "development", "format": "json", "locale_code": "en-CA", "updated_at": "2023-05-08T02:10:29.880961Z" } ], "page_info": { "after": null, "before": null, "page_size": 50 } }
Get a translation
Retrieve a translation by its locale and namespace, in a given environment.
Endpoint
Path parameters
Query parameters
Returns
A translation object
1 2 3 4 5 6 7 8
{ "content": "{\"welcome\":\"Hello, {{ name }}\"}", "created_at": "2023-05-08T02:10:29.880485Z", "environment": "development", "format": "json", "locale_code": "en-CA", "updated_at": "2023-05-08T02:10:29.880961Z" }
Upsert a translation
Updates a translation of a given locale code + namespace, or creates a new one if it does not yet exist.
Note: this endpoint only operates on translations in the “development” environment.
Endpoint
Path parameters
Query parameters
Body parameters
Returns
A translation object
1 2 3 4 5 6 7 8
{ "content": "{\"welcome\":\"Hello, {{ name }}\"}", "created_at": "2023-05-08T02:10:29.880485Z", "environment": "development", "locale_code": "en-CA", "format": "json", "updated_at": "2023-05-08T02:10:29.880961Z" }
Validate a translation
Validates a translation payload without persisting it.
Note: this endpoint only operates on translations in the “development” environment.
Endpoint
Path parameters
Body parameters
Returns
A translation object
1 2 3 4 5 6 7 8
{ "content": "{\"welcome\":\"Hello, {{ name }}\"}", "created_at": "2023-05-08T02:10:29.880485Z", "environment": "development", "locale_code": "en-CA", "format": "json", "updated_at": "2023-05-08T02:10:29.880961Z" }
Partials
Partials are reusable pieces of content you can use across your channel templates.
You can retrieve, update, and create partials as well as list all partials in a given environment. Partials are identified by their unique partial key.
Partial definition
Attributes
1 2 3 4 5 6 7 8 9 10 11 12 13
{ "key": "cta", "type": "html", "name": "Call to action", "description": "Call to action", "visual_block_enabled": false, "environment": "development", "icon_name": "BellDot", "content": "<div>{{heading}}<button>{{cta}}</button></div>", "created_at": "2022-12-31T12:00:00.000000Z", "updated_at": "2022-12-31T12:00:00.000000Z", "valid": false }
List all partials
Returns a paginated list of partials available in a given environment. The partials are returned in alpha-sorted order by key.
Endpoint
Query parameters
Returns
A paginated list of partials
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
{ "entries": [ { "key": "cta", "type": "html", "name": "Call to action", "description": "Call to action", "visual_block_enabled": false, "environment": "development", "icon_name": "BellDot", "content": "<div>{{heading}}<button>{{cta}}</button></div>", "created_at": "2022-12-31T12:00:00.000000Z", "updated_at": "2022-12-31T12:00:00.000000Z", "valid": false } ], "page_info": { "after": null, "before": null, "page_size": 50 } }
Get a partial
Retrieve a partial by its locale and namespace, in a given environment.
Endpoint
Path parameters
Query parameters
Returns
A partial object
1 2 3 4 5 6 7 8 9 10 11 12 13
{ "key": "cta", "type": "html", "name": "Call to action", "description": "Call to action", "visual_block_enabled": false, "environment": "development", "icon_name": "BellDot", "content": "<div>{{heading}}<button>{{cta}}</button></div>", "created_at": "2022-12-31T12:00:00.000000Z", "updated_at": "2022-12-31T12:00:00.000000Z", "valid": false }
Upsert a partial
Updates a partial of a given key, or creates a new one if it does not yet exist.
Note: this endpoint only operates on partials in the “development” environment.
Endpoint
Path parameters
Query parameters
Body parameters
Returns
A partial object
1 2 3 4 5 6 7 8 9 10 11 12 13
{ "key": "cta", "type": "html", "name": "Call to action", "description": "Call to action", "visual_block_enabled": false, "environment": "development", "icon_name": "BellDot", "content": "<div>{{heading}}<button>{{cta}}</button></div>", "created_at": "2022-12-31T12:00:00.000000Z", "updated_at": "2022-12-31T12:00:00.000000Z", "valid": false }
Validate a partial
Validates a partial payload without persisting it.
Note: this endpoint only operates on partials in the “development” environment.
Endpoint
Path parameters
Body parameters
Returns
A partial object
1 2 3 4 5 6 7 8 9 10 11 12 13
{ "key": "cta", "type": "html", "name": "Call to action", "description": "Call to action", "visual_block_enabled": false, "environment": "development", "icon_name": "BellDot", "content": "<div>{{heading}}<button>{{cta}}</button></div>", "created_at": "2022-12-31T12:00:00.000000Z", "updated_at": "2022-12-31T12:00:00.000000Z", "valid": false }
Commits
To version the changes you make in your environments, Knock uses a commit model. When you make changes to a workflow, a layout, or a translation, you will need to commit them in your development environment, then promote to subsequent environments before those changes will appear in the respective environments.
You can retrieve all commits in a given environment, or show the details of one single commit based on the target commit id.
Commit definition
Attributes
CommitResource attributes
CommitAuthor attributes
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "id": "ce3e5457-34f2-4f53-94a2-2f316528d83f", "resource": { "identifier": "default", "type": "email_layout" }, "author": { "email": "John@gmail.com", "name": "John Doe" }, "commit_message": "Initial email layout", "environment": "development", "created_at": "2023-09-22T18:57:21.704602Z" }
List all commits
Returns a paginated list of commits in a given environment. The commits are ordered from most recent first.
Endpoint
Query parameters
Returns
A paginated list of commits
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
{ "entries": [ { "id": "ce3e5457-34f2-4f53-94a2-2f316528d83f", "resource": { "identifier": "default", "type": "email_layout" }, "author": { "email": "John@gmail.com", "name": "John Doe" }, "commit_message": "Initial email layout", "environment": "development", "created_at": "2023-09-22T18:57:21.704602Z" }, { "id": "e4a22631-e05e-4d40-b323-4dc327c0670e", "resource": { "identifier": "new-comment", "type": "workflow" }, "author": { "email": "franklin@gmail.com", "name": "Franklin Sierra" }, "environment": "development", "created_at": "2023-11-13T19:28:25.090196Z" } ], "page_info": { "after": null, "before": null, "page_size": 50 } }
Get commit
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "id": "ce3e5457-34f2-4f53-94a2-2f316528d83f", "resource": { "identifier": "default", "type": "email_layout" }, "author": { "email": "John@gmail.com", "name": "John Doe" }, "commit_message": "Initial email layout", "environment": "development", "created_at": "2023-09-22T18:57:21.704602Z" }
Commit all changes
Promote all changes
Promote all changes across all resources to the target environment from its preceding environment.
Endpoint
Query parameters
A slug of the target environment to which you want to promote all changes from its directly preceding environment.
For example, if you have three environments “development”, “staging”, and “production” (in that order), setting this param to “production” will promote all new changes from the staging environment.
Note: This must be a non-development environment.
Returns
result
A "success" message.
1 2 3
{ "result": "success" }
Promote one change
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "commit": { "id": "e4a22631-e05e-4d40-b323-4dc327c0670e", "resource": { "identifier": "new-comment", "type": "workflow" }, "author": { "email": "franklin@gmail.com", "name": "Franklin Sierra" }, "environment": "staging" } }