NightmailDocs
Docs

Test campaign

post/v1/campaigns/{id}/test

Send the current draft, personalized with data, to one address as a transactional test. It shows the footer as recipients get it (the Unsubscribe link, a placeholder here, and the workspace’s postal address, if set) without List-Unsubscribe headers, and needs no postal address. On Hosted sending a test goes only to an address the workspace has proven is its own: a member’s verified email, an address at one of its currently verified domains or their subdomains (its receiving addresses and inboxes there included; not a domain whose verification lapsed), or the SES mailbox simulator (422 TEST_RECIPIENT_NOT_OWNED otherwise; send the campaign to reach anyone else), a workspace sends at most 20 tests a clock hour (429 CAMPAIGN_TEST_LIMIT, retryable at resetAt), and each test is screened on its own, with the campaign limit (131,072 bytes of screened text by default; 422 CONTENT_TOO_LARGE_TO_SCREEN with error.details[0] { screenedBytes, limitBytes } over it).

Needs Send email on the whole workspace.

Example

import { createClient } from '@nightmail/sdk/client';
import { testCampaign } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await testCampaign({
  client,
  path: {
    "id": "resource_123"
  },
  body: {
    "to": "recipient@example.com",
    "data": {}
  },
  throwOnError: true,
});

console.log(result.data);
curl --request POST \
  --url 'https://nightmail.dev/v1/campaigns/resource_123/test' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "to": "recipient@example.com",
  "data": {}
}'

Parameters

idrequiredpath · string
Idempotency-Keyheader · string

Optional. Makes retries safe. Repeating a request with the same key and the same body returns the original result without performing the write again. While the first request with a key is still running, a duplicate returns 409 IDEMPOTENCY_IN_PROGRESS with Retry-After: retry with the same key, never a new one. Reusing a key with a different body returns 409 IDEMPOTENCY_CONFLICT. Keys are scoped to the API key and request path. A send's key is kept at least 30 days from the request, as long as the log of the emails it queued; then it is deleted, and the same key is a new request that sends again. A scheduled send's key is kept at least 60 days, after which a repeat is refused because its time has passed. Without a key, every request is processed, so a retried send can deliver twice.

Request body

CampaignTestInput
torequiredstring
dataobject

Up to 100 key/value pairs, at most 64 KiB of JSON total.

Responses

202Success
EmailQueued
idrequiredstring
statusrequiredstring
simulatedrequiredboolean
screenobject

Content-screen outcome recorded at accept time when screening applies.

screen.statusrequiredstring
warningsobject[]

Recipients whose address looks risky (a disposable inbox, a mistyped provider, a role address): the email was queued anyway. Campaigns and marketing sends skip risky contacts.

warnings[].emailrequiredstring
warnings[].riskrequiredstring
warnings[].suggestionrequiredstring or null
400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiError
errorrequiredobject
error.coderequiredstring
error.messagerequiredstring
error.requestIdrequiredstring
error.fieldstring
error.retryablerequiredboolean
error.resetAtstring

Next capacity change for a Hosted rolling send limit.

error.detailsobject[]

Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch).

error.requiredobject

On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.