Telling a production key from a test one
A key carries no label saying which environment it belongs to. What it carries is an organization, and that is the thing to assert: compareorganization.slug — or organization.id — against what
your integration expects, and stop if they differ.
bash
ORG=$(curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
"https://www.agentsmail.io/api/v1/me" | jq -r '.data.organization.slug')
[ "$ORG" = "acme-staging" ] || { echo "wrong organization: $ORG"; exit 1; }The bootstrap sequence
1
Find out where you are
bash
curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
"https://www.agentsmail.io/api/v1/me" | jq '.data'role: member means every write below
will answer 403.2
Pick the list
bash
LIST_ID=$(curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
"https://www.agentsmail.io/api/v1/lists" | jq -r '.data[] | select(.name == "Newsletter") | .id')POST /api/v1/lists, see Audience.3
Work the audience
bash
curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
"https://www.agentsmail.io/api/v1/contacts?listId=$LIST_ID&status=subscribed"GET /api/v1/tags is the same trick as /lists, for tag ids.4
Compose and send
bash
curl -s -X POST -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
-d '{"name":"August newsletter","subject":"What shipped in August","templateId":"'$TEMPLATE_ID'","listId":"'$LIST_ID'"}' \
"https://www.agentsmail.io/api/v1/campaigns"/me and /lists never works from a stale id.