# add_www_domain

Source: https://modulify.ai/docs/api/domains/add-www-domain

Adds the www version of one of a site's custom domains, so the root and the www address both reach the site.

- Title: Add the www companion domain
- Scope: `config:write`
- Access: Destructive
- Endpoint: `POST /v1/add_www_domain`

Usually you do not need it, because `add_custom_domain` and `verify_domain` already attach the www companion for a root domain. Reach for it after `remove_www_domain`, or when `get_domain_status` shows no companion on a root domain because the automatic attempt did not complete.

It requires a paid plan and the **Manage domains** permission. The companion only exists for root domains, so a domain that is itself a subdomain is refused, and so is one that already has a companion or whose www hostname already belongs to this site or to another site in this workspace, with that site's name. While the domain itself still needs its [ownership record](https://modulify.ai/docs/publish/custom-domains#the-ownership-record), the companion waits for that TXT record too before it connects.

The proof that the domain is yours covers its www hostname, because the companion uses the domain's TXT record. So when a site in another workspace has the www hostname and the domain is verified, or was bought on the workspace's **Domains** page, that site loses it to this one and stops answering on it straight away, and the message ends with `www.example.com was moved here from another site.` The tool tells the client to confirm with you first. While the domain is not verified yet, it is refused with `www.example.com is used by another Modulify site. Once example.com is verified, add www.example.com again to move it here!`, and a domain connected before Modulify asked for the record has to be connected first, with `Once example.com is connected` in the message.

When the domain is itself the www hostname, because its root was removed, it adds the root back instead. When the hostname it adds is the domain waiting on verification, that pending verification is cleared.

Like the domain itself, the companion is not live until its DNS records are in place, so call `get_domain_status` afterwards to read what to add, or, for a domain the workspace bought that uses Modulify's nameservers, whether the records Modulify added are in place. On such a domain, the A, AAAA, ANAME and CNAME records already at the hostname it adds are replaced, so whatever they pointed at stops answering there, and the tool tells the client to confirm with you first. See [www and apex domains](https://modulify.ai/docs/publish/www-and-apex).

## Request

Call it with a `POST` to `https://api.modulify.ai/v1/add_www_domain`, sending the inputs below as a JSON object. The token needs the `config:write` scope.

> **Warning**
>
> This method is marked destructive: it deletes or overwrites data. Check the inputs before you call it, and send an [Idempotency-Key](https://modulify.ai/docs/api/idempotency) header whenever you might retry it.

```bash
curl -X POST https://api.modulify.ai/v1/add_www_domain \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"projectId":"PROJECT_ID","domainId":"DOMAIN_ID"}'
```

Over MCP, the same method is the [add_www_domain tool](https://modulify.ai/docs/mcp/domains/add-www-domain).

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | Yes | The site id. |
| `domainId` | string | Yes | The `_id` of the custom domain to add the www companion to, as `get_domain_status` or `add_custom_domain` returned it. The companion is derived from that domain. |

## Response

Every call answers with the [JSON envelope](https://modulify.ai/docs/api/requests-and-responses#the-response) of `success`, `message`, `data`, `code` and `version`. `data` holds the result described above, and on a method that returns a total, `count` carries it. The [response headers](https://modulify.ai/docs/api/requests-and-responses#headers-on-every-method-call) carry the call's `X-Request-Id` and what is left of your per-minute budget in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. [Errors](https://modulify.ai/docs/api/errors) explains every status code a call can answer with.