# Activities

## Creating Activities

The example below shows how to create an activity and add it to a feed.

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// Add an activity to 1 feed
let activity = try await feed.addActivity(
    request: .init(
        text: "hello world",
        type: "post"
    )
)
// Add an activity to multiple feeds
let multiFeedActivity = try await client.addActivity(
    request: .init(
        fids: ["user:1", "stock:apple"],
        text: "apple stock will go up",
        type: "post"
    )
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
// Add an activity to 1 feed
const response = await feed.addActivity({
  type: "post",
  text: "apple stock will go up",
});

console.log(response.activity);

//...or multiple feeds
const response = await client.addActivity({
  fids: ["user:1", "stock:apple"],
  type: "post",
  text: "apple stock will go up",
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
// Add an activity to 1 feed or multiple feeds
const response = await client.feeds.addActivity({
  fids: ["user:1", "stock:apple"],
  type: "post",
  text: "apple stock will go up",
  // Provide user id, the owner of the activity
  user_id: "<user id>",
});

console.log(response.activity);
```

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
// Add an activity to 1 feed
feedsClient := client.Feeds()
ctx := context.Background()

activity, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
    Text: getstream.PtrTo("hello world"),
    Type: getstream.PtrTo("post"),
    Fids: []string{"user:john"},
})
if err != nil {
    log.Fatal(err)
}
log.Printf("Activity created: %+v", activity.Data)

// Add an activity to multiple feeds
multiFeedActivity, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
    Fids: []string{"user:1", "stock:apple"},
    Text: getstream.PtrTo("Apple stock will go up"),
    Type: getstream.PtrTo("post"),
})
if err != nil {
    log.Fatal(err)
}
log.Printf("Multi-feed activity: %+v", multiFeedActivity.Data)
```

</codetabs-item>

</codetabs>

The above example was quite simple. Here are a few more examples:

### Image & Video

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
let imageActivity = try await feed.addActivity(
    request: .init(
        attachments: [
            Attachment(
                imageUrl: "https://example.com/image.jpg",
                type: "image"
            )
        ],
        text: "look at NYC",
        type: "post"
    )
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
feed.addActivity({
  type: "post",
  text: "look at NYC",
  attachments: [
    {
      type: "image",
      image_url: "https://example.com/image.png",
      custom: {},
    },
  ],
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
client.feeds.addActivity({
  fids: ["user:1"],
  type: "post",
  text: "look at NYC",
  attachments: [
    {
      type: "image",
      image_url: "https://example.com/image.png",
      custom: {},
    },
  ],
  // Provide user id, the owner of the activity
  user_id: "<user id>",
});
```

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
package main

import (
    "context"
    "log"

    "github.com/GetStream/getstream-go/v3"
)

func main() {
    client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    feedsClient := client.Feeds()

    // Add activity with image attachment
    imageActivity, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
        Fids: []string{"user:1"},
        Type: getstream.PtrTo("post"),
        Text: getstream.PtrTo("look at NYC"),
        Attachments: []getstream.Attachment{
            {
                Type:     "image",
                ImageURL: getstream.PtrTo("https://example.com/image.png"),
                Custom:   map[string]interface{}{},
            },
        },
        UserID: getstream.PtrTo("<user id>"),
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Image activity created: %+v", imageActivity.Data)

    // Add activity with video attachment
    videoActivity, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
        Fids: []string{"user:1"},
        Type: getstream.PtrTo("post"),
        Text: getstream.PtrTo("Check out this video!"),
        Attachments: []getstream.Attachment{
            {
                Type:     "video",
                AssetURL: getstream.PtrTo("https://example.com/video.mp4"),
                ImageURL: getstream.PtrTo("https://example.com/thumbnail.jpg"), // Video thumbnail
                Custom: map[string]interface{}{
                    "duration": 120, // seconds
                },
            },
        },
        UserID: getstream.PtrTo("<user id>"),
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Video activity created: %+v", videoActivity.Data)
}
```

</codetabs-item>

</codetabs>

### Stories

For a story you typically want multiple attachments and an expiration set:

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
let storyActivity = try await feed.addActivity(
    request: .init(
        attachments: [
            Attachment(imageUrl: "https://example.com/image1.jpg", type: "image"),
            Attachment(assetUrl: "https://example.com/video1.mp4", type: "video")
        ],
        expiresAt: ISO8601DateFormatter().string(from: tomorrow),
        text: "My story",
        type: "story"
    )
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

feed.addActivity({
  type: "story",
  text: "My story",
  expires_at: tomorrow.toISOString(),
  attachments: [
    {
      type: "image",
      image_url: "https://example.com/image.png",
      custom: {},
    },
    {
      type: "video",
      image_url: "https://example.com/video.mp4",
      custom: {},
    },
  ],
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

client.feeds.addActivity({
  fids: ["story:1"],
  type: "story",
  text: "My story",
  expires_at: tomorrow.toISOString(),
  attachments: [
    {
      type: "image",
      image_url: "https://example.com/image.png",
      custom: {},
    },
    {
      type: "video",
      image_url: "https://example.com/video.mp4",
      custom: {},
    },
  ],
  user_id: "<user id>",
});
```

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
package main

import (
    "context"
    "log"
    "time"

    "github.com/GetStream/getstream-go/v3"
)

func main() {
    client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    feedsClient := client.Feeds()

    // Set expiration to tomorrow
    tomorrow := time.Now().Add(24 * time.Hour)

    // Create a story with multiple attachments and expiration
    storyActivity, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
        Fids:      []string{"story:1"},
        Type:      getstream.PtrTo("story"),
        Text:      getstream.PtrTo("My story"),
        ExpiresAt: getstream.PtrTo(tomorrow.Format(time.RFC3339)),
        Attachments: []getstream.Attachment{
            {
                Type:     "image",
                ImageURL: getstream.PtrTo("https://example.com/image1.jpg"),
                Custom: map[string]interface{}{
                    "filter": "valencia",
                },
            },
            {
                Type:     "video",
                AssetURL: getstream.PtrTo("https://example.com/video1.mp4"),
                ImageURL: getstream.PtrTo("https://example.com/video_thumb.jpg"),
                Custom: map[string]interface{}{
                    "duration": 15, // 15 second story
                },
            },
        },
        UserID: getstream.PtrTo("<user id>"),
        Custom: map[string]interface{}{
            "story_type": "daily",
            "location":   "New York",
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Story activity created: %+v", storyActivity.Data)
    log.Printf("Story expires at: %s", tomorrow.Format(time.RFC3339))
}
```

</codetabs-item>

</codetabs>

## Overview of All Activity Fields

Here's an overview of all the fields you can add when creating an activity:

| Field              | Description                                                                                                                                              |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`               | Either set your own id, or let our server generate it. Setting your own ID can be convenient if your activity maps 1 to 1 to something in your database. |
| `type`             | The type of activity. Defaults to "post" if not provided.                                                                                                |
| `fids`             | The list of feed IDs to add this activity to                                                                                                             |
| `text`             | The text for this activity                                                                                                                               |
| `attachments`      | A list of attachments. Video, images, location, etc. Also supports custom attachments                                                                    |
| `custom`           | Any custom data you want to add                                                                                                                          |
| `visibility`       | Visibility levels for the activity                                                                                                                       |
| `location`         | Specify an activity location. This allows for feeds to show content close to you. Format: `ActivityLocation(lat: 40.014984, lng: -105.270546)`           |
| `expiresAt`        | When the activity expires. After this timestamp it's only visible to the person who created this activity (or server side API calls)                     |
| `mentionedUserIds` | A list of users mentioned in this activity                                                                                                               |
| `parentId`         | The parent activity. Used for replies/reshares etc                                                                                                       |
| `searchData`       | Any extra data you want to search on for this activity                                                                                                   |
| `filterTags`       | Array of strings that you can filter on when querying the feed                                                                                           |
| `interestTags`     | Either set the interest tags manually or enable an activity processor to have AI determine the topics for this activity. Used for "for you" style feeds  |

## Adding Many Activities

You can also batch add activities. Here's an example:

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
let activities = [
    ActivityRequest(
        fids: ["user:123"],
        id: "1",
        text: "hi",
        type: "post"
    ),
    ActivityRequest(
        fids: ["user:456"],
        id: "2",
        text: "hi",
        type: "post"
    )
]
let upsertedActivities = try await client.upsertActivities(activities)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.upsertActivities({
  activities: [
    {
      fids: ["user:123"],
      id: "1",
      type: "post",
      text: "hi",
    },
    {
      fids: ["user:456"],
      id: "2",
      type: "post",
      text: "hi",
    },
  ],
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
client.feeds.upsertActivities({
  activities: [
    {
      fids: ["user:123"],
      id: "1",
      type: "post",
      text: "hi",
      user_id: "<user id>",
    },
    {
      fids: ["user:456"],
      id: "2",
      type: "post",
      text: "hi",
      user_id: "<user id>",
    },
  ],
});
```

</codetabs-item>

</codetabs>

## Updating & Deleting Activities

This example shows how to update or delete an activity:

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// Update an activity
let updatedActivity = try await feed.updateActivity(
    id: "123",
    request: .init(
        custom: ["custom": "custom"],
        text: "Updated text"
    )
)

// Delete an activity
let hardDelete = false // Soft delete sets deleted at but retains the data, hard delete fully removes it
try await feed.deleteActivity(id: "123", hardDelete: hardDelete)

// Batch delete activities
try await client.deleteActivities(
    request: .init(
        activityIds: ["123", "456"],
        hardDelete: false
    )
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
// Update an activity
client.updateActivity({
  activity_id: "123",
  text: "Updated text",
  custom: {
    color: "blue",
  },
});

client.deleteActivity({
  activity_id: "123",
  hard_delete: false, // Soft delete sets deleted at but retains the data, hard delete fully removes it
});

// Batch delete activities
client.deleteActivities({
  activity_ids: ["123", "456"],
  hard_delete: false,
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
// Update an activity
client.feeds.updateActivity({
  activity_id: "123",
  text: "Updated text",
  custom: {
    color: "blue",
  },
  user_id: "<user id>",
});

client.feeds.deleteActivity({
  activity_id: "123",
  hard_delete: false, // Soft delete sets deleted at but retains the data, hard delete fully removes it
  user_id: "<user id>",
});

// Batch delete activities
client.feeds.deleteActivities({
  activity_ids: ["123", "456"],
  user_id: "<user id>",
  hard_delete: false,
});
```

</codetabs-item>

</codetabs>

---

This page was last updated at 2025-08-15T14:14:09.525Z.

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