Update an API key
Rename or re-scope an API key, or set its source-IP allowlist.
Rename a key, narrow its scope, or restrict it to a source-IP allowlist — all without rotating the secret.
PATCH /v3/keys/{id}
Body parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Optional | New label (max 255 chars). |
scope | string | Optional | full_access, send_only or read_only. Live keys only — test keys always stay full_access and this field is ignored for them. |
verify_before_send | boolean or null | Optional | Override (true/false) or inherit (null) the verify-before-send setting. Live keys only. |
test_outcomes | object | Optional | New simulated outcome mix. Test keys only — ignored for live keys. |
ip_allowlist | array | Optional | Source-IP allowlist as [{ "cidr": "203.0.113.0/24", "label": "office" }] (max 50 entries, IPv4/IPv6 CIDRs — bare IPs are normalized to /32//128). Requests from any other IP are rejected with 403 ip_not_allowed. Empty array [] clears the restriction. Applies to both live and test keys. |
Responses
| Status | Description |
|---|---|
200 | OK. The updated key. An empty update returns the current key unchanged. |
400 | Validation error — e.g. an invalid CIDR in ip_allowlist (the message names the offending entry). |
401 | Missing or invalid API key. |
403 | Only account owners/admins can change a key's IP allowlist. |
404 | No such key on your account, or it has already been revoked. |
Code examples
cURL
curl -X PATCH https://api.wemail.io/v3/keys/{id} \
-H "Authorization: Bearer afn_live_…" \
-H "Content-Type: application/json" \
-d '{ "name": "Production API Key (rotating)", "scope": "send_only" }'Node.js
const res = await fetch("https://api.wemail.io/v3/keys/{id}", {
method: "PATCH",
headers: {
Authorization: `Bearer ${process.env.WEMAIL_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ "name": "Production API Key (rotating)", "scope": "send_only" }),
});
const data = await res.json();Python
import os, requests
r = requests.patch(
"https://api.wemail.io/v3/keys/{id}",
headers={"Authorization": f"Bearer {os.environ['WEMAIL_API_KEY']}"},
json={ "name": "Production API Key (rotating)", "scope": "send_only" },
)
data = r.json()