Docs
/
/

Audiences mAPI reference

Complete reference documentation for the Audiences resource.

Audiences

#

Audiences are user segments that you can use to target users for workflows, guides, and broadcasts.

Archive an audience

#

Archives a given audience across all environments.

Endpoint

DELETE/v1/audiences/{audience_key}

Path parameters

audience_key
string

The key of the audience to archive.

Query parameters

environment
string

The environment slug.

Returns

ArchiveAudienceResponse

The response from archiving an audience.

result
string

The result of the archive operation.

Get an audience

#

Retrieve an audience by its key in a given environment.

Endpoint

GET/v1/audiences/{audience_key}

Path parameters

audience_key
string

The key of the audience to retrieve.

Query parameters

environment
string

The environment slug.

branch
string

The slug of a branch to use. This option can only be used when environment is "development".

annotate
boolean

Whether to annotate the resource. Only used in the Knock CLI.

hide_uncommitted_changes
boolean

Whether to hide uncommitted changes. When true, only committed changes will be returned. When false, both committed and uncommitted changes will be returned.

Returns

An audience defines a set of users that can be targeted for notifications. Can be either a StaticAudience (members explicitly added/removed) or a DynamicAudience (members determined by segment conditions).

Upsert an audience

#

Updates an audience of a given key, or creates a new one if it does not yet exist.

Endpoint

PUT/v1/audiences/{audience_key}

Path parameters

audience_key
string

The key of the audience to upsert.

Query parameters

environment
string

The environment slug.

branch
string

The slug of a branch to use. This option can only be used when environment is "development".

annotate
boolean

Whether to annotate the resource. Only used in the Knock CLI.

commit
boolean

Whether to commit the resource at the same time as modifying it.

commit_message
string

The message to commit the resource with, only used if commit is true.

Request body

audience
2 possible types
Required

An audience object with attributes to create or update an audience. Use type: static for audiences with explicitly managed members, or type: dynamic for audiences with segment-based membership.

Returns

WrappedAudienceResponse

Wraps the Audience response under the audience key.

audience
2 possible types

An audience defines a set of users that can be targeted for notifications. Can be either a StaticAudience (members explicitly added/removed) or a DynamicAudience (members determined by segment conditions).

Validate an audience

#

Validates an audience payload without persisting it.

Endpoint

PUT/v1/audiences/{audience_key}/validate

Path parameters

audience_key
string

The key of the audience to validate.

Query parameters

environment
string

The environment slug.

branch
string

The slug of a branch to use. This option can only be used when environment is "development".

Request body

audience
2 possible types
Required

An audience object with attributes to create or update an audience. Use type: static for audiences with explicitly managed members, or type: dynamic for audiences with segment-based membership.

Returns

WrappedAudienceResponse

Wraps the Audience response under the audience key.

audience
2 possible types

An audience defines a set of users that can be targeted for notifications. Can be either a StaticAudience (members explicitly added/removed) or a DynamicAudience (members determined by segment conditions).

List audiences

#

Returns a paginated list of audiences for the given environment.

Endpoint

GET/v1/audiences

Query parameters

environment
string

The environment slug.

branch
string

The slug of a branch to use. This option can only be used when environment is "development".

after
string

The cursor to fetch entries after.

before
string

The cursor to fetch entries before.

limit
integer

The number of entries to fetch per-page.

annotate
boolean

Whether to annotate the resource. Only used in the Knock CLI.

hide_uncommitted_changes
boolean

Whether to hide uncommitted changes. When true, only committed changes will be returned. When false, both committed and uncommitted changes will be returned.

Returns

PaginatedAudienceResponse

A paginated list of Audience. Contains a list of entries and page information.

entries

A list of entries.

page_info

The information about a paginated result.

after
string

The cursor to fetch entries after. Will only be present if there are more entries to fetch.

before
string

The cursor to fetch entries before. Will only be present if there are more entries to fetch before the current page.

page_size
integer

The number of entries to fetch per-page.

Audience

#

An audience defines a set of users that can be targeted for notifications. Can be either a StaticAudience (members explicitly added/removed) or a DynamicAudience (members determined by segment conditions).

Attributes

Audience
2 possible types

An audience defines a set of users that can be targeted for notifications. Can be either a StaticAudience (members explicitly added/removed) or a DynamicAudience (members determined by segment conditions).

DynamicAudience

#

A dynamic audience where membership is determined by segment conditions evaluated at runtime.

Attributes

created_at
string(date-time)

The timestamp of when the audience was created.

description
string

A description of the audience.

environment
string

The slug of the environment in which the audience exists.

key
string

The unique key of the audience.

name
string

The name of the audience.

segments
object[]

A list of segments that define the dynamic audience membership criteria. Each segment contains one or more conditions joined by AND. Multiple segments are joined by OR.

conditionsRequired

A list of conditions within this segment, joined by AND.

argument
string

The argument to compare against. Can be a static value (string, number, boolean) or a dynamic path expression.

operator
enum(string)
Required

The operator to use when evaluating the condition.

equal_tonot_equal_togreater_thanless_thangreater_than_or_equal_toless_than_or_equal_tocontainsnot_containscontains_allnot_contains_allis_timestamp_beforeis_timestamp_on_or_afteris_timestamp_betweenis_betweenemptynot_emptyexistsnot_existsis_timestampis_audience_memberis_not_audience_member
property
string
Required

The property to be evaluated. Properties are dynamic values using path expressions like recipient.plan or recipient.created_at.

sha
string

The SHA hash of the audience data.

type
enum(string)

The type of audience. Always dynamic for dynamic audiences.

dynamic
updated_at
string(date-time)

The timestamp of when the audience was last updated.

StaticAudience

#

A static audience where members are explicitly added or removed via the API.

Attributes

created_at
string(date-time)

The timestamp of when the audience was created.

description
string

A description of the audience.

environment
string

The slug of the environment in which the audience exists.

key
string

The unique key of the audience.

name
string

The name of the audience.

sha
string

The SHA hash of the audience data.

type
enum(string)

The type of audience. Always static for static audiences.

static
updated_at
string(date-time)

The timestamp of when the audience was last updated.

AudienceCondition

#

A condition to evaluate for audience membership.

Attributes

argument
string

The argument to compare against. Can be a static value (string, number, boolean) or a dynamic path expression.

operator
enum(string)

The operator to use when evaluating the condition.

equal_tonot_equal_togreater_thanless_thangreater_than_or_equal_toless_than_or_equal_tocontainsnot_containscontains_allnot_contains_allis_timestamp_beforeis_timestamp_on_or_afteris_timestamp_betweenis_betweenemptynot_emptyexistsnot_existsis_timestampis_audience_memberis_not_audience_member
property
string

The property to be evaluated. Properties are dynamic values using path expressions like recipient.plan or recipient.created_at.

New chat