# Alterar uma campanha

Source: https://won.dev/pt-BR/docs/email/campaigns-update

`PATCH https://api.won.dev/v1/email/campaigns/{id}`

Altera uma campanha que não terminou (`draft`, `active` ou `paused`): só os campos enviados; os outros ficam como estão. O envio lê a campanha antes de cada e-mail, então uma alteração vale a partir do próximo. `steps` substitui a cadência inteira: uma etapa que já foi para alguém continua nela, com cada versão que foi enviada, embora o texto possa mudar para os e-mails que ainda faltam; etapas que ninguém recebeu podem mudar, sair ou ser adicionadas. Quem já recebeu todas as etapas terminou e não recebe etapas adicionadas depois. Uma espera que já começou mantém a duração. Os textos novos são conferidos como na criação, e um marcador sem valor alternativo é recusado enquanto alguém que ainda espera não tiver valor para ele. Não há simulação: uma alteração que não passa numa checagem não muda nada. Grátis.

- **Cobrança:** Grátis.

Uma chave de teste (`won_test_...`) roda isto no [sandbox](/pt-BR/docs/email#sandbox): nada é enviado e nada é cobrado.

## Parâmetros [#parameters]

`id` faz parte do caminho. Os demais vão no corpo JSON. Requisições `PATCH` também aceitam o cabeçalho `Idempotency-Key`; veja [Enviar uma requisição duas vezes](/pt-BR/docs/email#idempotency).

| Parâmetro | Tipo | Obrigatório | Descrição (texto original da API) |
| --- | --- | --- | --- |
| `id` | string | sim | Campaign ID, such as `cmp_7p1q8w3e5r4k2m9x`. |
| `name` | string | não | A name for your own reference. Recipients never see it. |
| `steps` | object[] | não | The whole sequence as it is to be, in order. It replaces the one there is. |
| `steps[].delay_days` | integer | não | Sending days to wait after the step before. Default 3. Ignored on the first step. |
| `steps[].subject` | string | não | The subject line. Required on the first step. Leave it out on a follow-up to send it as a reply in the thread of the first email, which is what gets answers. |
| `steps[].body` | string | sim | The text, as plain text. Placeholders: `{{first_name}}`, `{{last_name}}`, `{{company}}`, your own from `variables`, and `{{sender_first_name}}` and `{{sender_name}}` for the name of the mailbox that writes. `{{first_name\|there}}` falls back to "there". Do not add a signature block with your company and address or an unsubscribe line: every email ends with them. |
| `steps[].weight` | integer | não | With `variants`: this version's share of the recipients, relative to the others. Default: `1`. |
| `steps[].variants` | object[] | não | Other versions of this step, to test against it. Each recipient gets one version, always the same one. `GET /email/campaigns/{id}` shows how each did. |
| `steps[].variants[].subject` | string | não | The subject line. Required on the first step. Leave it out on a follow-up to send it as a reply in the thread of the first email, which is what gets answers. |
| `steps[].variants[].body` | string | sim | The text, as plain text. Placeholders: `{{first_name}}`, `{{last_name}}`, `{{company}}`, your own from `variables`, and `{{sender_first_name}}` and `{{sender_name}}` for the name of the mailbox that writes. `{{first_name\|there}}` falls back to "there". Do not add a signature block with your company and address or an unsubscribe line: every email ends with them. |
| `steps[].variants[].weight` | integer | não | With `variants`: this version's share of the recipients, relative to the others. Default: `1`. |
| `schedule` | object | não | The days and hours to send in. It replaces the whole schedule. |
| `schedule.timezone` | string | não | IANA time zone the hours are read in for a recipient whose own is not known. Default `America/New_York`. |
| `schedule.days` | (`sun` \| `mon` \| `tue` \| `wed` \| `thu` \| `fri` \| `sat`)[] | não | Days emails go out on. Default Monday to Friday. |
| `schedule.start_hour` | integer | não | First hour emails go out in. Default 9. |
| `schedule.end_hour` | integer | não | Emails go out before this hour. Default 17. |
| `daily_limit` | integer | não | The most emails the campaign sends on one day. It never sends more than the sender's domains may send, 45 a day each at full speed, which the sender's campaigns share. |
| `stop_on_company_reply` | boolean | não | When one person at a company answers, stop writing to the others at that company. |
| `track_opens` | boolean | não | Count opens with an invisible image. Off by default: it lowers inbox placement, and mail programs that fetch images themselves make the numbers unreliable. |
| `track_clicks` | boolean | não | Count clicks by sending links through our redirect. Off by default, for the same reason. |
| `metadata` | object | não | Your own keys and values, such as `{"customer_id": "c_812"}`: up to 20 keys of at most 40 characters, each value a string of at most 500. It replaces the metadata there is; `{}` removes it. Events that already happened keep what they carried. |

## Resposta [#response]

Os erros estão descritos em [Erros](/pt-BR/docs/errors).

| Campo | Tipo | Descrição (texto original da API) |
| --- | --- | --- |
| `data` | object | The campaign as it is now, and what the checks found in its texts. |
| `data.campaign` | object |  |
| `data.campaign.id` | string | Campaign ID, such as `cmp_7p1q8w3e5r4k2m9x`. |
| `data.campaign.name` | string |  |
| `data.campaign.sender_id` | string | The sender it is from. It sends from that sender's domains. |
| `data.campaign.status` | `draft` \| `active` \| `paused` \| `completed` \| `canceled` \| `suspended` | `draft` until started. `active` sends. `paused` waits for `resume`. `completed`, `canceled` and `suspended` are final. |
| `data.campaign.pause_reason` | `manual` \| `no_domains` \| `list_quality` \| `sending_suspended` \| null | Why it is paused: `manual`, `no_domains` (the sender's last sending domain ended; it goes on by itself once a new one is ready), `list_quality` (too many invalid addresses; resuming accepts the list as it is), `sending_suspended` (the sender was suspended). |
| `data.campaign.waiting` | `daily_limit` \| `ramping` \| `no_domains` \| null | Why an active campaign is not sending right now although people are due: `daily_limit` (it, or its sender's domains, sent all they may today), `ramping` (the same, while a domain is still on its way up to full speed), `no_domains` (its sender has no domain that can send yet). Null when it sends, or nobody is due. |
| `data.campaign.steps` | object[] | The sequence, in order. |
| `data.campaign.steps[].delay_days` | integer | Sending days to wait after the email before. 0 on the first step. |
| `data.campaign.steps[].versions` | object[] | The text of the step. More than one when versions are tested against each other. |
| `data.campaign.steps[].versions[].subject` | string \| null | Null on a follow-up that goes out as a reply in the thread of the first email. |
| `data.campaign.steps[].versions[].body` | string |  |
| `data.campaign.steps[].versions[].weight` | integer | Its share of the recipients, relative to the other versions. |
| `data.campaign.steps[].versions[].stats` | object | How this version did. |
| `data.campaign.steps[].versions[].stats.sent` | integer |  |
| `data.campaign.steps[].versions[].stats.opened` | integer | Emails opened at least once. Counted only when `track_opens` is on. |
| `data.campaign.steps[].versions[].stats.clicked` | integer |  |
| `data.campaign.steps[].versions[].stats.replied` | integer | Replies that came after this email and before the next one. |
| `data.campaign.schedule` | object | When emails go out: on these days, between these hours, in the recipient's time. |
| `data.campaign.schedule.timezone` | string | IANA time zone the hours are read in when a recipient's own is not known. |
| `data.campaign.schedule.days` | (`sun` \| `mon` \| `tue` \| `wed` \| `thu` \| `fri` \| `sat`)[] |  |
| `data.campaign.schedule.start_hour` | integer |  |
| `data.campaign.schedule.end_hour` | integer |  |
| `data.campaign.daily_limit` | integer | The most emails the campaign sends on one day. What its sender's domains can send is the limit above it. |
| `data.campaign.stop_on_company_reply` | boolean | One person at a company answers: nobody else at that company gets another email. |
| `data.campaign.track_opens` | boolean |  |
| `data.campaign.track_clicks` | boolean |  |
| `data.campaign.metadata` | object | Your own keys and values, as you gave them. Empty when none were. |
| `data.campaign.stats` | object | Where the campaign stands. |
| `data.campaign.stats.recipients` | integer | People in the campaign. |
| `data.campaign.stats.waiting` | integer | Still being checked, or waiting for their first email. |
| `data.campaign.stats.in_sequence` | integer | Got at least one email and have more to come. |
| `data.campaign.stats.finished` | integer | Got every email and did not answer. |
| `data.campaign.stats.replied` | integer |  |
| `data.campaign.stats.bounced` | integer |  |
| `data.campaign.stats.unsubscribed` | integer |  |
| `data.campaign.stats.excluded` | integer | Left out or stopped: invalid address, suppressed, or stopped by you. |
| `data.campaign.stats.emails_sent` | integer |  |
| `data.campaign.stats.emails_opened` | integer |  |
| `data.campaign.stats.emails_clicked` | integer |  |
| `data.campaign.test` | boolean | Made with a test key: sending and replies are simulated. |
| `data.campaign.created_at` | string | When it was created, as an ISO 8601 time in UTC. |
| `data.campaign.started_at` | string \| null |  |
| `data.campaign.completed_at` | string \| null |  |
| `data.campaign.next_check_after` | integer \| null | Seconds until something is likely to have changed. Asking sooner tells you nothing new. Null when the campaign is not running. |
| `data.content` | object | What the checks found in the sequence as it is now. |
| `data.content.advice` | object[] | What would make the emails more likely to reach an inbox and be answered. |
| `data.content.advice[].step` | integer | The step, counted from 1. |
| `data.content.advice[].version` | integer | The version of the step, counted from 1. |
| `data.content.advice[].field` | `subject` \| `body` |  |
| `data.content.advice[].code` | string |  |
| `data.content.advice[].message` | string |  |
| `data.content.variables` | object[] | The placeholders your texts use beyond the sender's own. `required` ones have no fallback: a recipient without a value is left out. |
| `data.content.variables[].name` | string |  |
| `data.content.variables[].required` | boolean |  |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | Nothing is charged here. The balance, for reference. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

## Exemplo [#example]

```bash
curl -X PATCH https://api.won.dev/v1/email/campaigns/cmp_7p1q8w3e5r4k2m9x \
  -H "Authorization: Bearer $WON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "daily_limit": 80,
  "steps": [
    {
      "subject": "Office chairs for {{company}}",
      "body": "Hi {{first_name|there}},\n\nI saw that {{company}} imports office seating. We make mesh task chairs in Leeds and ship to the US in four weeks.\n\nWould a price list be useful?\n\n{{sender_first_name}}"
    },
    {
      "delay_days": 4,
      "body": "Hi {{first_name|there}},\n\nWe can ship samples within a week now. Shall I send one?\n\n{{sender_first_name}}"
    }
  ]
}'
```

```json
{
  "data": {
    "campaign": {
      "id": "cmp_7p1q8w3e5r4k2m9x",
      "name": "US chair importers, November",
      "sender_id": "snd_4k2m9x7p1q8w3e5r",
      "status": "active",
      "pause_reason": null,
      "waiting": null,
      "steps": [
        {
          "delay_days": 0,
          "versions": [
            {
              "subject": "Office chairs for {{company}}",
              "body": "Hi {{first_name|there}},\n\nI saw that {{company}} imports office seating. We make mesh task chairs in Leeds and ship to the US in four weeks.\n\nWould a price list be useful?\n\n{{sender_first_name}}",
              "weight": 1,
              "stats": {
                "sent": 42,
                "opened": 0,
                "clicked": 0,
                "replied": 3
              }
            }
          ]
        },
        {
          "delay_days": 3,
          "versions": [
            {
              "subject": null,
              "body": "Hi {{first_name|there}},\n\nJust checking that my note reached the right person. Who looks after seating suppliers at {{company}}?\n\n{{sender_first_name}}",
              "weight": 1,
              "stats": {
                "sent": 17,
                "opened": 0,
                "clicked": 0,
                "replied": 1
              }
            }
          ]
        }
      ],
      "schedule": {
        "timezone": "America/New_York",
        "days": [
          "mon",
          "tue",
          "wed",
          "thu",
          "fri"
        ],
        "start_hour": 9,
        "end_hour": 17
      },
      "daily_limit": 80,
      "stop_on_company_reply": true,
      "track_opens": false,
      "track_clicks": false,
      "metadata": {
        "customer_id": "c_812"
      },
      "stats": {
        "recipients": 120,
        "waiting": 74,
        "in_sequence": 38,
        "finished": 0,
        "replied": 4,
        "bounced": 1,
        "unsubscribed": 1,
        "excluded": 2,
        "emails_sent": 59,
        "emails_opened": 0,
        "emails_clicked": 0
      },
      "test": false,
      "created_at": "2026-11-18T14:03:10.000Z",
      "started_at": "2026-11-18T14:03:11.000Z",
      "completed_at": null,
      "next_check_after": 1740
    },
    "content": {
      "advice": [],
      "variables": [
        {
          "name": "company",
          "required": true
        },
        {
          "name": "first_name",
          "required": false
        }
      ]
    }
  },
  "notice": null,
  "usage": {
    "cost": 0,
    "balance": 48.08,
    "replayed": false
  }
}
```