API reference

The complete API reference for the Knock Kotlin SDK.

In this section, you'll find the documentation for the classes and methods available in the Kotlin SDK.

Knock

The top-level Knock class. Create an authenticated Knock client instance for interacting with Knock.

Params

publishableKeyString*The public API key for the Knock environment.
userIdString*The user ID to make requests against.
userTokenString (optional)A JWT that identifies the authenticated user, signed with the private key provided in the Knock dashboard. Required to secure your production environment. Learn more.
hostnameString (optional)Optional hostname to configure which Knock endpoint to make requests against.

Example


getUser

Returns the current user's profile stored in Knock.

Returns

Result<User>


updateUser

Updates the current user's profile in Knock.

Params

userUserProperties to update on the current user

Returns

Result<User>


getAllUserPreferences

Returns all of the preference sets for the current user.

Returns

Result<List<PreferenceSet>>


getUserPreferences

Returns a single preference set for the current user, specified by the preferenceId. For the default preference set, set the preferenceId to be default.

Params

preferenceIdStringThe ID of the preference set to retrieve

Returns

Result<PreferenceSet>


setUserPreferences

Updates the preference set specified by the preferenceId with the new preferenceSet.

Params

preferenceIdStringThe ID of the preference set
preferenceSetPreferenceSetThe preferences to update for the preference set

Returns

Result<PreferenceSet>


getUserChannelData

Returns the channel data for the current user on the channel specified with channelId.

Params

channelIdStringThe channel ID to get channel data for

Returns

Result<ChannelData>


updateUserChannelData

Updates the channel data for the current user on the channel specified with channelId.

Params

channelIdStringThe channel ID to update the channel data for
dataAnyThe data to update for the channel data

Returns

Result<ChannelData>


registerTokenForFCM

A convenience method for getting and setting channel data for a FCM channel for the current user.

Params

channelIdStringThe channel ID to update the channel data for
tokenStringThe device token to set

Returns

Result<ChannelData>


getMessage

Returns information about a single message specified by the messageId.

Params

messageIdStringThe ID of the message to retrieve

Returns

Result<KnockMessage>


updateMessageStatus

Updates the status of a single message specified by the message or messageId.

Params

messageIdStringThe ID of the message to update
messageKnockMessageA Knock message to update
statusKnockMessageStatusUpdateTypeThe status to set on the message

Returns

Result<KnockMessage>


deleteMessageStatus

Removes the update of a single message status specified by the message or messageId.

Params

messageIdStringThe ID of the message to update
messageKnockMessageA Knock message to update
statusKnockMessageStatusUpdateTypeThe status to set on the message

Returns

Result<KnockMessage>


batchUpdateStatuses

Updates up to 50 messages with the given status in a single request specified by messageIds.

Params

messageIdsList<String>A list of message IDs
statusKnockMessageStatusBatchUpdateTypeThe status to set on the messages

Returns

Result<List<KnockMessage>>