> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Edit Posts

> Update existing posts with the public SDK edit APIs and platform-specific editor surfaces.

Use post editing when your app needs to update content that already exists. The SDKs update the post by ID; permission checks are enforced by the backend for post owners, moderators, and admins according to your app configuration.

## Platform Support

| Platform   | Public edit surface                               | Notes                                                                                                                                      |
| ---------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| TypeScript | `PostRepository.editPost(postId, patch)`          | Patch can include `data`, `metadata`, `tags`, `mentionees`, `hashtags`, `attachments`, `links`, `productTags`, and `attachmentProductTags` |
| iOS        | `postRepository.editPost(withId:builder:...)`     | Use the builder type that matches the original post content type                                                                           |
| Android    | `postRepository.editPost(postId).build().apply()` | Builder supports text, title, attachments, metadata, mentions, hashtags, tags, links, product tags, and tagged attachment products         |
| Flutter    | `post.edit().build().update()`                    | Editor is available on an `AmityPost`; it supports text, image, file, video, custom data, metadata, and mentioned users                    |

<Info>
  The current Flutter public editor does not expose link preview replacement or product-tag editing. Keep those updates on platforms that expose the fields.
</Info>

## Parameters

| Operation     | Parameter                           | Required | Description                                                               |
| ------------- | ----------------------------------- | -------- | ------------------------------------------------------------------------- |
| Update a post | `postId`                            | Yes      | Post ID to update. Flutter updates through a loaded `AmityPost` object.   |
| Update a post | Text/data patch                     | Usually  | Updated text or post data supported by the original post type.            |
| Update a post | Attachments/media                   | No       | Complete attachment set to keep where the SDK exposes attachment editing. |
| Update a post | `metadata`, `tags`, mentions, links | No       | Optional fields exposed by the target SDK edit surface.                   |

## Update a Post

Load or know the post ID, then apply the platform-specific editor or patch API for the fields your product allows users to change.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { PostRepository } from "@amityco/ts-sdk";

  const { data: updatedPost } = await PostRepository.editPost(postId, {
    data: {
      text: "Updated caption with https://www.amity.co",
    },
    attachments: [
      {
        type: "image",
        fileId: imageFileId,
      },
    ],
    metadata: {
      editedFrom: "profile",
    },
    tags: ["release-note"],
    links: [
      {
        url: "https://www.amity.co",
        index: 21,
        length: 20,
        renderPreview: true,
        domain: "www.amity.co",
      },
    ],
  });

  renderResults(updatedPost);
  ```

  ```swift iOS theme={null}
  let builder = AmityTextPostBuilder()
  builder.setText("Updated caption")

  let updatedPost = try await postRepository.editPost(
      withId: "post-id",
      builder: builder,
      metadata: ["editedFrom": "profile"],
      mentionees: nil,
      hashtags: nil,
      links: nil,
      productTags: nil,
      attachmentProductTags: nil
  )

  showSuccessMessage(updatedPost.postId)
  ```

  ```kotlin Android theme={null}
  val metadata = JsonObject().apply {
      addProperty("editedFrom", "profile")
  }

  postRepository.editPost(postId = postId)
      .text(text = "Updated caption")
      .metadata(metadata)
      .tags(listOf("release-note"))
      .build()
      .apply()
      .subscribe(
          { showSuccessMessage(postId) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final post = await AmitySocialClient.newPostRepository().getPost(postId);

  await post
      .edit()
      .text('Updated caption')
      .metadata({'editedFrom': 'profile'})
      .build()
      .update();
  ```
</CodeGroup>

## Editing Media

On platforms with attachment editing, send the complete attachment set you want the post to keep. If you omit an existing image, file, or video from the update payload, that attachment should be treated as removed from the edited post.

| Platform   | Media edit pattern                                                                                                                    |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| TypeScript | Send `attachments` with `{ type, fileId }` entries                                                                                    |
| iOS        | Rebuild the post with the matching media builder, such as `AmityImagePostBuilder`, `AmityFilePostBuilder`, or `AmityVideoPostBuilder` |
| Android    | Pass media objects through `.attachments(...)` on the edit builder                                                                    |
| Flutter    | Use `.image(...)`, `.file(...)`, or `.video(...)` on the loaded post editor                                                           |

## Notes

* Keep the edit operation tied to the content type that was originally created.
* Preserve existing attachments by reading the current post first and including the items that should remain.
* After a successful edit, use the returned or live-updated post to refresh UI state such as edited timestamps, tags, metadata, and attachment lists.

## Related Topics

<CardGroup cols={3}>
  <Card title="Get Posts" icon="newspaper" href="../retrieval/get-post">
    Load the current post before editing.
  </Card>

  <Card title="Delete Posts" icon="trash" href="./delete-post">
    Remove posts through soft or hard deletion.
  </Card>

  <Card title="Viewing Content" icon="eye" href="../retrieval/viewing-content">
    Render the updated post content.
  </Card>
</CardGroup>
