Import Files

Imports are not entirely supported on V3. This page is a work in progress.

If you've just started using Stream, you might want to import data from your old infrastructure. Instead of using the APIs and creating your own import scripts, you can make use of our import feature.

Import files use the JSON Lines format (one JSON object per line). Each line is an envelope that wraps a single record:

{ "type": "<entity>", "data": { ... } }

Valid values for type are: user, feed, feed_group, feed_view, activity, comment, reaction, bookmark, follow, and collection. The full JSON Schemas are published at GetStream/protocol.

The Process

The steps for importing data into your app are as follows:

Install the CLI

brew tap GetStream/stream-cli https://github.com/GetStream/stream-cli
brew install stream-cli

Setup your app

stream-cli config new
stream-cli import feeds upload-import myfile.jsonl
stream-cli import feeds get-import <task-id> --watch
stream-cli import feeds list-imports

Users

Users are shared with chat and video. So if you already use those products you typically don't need to import users. The structure for importing users is shown below:

{ "type": "user", "data": { "id": "myuserid", "role": "user", "custom": {} } }

Feeds

This is how you can import feeds.

{
  "type": "feed",
  "data": {
    "group_id": "user",
    "id": "myuserid",
    "fid": "user:myuserid",
    "created_by_id": "myuserid",
    "name": "My Feed",
    "description": "A sample feed",
    "visibility": "public",
    "custom": {}
  }
}

fid is the fully-qualified feed id and is typically "{group_id}:{id}".

Follows

For follows specify the import in the following structure:

{
  "type": "follow",
  "data": {
    "source_fid": "timeline:123",
    "target_fid": "user:222",
    "push_preference": "none",
    "custom": {}
  }
}

Activities

Activities are the core records posted to one or more feeds:

{
  "type": "activity",
  "data": {
    "id": "activity-123",
    "type": "post",
    "user_id": "user-222",
    "fids": ["user:myuserid"],
    "text": "hello world",
    "visibility": "public",
    "custom": {}
  }
}

Comments

For comments specify the import in the following structure:

{
  "type": "comment",
  "data": {
    "id": "comment-1",
    "object_type": "activity",
    "object_id": "activity-123",
    "user_id": "user-222",
    "text": "buy a gaming chair",
    "mentioned_user_ids": ["user-222"],
    "parent_id": null,
    "attachments": [],
    "custom": {}
  }
}

Reactions

For reactions specify the import in the following structure:

{
  "type": "reaction",
  "data": {
    "user_id": "user-222",
    "activity_id": "activity-123",
    "type": "like",
    "custom": {}
  }
}

activity_id is required. Set comment_id as well when reacting to a comment on the activity.

Putting it all together

A single import file mixes entity types — one record per line:

{"type":"user","data":{"id":"myuserid","role":"user","custom":{}}}
{"type":"feed","data":{"group_id":"user","id":"myuserid","fid":"user:myuserid","created_by_id":"myuserid","custom":{}}}
{"type":"activity","data":{"id":"activity-123","type":"post","user_id":"myuserid","fids":["user:myuserid"],"text":"hello world"}}
{"type":"comment","data":{"id":"comment-1","object_type":"activity","object_id":"activity-123","user_id":"myuserid","text":"nice!"}}
{"type":"reaction","data":{"user_id":"myuserid","activity_id":"activity-123","type":"like"}}