Exporting Data

Exporting Channels

This method allows you to request an export of one or many channels and download all messages and metadata. Channel exports are created asynchronously, you can use the Task ID returned by the APIs to keep track of the status and to download the final result when it is ready.

The data created by the export is following the same format as the regular APIs and is JSON encoded. By default the entire history is included in the export (excluding truncated messages), but you may optionally request the export to include only the messages in a specific interval using the messages_since and messages_until parameters.

Requesting a channel export

Following code example presents basic usecase of exporting channels. By default truncated messages or soft deleted channels are excluded from export. But you can include them by setting the options include_truncated_messages and include_soft_deleted_channels as true.

since := time.Date(2020, time.November, 10, 9, 30, 0, 0, time.UTC)
until := time.Date(2020, time.November, 10, 11, 30, 0, 0, time.UTC)
opts := &ExportChannelOptions{IncludeTruncatedMessages: &includeTruncated}

expChannels := []*ExportableChannel{
	{Type: "livestream", ID: "white-room", MessagesSince: &since, MessagesUntil: &until},
}

response, err := c.ExportChannels(ctx, expChannels, opts)

taskId := response.TaskID

Up to 25 channels can be exported with a single export request.

you can use v2 version of the channel export by adding version:"v2" in the request body which will use the new export for channels where each entity of the export would be exported as line separated json.

since := time.Date(2020, time.November, 10, 9, 30, 0, 0, time.UTC)
until := time.Date(2020, time.November, 10, 11, 30, 0, 0, time.UTC)
opts := &ExportChannelOptions{Version: "v2"}

expChannels := []*ExportableChannel{
	{Type: "livestream", ID: "white-room", MessagesSince: &since, MessagesUntil: &until},
}

response, err := c.ExportChannels(ctx, expChannels, opts)

Retrieving the status of 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.

The URL to the export file has an expiration of 24-hours. The link is generated every time you request the export status. The export will be available for 60 days.

task, err := c.GetExportChannelsTask(ctx, response.TaskID)

fmt.Println(task.Status)     // the status for this task
fmt.Println(task.Result)     // the result object, only present if the task is completed
fmt.Println(task.Result["url"])  // the link to the JSON export
fmt.Println(task.Error)      // if not null the description of the task error

Timestamps will be returned in this format: “2021-02-17T08:17:49.745857Z” and are in UTC.

Exporting Users

To export user data, Stream Chat exposes an exportUser method. This method can only be called server-side due to security concerns, so please keep this in mind when attempting to make the call.

Below is an example of how to execute the call to export user data:

user, err := client.ExportUser(ctx, userID, nil)

The export will return all data about the user, including:

  • User ID

  • Messages

  • Reactions

  • Custom Data

Users with more than 10,000 messages will throw an error during the export process. Reach out to https://getstream.io/contact/support/ for an export of a user with >10,000 messages

© Getstream.io, Inc. All Rights Reserved.