> ## 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.

# Custom Posts

> Create custom post types with application-defined structured data.

Custom posts let your app publish structured content that it renders itself, such as product cards, event cards, listings, or other domain-specific content.

Use a stable, application-owned data type such as `post.product` or `event.session`. Avoid built-in post data types such as `text`, `image`, `video`, `file`, `poll`, and `liveStream`.

<CardGroup cols={2}>
  <Card title="Structured Data" icon="database">
    Store an application-defined JSON payload in the post data.
  </Card>

  <Card title="Custom Rendering" icon="paintbrush">
    Render custom post types with your own UI in feeds and detail screens.
  </Card>
</CardGroup>

## Parameters

| Parameter                      | Required | Description                                                                               |
| ------------------------------ | -------- | ----------------------------------------------------------------------------------------- |
| `dataType` or `customDataType` | Yes      | Stable application-owned type string that identifies how your app should render the post. |
| `data`                         | Yes      | JSON-style payload for the custom post. Keep this schema owned by your application.       |
| `targetType`                   | Yes      | Feed target, usually `community` or `user`.                                               |
| `targetId`                     | Yes      | Community ID or user ID for the target feed.                                              |
| `metadata`                     | No       | Auxiliary custom metadata that should not define the post type.                           |
| `mentionees`                   | No       | User mention payload where supported by the platform builder.                             |

## Create a Custom Post

The examples below create a custom product-style post in a community. Replace the data type and payload with your app's schema.

<CodeGroup>
  ```swift iOS theme={null}
  let postRepository = AmityPostRepository()
  let builder = AmityCustomPostBuilder()
  builder.setDataType("post.product")
  builder.setData([
      "title": "Wireless headphones",
      "price": 149.99,
      "currency": "USD"
  ])

  let post = try await postRepository.createCustomPost(
      builder,
      targetId: communityId,
      targetType: .community,
      metadata: nil,
      mentionees: nil
  )
  ```

  ```kotlin Android theme={null}
  val data = JsonObject().apply {
      addProperty("title", "Wireless headphones")
      addProperty("price", 149.99)
      addProperty("currency", "USD")
  }

  postRepository.createCustomPost(
      targetType = AmityPost.TargetType.COMMUNITY,
      targetId = communityId,
      customDataType = "post.product",
      data = data
  )
      .subscribe({ post ->
          showSuccessMessage(post.getPostId())
      }, { error ->
          handleGeneralError(error)
      })
  ```

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

  const { data: post } = await PostRepository.createPost({
    targetType: "community",
    targetId: communityId,
    dataType: "post.product",
    data: {
      title: "Wireless headphones",
      price: 149.99,
      currency: "USD",
    },
  });
  ```

  ```dart Flutter theme={null}
  final post = await AmitySocialClient.newPostRepository()
      .createPost()
      .targetCommunity(communityId)
      .custom('post.product', {
        'title': 'Wireless headphones',
        'price': 149.99,
        'currency': 'USD',
      })
      .post();
  ```
</CodeGroup>

## Notes

* The SDK stores the custom payload; your application owns validation and rendering for the custom schema.
* Use one stable data type per custom schema so feeds can route rendering predictably.
* Keep custom post data focused on renderable content. Use `metadata` for auxiliary app data that should not define the post type.

## Related Topics

<CardGroup cols={3}>
  <Card title="Posts Overview" icon="newspaper" href="../overview">
    Review post concepts, retrieval, and moderation flows.
  </Card>

  <Card title="Query Posts" icon="list" href="../retrieval/query-posts">
    Load custom posts back into feed and detail screens.
  </Card>

  <Card title="Edit Posts" icon="pen-to-square" href="../moderation/edit-post">
    Update supported post fields after creation.
  </Card>
</CardGroup>
