ZapSMTP / Docs / API keys & SMTP credentialsResponse
Create an API key
POST/v1/api-keys
Create an API key; the full key (token) is returned only once.
Requires a full-access live key; test keys get 403 test_key_restricted.
Body parameters
namestringrequired- Limits: 1-100 characters (not trimmed) → 422 invalid_parameter "name is required (max 100 chars)"
permissionstring- One of
full_access,sending_access. Defaultfull_access. domain_idstring- Restrict sending to one of the account's domains. Only with sending_access. Limits: 422 "domain_id can only be used with sending_access" / "unknown domain_id"
modestring- test creates a zap_test_ key (see API keys). One of
live,test. Defaultlive. streamstring- Restrict the key to one message stream. One of
transactional,broadcast. expires_atstring (RFC 3339)- Limits: must be in the future → 422 "expires_at must be in the future"
expires_in_daysinteger- Alternative to expires_at; when > 0 it overrides expires_at.
Errors
key_restrictedHTTP 403- this API key expires, so the keys it manages must expire no later than it does | this API key is limited to the <stream> stream, and so are the keys it manages
restricted_api_keyHTTP 403test_key_restrictedHTTP 403- test-mode keys can send test email and read, not change the account: use a live key
invalid_parameterHTTP 422- name, permission, domain_id, mode, stream or expiry invalid
curl -X POST 'https://zapsmtp.xyz/v1/api-keys' \
-H "Authorization: Bearer $ZAP_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"name": "checkout-service",
"permission": "sending_access",
"mode": "live"
}'const res = await fetch('https://zapsmtp.xyz/v1/api-keys', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ZAP_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"name": "checkout-service",
"permission": "sending_access",
"mode": "live"
}),
});
// 204 No Content (e.g. a delete) has no body
const data = res.status === 204 ? null : await res.json();
if (!res.ok) throw new Error(`${data.name}: ${data.message}`);
console.log(data);import os
import requests
res = requests.post(
"https://zapsmtp.xyz/v1/api-keys",
headers={"Authorization": f"Bearer {os.environ['ZAP_API_KEY']}"},
json={
"name": "checkout-service",
"permission": "sending_access",
"mode": "live",
},
timeout=30,
)
res.raise_for_status()
print(res.json() if res.status_code != 204 else "deleted")<?php
$ch = curl_init('https://zapsmtp.xyz/v1/api-keys');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('ZAP_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'name' => 'checkout-service',
'permission' => 'sending_access',
'mode' => 'live',
]),
]);
$data = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status >= 400) {
throw new RuntimeException($data['message']);
}
print_r($data);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{
"name": "checkout-service",
"permission": "sending_access",
"mode": "live"
}`)
req, err := http.NewRequest(
"POST",
"https://zapsmtp.xyz/v1/api-keys",
body,
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("ZAP_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(out))
}require 'net/http'
require 'json'
uri = URI('https://zapsmtp.xyz/v1/api-keys')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "Bearer #{ENV.fetch('ZAP_API_KEY')}"
req['Content-Type'] = 'application/json'
req.body = {
name: "checkout-service",
permission: "sending_access",
mode: "live"
}.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, (JSON.parse(res.body) unless res.body.to_s.empty?)import java.net.URI;
import java.net.http.*;
public class ZapRequest {
public static void main(String[] args) throws Exception {
var request = HttpRequest.newBuilder(URI.create("https://zapsmtp.xyz/v1/api-keys"))
.header("Authorization", "Bearer " + System.getenv("ZAP_API_KEY"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("""
{
"name": "checkout-service",
"permission": "sending_access",
"mode": "live"
}"""))
.build();
var response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}using System.Net.Http.Headers;
using System.Text;
using var http = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://zapsmtp.xyz/v1/api-keys");
request.Headers.Authorization = new AuthenticationHeaderValue(
"Bearer", Environment.GetEnvironmentVariable("ZAP_API_KEY"));
request.Content = new StringContent("""
{
"name": "checkout-service",
"permission": "sending_access",
"mode": "live"
}
""", Encoding.UTF8, "application/json");
var response = await http.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");Set
ZAP_API_KEY in your environment.Response 201 Created
{
"id": "019a1f05-3c4d-7e5f-8a6b-7c8d9e0f1a2b",
"token": "zap_8fK2mQ9xLr3TzV7bN1cW5yHjP0aS4dE6gU2iO9kX",
"key": {
"id": "019a1f05-3c4d-7e5f-8a6b-7c8d9e0f1a2b",
"name": "Production",
"prefix": "zap_8fK2mQ",
"permission": "sending_access",
"mode": "live",
"stream": null,
"expires_at": null,
"domain_id": "019a1f10-8a10-7b22-8c31-5d2e9f0a4b17",
"last_used_at": null,
"created_at": "2026-10-21T15:30:00Z"
}
}