GDPR and privacy

Companies conducting business within the European Union are legally required to comply with the General Data Protection Regulation (GDPR).

While many aspects of this regulation may not significantly affect your integration with Stream, the GDPR provisions regarding the right to data access and the right to erasure are directly pertinent. These provisions relate to data that is stored and managed on Stream's servers.

Because of this, Stream provides a set of methods that make complying with those portions of the law easy. They work the same way for every Stream product.

The Right to Access Data

GDPR gives EU citizens the right to request access to their information and the right to have access to this information in a portable format. Stream covers this requirement with the Export Users method.

This method can only be used with server-side authentication.

const response = await client.exportUsers({
  user_ids: [userID],
});
const taskID = response.task_id;

The export runs asynchronously and returns a task ID. Poll the task until its status is completed to obtain a URL for downloading the exported data in line-separated JSON format. Each user's export contains their profile, messages, reactions, calls, and custom data.

Info:

A single request can export up to 25 users with a maximum of 10,000 messages per user. Contact support to export users with more than 10,000 messages.

Retrieving the export

You can check the status of an export request using the task ID returned when the task was created. The result of the task contains the URL to the JSON file. Poll the task status endpoint, or use the SDK helper that waits for completion, as described in Async operations.

Exporting feeds data

Feeds data is exported with its own endpoint. Where the user is the owner, exportFeedUserData exports:

  • User data
  • Feeds
  • Follows
  • Activities
  • Comments
  • Reactions
  • Bookmarks
  • Bookmark folders
  • Collections

This method can only be used with server-side authentication.

// Start the export task
const response = await client.feeds.exportFeedUserData({
  user_id: userToExport.id,
});

// You have to poll this endpoint
const taskResponse = await client.getTask({ id: response.task_id });
console.log(taskResponse.status === "completed");

Poll the task ID the same way as for Export Users; the task result contains the URL to the JSON file.

Info:

The URL to the export file expires after 24 hours. The link is generated every time you request the export status. The export stays available for 60 days.

The Right to Erasure

The GDPR also grants EU citizens the right to request the deletion of their personal information. Stream offers mechanisms to delete users and their data in accordance with various use cases, ensuring compliance with these regulations.

Deleting users

await client.deleteUsers({ user_ids: ["<id>"] });

//restore
await client.restoreUsers({ user_ids: ["<id>"] });

By default users and their data are soft-deleted. The delete users endpoint supports the following parameters to control which data needs to be deleted and how.

Name Type Description Optional
user Enum (soft, pruning, hard) - Soft: marks user as deleted and retains all user data.
- Pruning: marks user as deleted and nullifies user information.
- Hard: deletes user completely.

When user is hard and messages or conversations is omitted, the omitted field is automatically set to hard. Setting messages to a non-hard value, or conversations to soft, returns an error. To keep the user's conversation channels, set conversations to keep.
Yes
conversations Enum (soft, hard, keep) - Soft: marks all conversation channels as deleted (same effect as Delete Channels with 'hard' option disabled).
- Hard: deletes channel and all its data completely including messages (same effect as Delete Channels with 'hard' option enabled).
- Keep: doesn't delete conversation channels. The deleted user's memberships are removed, channels they created are transferred to new_channel_owner_id, and their messages are deleted according to messages.

A conversation channel is any channel with two or fewer members where one member is the deleted user.

When user is hard, omitting this field automatically promotes it to hard. Set it to keep to hard delete the user while keeping their conversation channels for the remaining members. Setting conversations to soft with user set to hard returns an error.
Yes
messages Enum (soft, pruning, hard) - Soft: marks all user messages as deleted without removing any related message data.
- Pruning: marks all user messages as deleted, nullifies message information and removes some message data such as reactions and flags.
- Hard: deletes messages completely with all related information.

When user is hard, omitting this field automatically promotes it to hard. Setting messages to soft or pruning with user set to hard returns an error.
Yes
new_channel_owner_id string Channels owned by hard-deleted users will be transferred to this userID. If you don't provide a value, the channel owner will have a system generated ID like delete-user-8219f6578a7395g Yes
calls Enum (soft, hard) - Soft: marks calls and related data as deleted.
- Hard: deletes calls and related data completely
Note that this applies only to 1:1 calls, not group calls
Yes
exclude_channel_cids array of strings Channel CIDs (type:id) to leave out of the deletion. In the listed channels the user's messages, reactions, membership and thread participation are kept, and the channels are not deleted as conversation channels, whatever messages and conversations are set to.

Maximum 1000 entries, duplicates included. Cannot be combined with user set to hard or with files set to true. See Excluding channels from a deletion.
Yes
Warning:

When user is set to hard, the server requires that messages is also hard and that conversations is hard or keep. If either field is omitted, it is automatically promoted to hard. Any other value (soft or pruning) returns a validation error.

Hard deleting messages also deletes other members' thread replies to the deleted user's messages, including in conversation channels kept with conversations: keep.

Deleting users is done asynchronously and can take some time to complete. A single request can delete up to 100 users. Monitor the returned task ID the same way as for exports.

After deletion, a user can no longer connect to Stream or be displayed when querying users. For the rest of the user lifecycle (deactivating, reactivating, restoring), see Users.

Excluding channels from a deletion

Use exclude_channel_cids to delete a user while leaving some channels out of the deletion, for example while a conversation is under a legal hold. In each listed channel, the user's messages, reactions, membership and thread participation are kept, and the channel is not deleted as a conversation channel, whatever messages and conversations are set to. Everything else is deleted as requested. The list applies to every user in user_ids.

The following rules apply:

  • The list accepts up to 1000 CIDs. Duplicates count toward this limit.
  • A malformed CID (anything that is not type:id) returns a 400 error.
  • A well-formed CID that doesn't match an existing channel is accepted and excludes nothing.
  • exclude_channel_cids can't be combined with user set to hard or with files set to true. Both return a 400 error.

The exclusion only covers the request that carries it:

  • Send the list on every delete users request for any member of a kept channel, not only for the first user. Deleting another member without the list removes that member's membership and thread participation in the channel, applies the messages option to their messages there, removes their reactions there when user is pruning, and deletes the channel itself when conversations is soft or hard and the channel has two members or fewer.
  • The user record itself is not channel data. The user is still marked as deleted, and with user set to pruning the user's information is nullified, so kept messages refer to a deleted user.
  • Scheduled messages belong to the user, not to a channel. With user set to pruning, the user's scheduled messages are removed in every channel, including the excluded ones.
  • The user.deleted event doesn't list the channels that were kept. If you mirror deletions from this event in your own systems, skip the excluded channels yourself.
  • Other ways of deleting data don't know about the exclusion. Deleting or truncating the channel, deleting a message, a data retention policy, and a later delete users request sent without the list all remove data from a previously excluded channel.

The first request below soft deletes the user and hard deletes their conversation channels, except for the listed channel:

curl -X POST "https://chat.stream-io-api.com/api/v2/users/delete?api_key=${API_KEY}" \
  -H "Authorization: ${TOKEN}" \
  -H "stream-auth-type: jwt" \
  -H "Content-Type: application/json" \
  -d '{
    "user_ids": ["<id>"],
    "user": "soft",
    "conversations": "hard",
    "exclude_channel_cids": ["messaging:<channel-id>"]
  }'

When the channel no longer needs to be kept, send a second request for the same user without exclude_channel_cids:

curl -X POST "https://chat.stream-io-api.com/api/v2/users/delete?api_key=${API_KEY}" \
  -H "Authorization: ${TOKEN}" \
  -H "stream-auth-type: jwt" \
  -H "Content-Type: application/json" \
  -d '{
    "user_ids": ["<id>"],
    "user": "hard",
    "messages": "hard",
    "conversations": "hard"
  }'

This hard deletes the user and everything that was kept. A kept channel that has two members or fewer at the time of the second request, such as a 1:1 channel, is a conversation channel, so the second request deletes the channel itself, including the other member's messages. In a larger channel, the second request only removes the user's own messages, reactions, membership and thread participation.

Deleting product data

Each product has its own deletion endpoints and semantics for the resources a user leaves behind:

Deleting feeds data

Use deleteFeedUserData to erase a user's feeds data without deleting the user account itself. The following data will be deleted:

  • Follows where the user owns either the source or the target feed
  • Feeds owned by the user, following the logic described in Deleting a Feed
  • Activities owned by the user
  • Comments owned by the user
  • Reactions owned by the user
  • Bookmarks and bookmark folders owned by the user
  • Collections owned by the user

The hard_delete flag only affects how feeds, activities, comments, reactions, bookmarks, bookmark folders, and collections are removed. With hard_delete: false (the default), these entities are soft-deleted: the rows stay in the database with a deleted_at timestamp set and are filtered out of reads. With hard_delete: true, the rows are physically removed.

Follows are always hard-deleted regardless of the hard_delete flag. Both follow rows where the user is the source and rows where the user is the target are physically removed; there is no soft-delete state for follows. The deleted user's activities immediately stop appearing in the feeds of users who used to follow them, and the deleted user's own following list is cleared in full.

Danger:

Deleting feeds data is an irreversible operation. This goes for both soft and hard deletes.

// Start the delete task
const response = await client.feeds.deleteFeedUserData({
  user_id: userToDelete.id,
  hard_delete: false,
});

// You have to poll this endpoint
const taskResponse = await client.getTask({ id: response.task_id });
console.log(taskResponse.status === "completed");

PDPB

The same API endpoints documented here can also be used to comply with India's Personal Data Protection Bill (PDPB) requirements.