> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open-metadata.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Topic

> Create a new topic within a messaging service

# Create a Topic

Create a new topic within a messaging service.

## Body Parameters

<ParamField body="name" type="string" required>
  Name of the topic. Must be unique within the parent messaging service.
</ParamField>

<ParamField body="service" type="string" required>
  Fully qualified name of the parent MessagingService (e.g., `sample_kafka`).
</ParamField>

<ParamField body="messageSchema" type="object">
  Schema definition for messages in the topic.

  <Expandable title="properties">
    <ParamField body="schemaType" type="string">
      Type of schema (e.g., `Avro`, `Protobuf`, `JSON`, `Other`).
    </ParamField>

    <ParamField body="schemaText" type="string">
      The schema definition text.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="partitions" type="integer">
  Number of partitions for the topic.
</ParamField>

<ParamField body="cleanupPolicies" type="array">
  Array of cleanup policies for the topic (e.g., `delete`, `compact`).
</ParamField>

<ParamField body="replicationFactor" type="integer">
  Replication factor for the topic.
</ParamField>

<ParamField body="maximumMessageSize" type="integer">
  Maximum message size in bytes.
</ParamField>

<ParamField body="retentionSize" type="integer">
  Retention size in bytes. Use `-1` for unlimited.
</ParamField>

<ParamField body="displayName" type="string">
  Human-readable display name for the topic.
</ParamField>

<ParamField body="description" type="string">
  Description of the topic in Markdown format.
</ParamField>

<ParamField body="owners" type="array">
  Array of owner references (users or teams) to assign to the topic.

  <Expandable title="properties">
    <ParamField body="id" type="string">
      UUID of the owner entity.
    </ParamField>

    <ParamField body="type" type="string">
      Type of owner entity (e.g., `user`, `team`).
    </ParamField>

    <ParamField body="name" type="string">
      Name of the owner entity.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="domain" type="string">
  Fully qualified name of the domain to assign for governance purposes.
</ParamField>

<ParamField body="tags" type="array">
  Array of classification tags to apply to the topic.

  <Expandable title="properties">
    <ParamField body="tagFQN" type="string" required>
      Fully qualified name of the tag.
    </ParamField>

    <ParamField body="labelType" type="string">
      Type of label (e.g., `Manual`, `Derived`, `Propagated`).
    </ParamField>

    <ParamField body="state" type="string">
      State of the tag (e.g., `Suggested`, `Confirmed`).
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="extension" type="object">
  Custom property values defined by your organization's metadata schema.
</ParamField>

<RequestExample dropdown>
  ```python POST /v1/topics theme={null}
  from metadata.sdk import configure
  from metadata.sdk.entities import Topics
  from metadata.generated.schema.api.data.createTopic import CreateTopicRequest

  configure(
      host="https://your-company.open-metadata.org/api",
      jwt_token="your-jwt-token"
  )

  request = CreateTopicRequest(
      name="address_book",
      displayName="Address Book",
      service="sample_kafka",
      description="All Protobuf record related events gets captured in this topic",
      messageSchema={
          "schemaType": "Protobuf",
          "schemaText": "syntax = \"proto2\";\npackage tutorial;\nmessage Person { ... }"
      },
      partitions=1,
      cleanupPolicies=["delete"],
      replicationFactor=1,
      maximumMessageSize=1,
      retentionSize=-1
  )

  topic = Topics.create(request)
  print(f"Created: {topic.fullyQualifiedName}")
  ```

  ```java POST /v1/topics theme={null}
  import static org.openmetadata.sdk.fluent.Topics.*;

  // Create using builder pattern
  var topic = Topics.builder()
      .name("address_book")
      .displayName("Address Book")
      .service("sample_kafka")
      .description("All Protobuf record related events gets captured in this topic")
      .partitions(1)
      .cleanupPolicies(List.of("delete"))
      .replicationFactor(1)
      .create();
  ```

  ```bash POST /v1/topics theme={null}
  curl -X POST "{base_url}/api/v1/topics" \
    -H "Authorization: Bearer {access_token}" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "address_book",
      "service": "sample_kafka",
      "description": "All Protobuf record related events gets captured in this topic",
      "messageSchema": {
        "schemaType": "Protobuf",
        "schemaText": "syntax = \"proto2\";\npackage tutorial;\nmessage Person { ... }"
      },
      "partitions": 1,
      "cleanupPolicies": ["delete"],
      "replicationFactor": 1,
      "maximumMessageSize": 1,
      "retentionSize": -1
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "0a021819-982e-4ee4-a5a2-4af30eaa3016",
    "name": "address_book",
    "fullyQualifiedName": "sample_kafka.address_book",
    "description": "All Protobuf record related events gets captured in this topic",
    "version": 0.1,
    "updatedAt": 1769982663546,
    "updatedBy": "admin",
    "service": {
      "id": "469ef25e-9bdf-4d5f-8553-eb0ce8581f30",
      "type": "messagingService",
      "name": "sample_kafka",
      "fullyQualifiedName": "sample_kafka",
      "displayName": "sample_kafka",
      "deleted": false
    },
    "serviceType": "Kafka",
    "messageSchema": {
      "schemaText": "syntax = \"proto2\";\npackage tutorial;\nmessage Person { ... }",
      "schemaType": "Protobuf",
      "schemaFields": [
        {
          "name": "AddressBook",
          "dataType": "RECORD",
          "fullyQualifiedName": "sample_kafka.address_book.AddressBook",
          "children": []
        }
      ]
    },
    "partitions": 1,
    "cleanupPolicies": ["delete"],
    "replicationFactor": 1,
    "maximumMessageSize": 1,
    "retentionSize": -1,
    "href": "http://localhost:8585/api/v1/topics/0a021819-982e-4ee4-a5a2-4af30eaa3016",
    "deleted": false,
    "owners": [],
    "tags": [],
    "followers": [],
    "votes": {
      "upVotes": 0,
      "downVotes": 0,
      "upVoters": [],
      "downVoters": []
    },
    "domains": []
  }
  ```
</ResponseExample>

***

## Returns

Returns the created topic object with all specified properties and system-generated fields.

## Response

<ResponseField name="id" type="string">
  Unique identifier for the topic (UUID format).
</ResponseField>

<ResponseField name="name" type="string">
  Topic name.
</ResponseField>

<ResponseField name="fullyQualifiedName" type="string">
  Fully qualified name in format `service.topicName`.
</ResponseField>

<ResponseField name="displayName" type="string">
  Human-readable display name.
</ResponseField>

<ResponseField name="description" type="string">
  Description of the topic in Markdown format.
</ResponseField>

<ResponseField name="service" type="object">
  Reference to the parent messaging service.

  <Expandable title="properties">
    <ResponseField name="id" type="string">
      UUID of the messaging service.
    </ResponseField>

    <ResponseField name="type" type="string">
      Type of entity (always `messagingService`).
    </ResponseField>

    <ResponseField name="name" type="string">
      Name of the messaging service.
    </ResponseField>

    <ResponseField name="fullyQualifiedName" type="string">
      Fully qualified name of the messaging service.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="messageSchema" type="object">
  Schema definition for messages in the topic.

  <Expandable title="properties">
    <ResponseField name="schemaType" type="string">
      Type of schema (e.g., `Avro`, `Protobuf`, `JSON`).
    </ResponseField>

    <ResponseField name="schemaText" type="string">
      The schema definition text.
    </ResponseField>

    <ResponseField name="schemaFields" type="array">
      Parsed schema fields.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="partitions" type="integer">
  Number of partitions for the topic.
</ResponseField>

<ResponseField name="cleanupPolicies" type="array">
  Cleanup policies for the topic.
</ResponseField>

<ResponseField name="replicationFactor" type="integer">
  Replication factor for the topic.
</ResponseField>

<ResponseField name="maximumMessageSize" type="integer">
  Maximum message size in bytes.
</ResponseField>

<ResponseField name="retentionSize" type="integer">
  Retention size in bytes.
</ResponseField>

<ResponseField name="serviceType" type="string">
  Type of messaging service (e.g., Kafka, Redpanda, Kinesis).
</ResponseField>

<ResponseField name="owners" type="array" optional>
  List of owners assigned to the topic.

  <Expandable title="properties">
    <ResponseField name="id" type="string">
      UUID of the owner entity.
    </ResponseField>

    <ResponseField name="type" type="string">
      Type of owner entity (e.g., `user`, `team`).
    </ResponseField>

    <ResponseField name="name" type="string">
      Name of the owner entity.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="domains" type="array" optional>
  Domain assignments for governance.
</ResponseField>

<ResponseField name="tags" type="array" optional>
  Classification tags applied to the topic.

  <Expandable title="properties">
    <ResponseField name="tagFQN" type="string">
      Fully qualified name of the tag.
    </ResponseField>

    <ResponseField name="labelType" type="string">
      Type of label (e.g., `Manual`, `Derived`, `Propagated`).
    </ResponseField>

    <ResponseField name="state" type="string">
      State of the tag (e.g., `Suggested`, `Confirmed`).
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="extension" type="object" optional>
  Custom property values defined by your organization's metadata schema.
</ResponseField>

<ResponseField name="version" type="number">
  Version number for the entity (starts at 0.1).
</ResponseField>

***

## Create or Update (PUT)

Use `PUT /v1/topics` instead of `POST` to perform an upsert. If a topic with the same `fullyQualifiedName` already exists, it will be updated; otherwise, a new topic is created. The request body is the same as `POST`.

```bash theme={null}
curl -X PUT "{base_url}/api/v1/topics" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{ ... same body as POST ... }'
```

<Note>
  `PUT` will not return a `409` conflict error if the entity already exists -- it will update the existing entity instead.
</Note>

***

## Bulk Create or Update (PUT)

Use `PUT /v1/topics/bulk` to create or update multiple topics in a single request. The request body is an array of create request objects.

```bash theme={null}
curl -X PUT "{base_url}/api/v1/topics/bulk" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '[
    { "name": "topic_one", "service": "sample_kafka" },
    { "name": "topic_two", "service": "sample_kafka" }
  ]'
```

***

## Error Handling

| Code  | Error Type              | Description                                                |
| ----- | ----------------------- | ---------------------------------------------------------- |
| `400` | `BAD_REQUEST`           | Invalid request body or missing required fields            |
| `401` | `UNAUTHORIZED`          | Invalid or missing authentication token                    |
| `403` | `FORBIDDEN`             | User lacks permission to create topics                     |
| `409` | `ENTITY_ALREADY_EXISTS` | Topic with same name already exists in service (POST only) |
