# Create topic

> POST /topics — create a subscription topic within a sending domain.

`POST /topics`

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Display name (max 255 chars). |
| `default_subscription` | string | Yes | The default subscription preference for new contacts: `opt_in` (every contact receives the topic unless they explicitly unsubscribe from it) or `opt_out` (no contact receives the topic unless they explicitly subscribe). **This value cannot be changed later.** |
| `visibility` | string | No | Visibility of the topic on the preference page: `public` (all contacts can see and toggle it) or `private` (only contacts already opted in can see it). Defaults to `private`. |
| `description` | string | No | Optional description shown on the preference page (max 200 chars). |
| `domain` | string | Yes | The sending domain this topic belongs to (one of your domains). Topic names are unique within a domain but freely reusable across domains. Passing `audience_id` is no longer accepted — pass `domain`. |

**Node.js**

```js
import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.topics.create({ "domain": "yourdomain.com", "name": "Product updates", "default_subscription": "opt_in" });
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Topics.create({
  "domain": "yourdomain.com",
  "name": "Product updates",
  "default_subscription": "opt_in"
})
```

**PHP**

```php
$mailblastr = Mailblastr::client('mb_xxxxxxxxx');

$mailblastr->topics->create([
  'domain' => "yourdomain.com",
  'name' => "Product updates",
  'default_subscription' => "opt_in"
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Topics.create({
  "domain": "yourdomain.com",
  "name": "Product updates",
  "default_subscription": "opt_in"
})
```

**Go**

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, _ := http.NewRequest("POST", "https://api.mailblastr.com/topics", strings.NewReader(`{ "domain": "yourdomain.com", "name": "Product updates", "default_subscription": "opt_in" }`))
    req.Header.Set("Authorization", "Bearer mb_xxxxxxxxx")
    req.Header.Set("Content-Type", "application/json")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    out, _ := io.ReadAll(res.Body)
    fmt.Println(string(out))
}
```

**Rust**

```rust
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = Client::new()
        .post("https://api.mailblastr.com/topics")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{ "domain": "yourdomain.com", "name": "Product updates", "default_subscription": "opt_in" }"#)
        .send()
        .await?;
    println!("{}", res.text().await?);
    Ok(())
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mailblastr.com/topics"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("""
{ "domain": "yourdomain.com", "name": "Product updates", "default_subscription": "opt_in" }
"""))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**.NET**

```csharp
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.mailblastr.com/topics");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{ ""domain"": ""yourdomain.com"", ""name"": ""Product updates"", ""default_subscription"": ""opt_in"" }", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

```bash
curl -X POST 'https://api.mailblastr.com/topics' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "domain": "yourdomain.com", "name": "Product updates", "default_subscription": "opt_in" }'
```

**CLI**

```bash
mailblastr topics create \
  --domain 'yourdomain.com' \
  --name 'Product updates' \
  --default-subscription 'opt_in'
```

```json
{
  "object": "topic",
  "id": "topic_9a2f...",
  "audience_id": "aud_3b1c...",
  "name": "Product updates",
  "description": null,
  "default_subscription": "opt_in",
  "visibility": "private",
  "created_at": "2026-06-25T10:00:00.000Z"
}
```
