# Batch Methods

## Batch Add Activities

Multiple activities can be added with a single batch operation. This is very convenient when importing data to Stream.

```js label="JavaScript"
const activities = [
  { actor: "User:1", verb: "tweet", object: "Tweet:1" },
  { actor: "User:2", verb: "watch", object: "Movie:1" },
];

const addActivities = await user1.addActivities(activities);
```

### Parameters

| name       | type | description                                                                                                               | default | optional |
| ---------- | ---- | ------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
| activities | list | The list of activities to be added (as specified in [Adding Activities](https://getstream.io/activity-feeds/docs/node/v2/adding-activities/)) | -       | ✓        |

### Activity IDs

The API will return a response with a list containing the activity ids.

<Admonition type="info">

If you are importing your data for the first time, we suggest you create the follow-relationships after the activity import.

</Admonition>

## Batch Activity Add

This method allows you to add a single activity to multiple feeds with one API request.

<Admonition type="info">

Batch Activity Add has a limit of 5000 target feeds. Requests that exceed this limit will return an error.

</Admonition>

<Admonition type="info">

`TO` field [targeting](https://getstream.io/activity-feeds/docs/node/v2/targeting/) is not permitted via this endpoint. Attempting to add activities with a 'to' property will result in an error response.

</Admonition>

```js label="JavaScript"
const feeds = ["timeline:1", "timeline:2", "timeline:3", "timeline:4"];
const activity = {
  actor: "User:2",
  verb: "pin",
  object: "Place:42",
  target: "Board:1",
};
const response = await client.addToMany(activity, feeds);
```

### Parameters

| name     | type   | description                                           |
| -------- | ------ | ----------------------------------------------------- |
| feeds    | list   | The list of a feeds e.g. ['user:1', 'timeline:2']     |
| activity | object | The activity object (see Feed endpoint for reference) |

<Admonition type="info">

Activities added using this method are not propagated to followers. That is, any other Feeds that follow the Feed(s) listed in the API call will not receive the new Activity.

</Admonition>

<Admonition type="info">

Even if real-time is enabled, for this endpoint it is disabled by default since it's mainly for backend processing which shouldn't create noise for users. If you want to enable it, please send a request to support with your app id.

</Admonition>

## Batch get Activities by ID

Activities can be retrieved by IDs or foreign ID and time.

<Tabs>

```js label="JavaScript"
// retrieve two activities by ID
const response = await client.getActivities({
  ids: [
    "01b3c1dd-e7ab-4649-b5b3-b4371d8f7045",
    "ed2837a6-0a3b-4679-adc1-778a1704852d",
  ],
});

// retrieve two activities by their foreign ID and time
const response = await client.getActivities({
  foreignIDTimes: [
    { foreignID: "like:1", time: "2018-07-08T14:09:36.000000" },
    { foreignID: "post:2", time: "2018-07-09T20:30:40.000000" },
  ],
});

const response = await client.getActivities({
  ids: ["1febf8dd-cbbb-11ec-9717-025b47ecba9d"],
  reactions: { recent: true, counts: true, own: true, kind: true },
});
```

```js label="Node.js"
const response = await client.getActivities({
  ids: ["1febf8dd-cbbb-11ec-9717-025b47ecba9d"],
  reactions: { recent: true, counts: true, own: true, kind: true },
  user_id: "luis",
});
```

</Tabs>

<Admonition type="info">

Combining ID and foreign ID + time parameters is not allowed.

</Admonition>

### Parameters

| name             | type    | description                                                        | default | optional |
| ---------------- | ------- | ------------------------------------------------------------------ | ------- | -------- |
| ids              | string  | The comma-separated list of activity IDs to retrieve               | -       | ✓        |
| foreign_id_times | list    | The list of foreign_id and time values used to retrieve activities | -       | ✓        |
| reactions.own    | boolean | Include reactions added by current user to all activities          | -       | ✓        |
| reactions.recent | boolean | Include recent reactions to activities                             | -       | ✓        |
| reaction.counts  | boolean | Include reaction counts to activities                              | -       | ✓        |

<Admonition type="info">

The number of activities that can be retrieved with a single request is limited to 100.

</Admonition>

<Admonition type="info">

When using this endpoint server side you must include the `user_id` parameter for the own reactions to properly populated.

</Admonition>

## Batch Follow

Stream's Follow Many functionality gives you a fast method to follow many feeds in one go. This is convenient when importing data or on-boarding new users.

Follow Many has a limit of 2,500 follows per request.

<Admonition type="info">

Follow Many has a total request size limit of 128kb, in case you reach it we recommended to split the request in 2.

</Admonition>

`activity_copy_limit` can be specified to copy specific number of activities. By default, it's 100 such that upon follow 100 activities from the followed feed will be seen in our feed.

```js label="JavaScript"
// Batch following many feeds
// Let timeline:1 will follow user:1, user:2 and user:3

const follows = [
  { source: "timeline:1", target: "user:1" },
  { source: "timeline:1", target: "user:2" },
  { source: "timeline:1", target: "user:3", activity_copy_limit: 0 },
];

await client.followMany(follows);
```

<Admonition type="info">

This method can only be used server-side.

</Admonition>

<Admonition type="warning">

Note that the follow relationships will be processed in the background asynchronously so they wont show up immediately.

</Admonition>

Parameters

<Admonition type="warning">

The Batch Follow API does not return response data.

</Admonition>

## Batch Unfollow

Unfollow Many enables you to unfollow many feeds in bulk. However, its implementation is heavy. That's why its usage restricted to Enterprise accounts. While unfollowing, history can be kept by `keep_history.` It's false by default. When unfollow is done, any activities that come from unfollowed feed will be removed but if the flag is set, then this history will remain.

Unfollow Many has a limit of 250 unfollows per request.

```js label="JavaScript"
// Batch unfollowing many feeds
// Let timeline:1 will follow user:1, user:2 and user:3

const unfollows = [
  { source: "timeline:1", target: "user:1" },
  { source: "timeline:1", target: "user:2" },
  { source: "timeline:1", target: "user:3", keep_history: true },
];

await client.unfollowMany(unfollows);
```

<Admonition type="warning">

The Batch Unfollow API does not return response data. An error is returned on wrong input.

</Admonition>

## Batch update TO targets

Allows you to update the TO targets of multiple activities in a feed at once, up to a max of 100 activities per call.

```go label="Go"
feed, err := client.FlatFeed("user", "1")
if err != nil {
	panic(err)
}

reqs := []stream.UpdateToTargetsRequest{
	{
		ForeignID: "foreignID-0",
		Time:   stream.Time{},
		Opts: []stream.UpdateToTargetsOption{
			stream.WithToTargetsAdd("foo:bar", "baz:qux"),
		},
	},
	{
		ForeignID: "foreignID-1",
		Time:   stream.Time{},
		Opts: []stream.UpdateToTargetsOption{
			stream.WithToTargetsAdd("foo:bar", "baz:qux"),
			stream.WithToTargetsRemove("abc:123"),
		},
	},
}

resp, err := feed.BatchUpdateToTargets(context.Background(), reqs)
if err != nil {
	panic(err)
}
```

<Admonition type="info">

Currently only available in the Go and .NET SDKs, if you need support for your SDK please contact support.

</Admonition>


---

This page was last updated at 2026-08-07T20:37:31.571Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/node/v2/add-many-activities/](https://getstream.io/activity-feeds/docs/node/v2/add-many-activities/).