# Team API workflows

Use these workflows to automate common team administration tasks with the official Lettermint SDKs.

## Prerequisites

Before you start:

1. Create a [Team API token](/platform/teams/api-tokens).
2. Store it in `LETTERMINT_TEAM_TOKEN`.
3. Grant only the read and write abilities that the workflow needs.
4. Install an [official SDK](/sdks), or use cURL.

## Add and assign a domain

This workflow adds a domain, starts DNS verification, and assigns the domain to a project. Add each DNS record that has `required_for_verification` set to `true` before you run the verification step.

<CodeTabs syncKey="lettermint-language">

```typescript title="Node.js"
import { Lettermint } from "lettermint";

const lettermint = new Lettermint({
  teamToken: process.env.LETTERMINT_TEAM_TOKEN!,
});
const domain = await lettermint.domains.create({ domain: "example.com" });

await lettermint.domains.verifyDnsRecords(domain.id);
await lettermint.domains.updateProjects(domain.id, {
  project_ids: ["project-id"],
});
```

```php title="PHP"
<?php

use Lettermint\Lettermint;

$lettermint = new Lettermint(teamToken: getenv('LETTERMINT_TEAM_TOKEN'));
$domain = $lettermint->domains->create(['domain' => 'example.com']);

$lettermint->domains->verifyDnsRecords($domain->id);
$lettermint->domains->updateProjects($domain->id, [
    'project_ids' => ['project-id'],
]);
```

```python title="Python"
import os

from lettermint import Lettermint

with Lettermint(team_token=os.environ["LETTERMINT_TEAM_TOKEN"]) as lettermint:
    domain = lettermint.domains.create({"domain": "example.com"})
    lettermint.domains.verify_dns_records(domain["id"])
    lettermint.domains.update_projects(
        domain["id"],
        {"project_ids": ["project-id"]},
    )
```

```go title="Go"
package main

import (
	"context"
	"log"
	"os"

	lettermint "github.com/lettermint/lettermint-go/v3"
)

func main() {
	client, err := lettermint.New(lettermint.WithTeamToken(os.Getenv("LETTERMINT_TEAM_TOKEN")))
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()

	domain, err := client.Domains.Create(ctx, lettermint.StoreDomainData{
		Domain: "example.com",
	})
	if err != nil {
		log.Fatal(err)
	}

	if _, err = client.Domains.VerifyDNSRecords(ctx, domain.ID); err != nil {
		log.Fatal(err)
	}

	_, err = client.Domains.UpdateProjects(ctx, domain.ID, lettermint.UpdateDomainProjectsData{
		ProjectIDs: []string{"project-id"},
	})
	if err != nil {
		log.Fatal(err)
	}
}
```

```java title="Java"
import co.lettermint.Lettermint;
import co.lettermint.types.DomainData;
import co.lettermint.types.StoreDomainData;
import co.lettermint.types.UpdateDomainProjectsData;
import java.util.List;

Lettermint lettermint = Lettermint.builder()
    .teamToken(System.getenv("LETTERMINT_TEAM_TOKEN"))
    .build();

DomainData domain = lettermint.domains().create(new StoreDomainData("example.com"));

lettermint.domains().verifyDnsRecords(domain.id());
lettermint.domains().updateProjects(domain.id(), UpdateDomainProjectsData.builder()
    .projectIds(List.of("project-id"))
    .build());
```

```bash title="cURL"
DOMAIN_ID=$(curl -sS -X POST "https://api.lettermint.co/v1/domains" \
  -H "Authorization: Bearer $LETTERMINT_TEAM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"domain":"example.com"}' | jq -r '.id')

curl -X POST "https://api.lettermint.co/v1/domains/$DOMAIN_ID/dns-records/verify" \
  -H "Authorization: Bearer $LETTERMINT_TEAM_TOKEN"

curl -X PUT "https://api.lettermint.co/v1/domains/$DOMAIN_ID/projects" \
  -H "Authorization: Bearer $LETTERMINT_TEAM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"project_ids":["project-id"]}'
```

</CodeTabs>

The final request returns the updated domain-to-project assignment. DNS verification remains pending until all required records resolve.

:::note
Start DKIM updates for existing domains from the domain's **DNS** page in the dashboard. The Team API does not start or manage this update. Keep the current DKIM TXT record until the dashboard confirms the change.
:::

## Provision a project

Use this sequence when you provision an application environment:

1. Create a project with `projects.create`.
2. Create a route with `projects.createRoute`.
3. Create a webhook with `webhooks.create`.
4. Store the returned Project API token in `LETTERMINT_PROJECT_TOKEN`.

The [Team API quickstart](/platform/teams/team-api/quickstart#create-a-new-project) contains a complete six-language project example. See the [Team API reference](/api-reference/team) for the route and webhook request schemas.

## Monitor message delivery

Use `messages.list` to filter messages by status, project, route, recipient, or date. Then use `messages.events` with a message ID to retrieve its delivery history.

A message with several recipients has one status: the highest-ranked recipient result. Use `messages.events` to see each recipient's result. See [Status for messages with multiple recipients](/platform/emails/activity#status-for-messages-with-multiple-recipients).

The Messages API is read-only. Use a Project API token and the Sending API to send email.

## Manage suppressions

Use `suppressions.create`, `suppressions.list`, and `suppressions.delete` to manage suppression entries. The [Suppressions guide](/platform/emails/suppressions) contains complete examples for all official SDKs and cURL.

## Production guidance

- Store tokens in environment variables or a secrets manager.
- Grant only the abilities that each integration needs.
- Use cursor-based pagination for large result sets.
- Log request IDs and timestamps for troubleshooting.
- Retry temporary failures with exponential backoff.
- Remove tokens that are no longer used.

:::warning
Team API tokens can access team resources. Never expose them in client-side code, public repositories, or logs.
:::

## Next steps

- [Team API quickstart](/platform/teams/team-api/quickstart) - Run your first requests.
- [Manage member access](/platform/teams/team-api/member-access) - Assign roles and project access.
- [Team API reference](/api-reference/team) - Review endpoint schemas.
