# Set a workspace up with an agent

You do not need to click through the dashboard to get started. Give an agent one
account key and the block below, and it walks the same path a person would: create
the workspace, publish the DNS records, wait for DKIM, test, then ask for
production access.

## 1. Get an account key

An account key starts `wm_acct_` and is not bound to a workspace, so one key can
create and inspect several. Ask the operator for one, or mint it yourself if you
have operator access:

```bash
curl -X POST https://werkmail.eu/api/account/tokens \
  -H "X-Admin-Token: $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"my agent","expires_in_days":365}'
```

The key is shown once. Store it like a password, it can create workspaces. Read it from the file
you saved, never type it again: a single extra character at the end turns a working key into
`account_token_invalid`.

## 2. Copy this for your agent

```text
You are setting up a Werkmail workspace end to end. Work in this order and stop
only where a human has to act: DNS changes and approving production access.

BASE = https://werkmail.eu
Authorization: Bearer $WERKMAIL_ACCOUNT_TOKEN
Always send a normal browser User-Agent, the edge answers 403 without it.

1. GET $BASE/api/account/workspaces
   Never assume a workspace exists, read what is there first.
2. POST $BASE/api/account/workspaces {"name":"Practice X","domain":"mail.practice-x.at"}
   The answer carries the DKIM records, the DNS block and a workspace key
   (wm_team_...). Keep that key, everything after this uses it.
   Calling this again for the same domain resumes the half finished workspace
   and returns the same records instead of failing, so a retry is always safe.
3. Give the human the DKIM and MAIL FROM records exactly as returned. DNS only,
   never proxied.
4. POST $BASE/api/account/workspaces/{id}/verify-domain until dkim_verified is
   true. The provider checks on its own schedule, so poll with a pause.
5. GET $BASE/api/account/workspaces/{id}/next-step and follow the single action
   it names. Do not improvise steps.
6. Optional branded links: PUT $BASE/api/practices/{id}/tracking-domain
   {"domain":"links.practice-x.at"} with the workspace key. The CNAME points at
   r.eu-central-1.awstrack.me, or the host must be a verified identity when the
   record is proxied.
7. Build the campaign as a draft with the workspace key:
   POST $BASE/api/practices/{id}/broadcasts {"draft":true,...}
   Then POST .../broadcasts/{campaignID}/test {"to":"owner@example.com"}.
   Never set "start" or "scheduled_at" without written approval.
8. POST $BASE/api/practices/{id}/production-access and tell the human it is a
   request, not a switch.
9. After approval send the first campaign to a small list only, then read
   GET /api/practices/{id}/events and report delivered, opened, clicked, bounced.

Rules: never invent DNS values, never send to addresses the human did not name,
respect the limit of two marketing mails per recipient in 24 hours, and report
numbers you actually read.
```

## 3. What the agent can and cannot do

- It can create a workspace, attach a domain, read the DKIM state and follow the
  next step without asking you anything.
- It cannot publish DNS records. That stays with the person who owns the zone.
- It cannot grant production access. It can only request it, an operator decides.
- It cannot send with an account key. Sending needs the workspace key that step 2
  returns.

## 4. Where to read next

- [API reference](/api/reference) for every route, field and error code.
- [Errors](/errors) for the stable codes an agent should branch on.
- [Email for agents](/email-for-agents) for the accept fast, report honestly rules.
- [Automation recipes](/automation-recipes) for the calls in a working order.
- OpenAPI file: [/openapi.yaml](/openapi.yaml) if your agent reads schemas.
