wpkrypt

Documentation

Send your first text message, choose API key permissions and verify webhook events.

Open API reference

Send your first message

Link your number in the dashboard, verify your email and use an active plan. Run these examples on your server. Go to dashboard

WPKRYPT_API_URL
API origin. Leave out /api/v1. Use HTTPS in production.
WPKRYPT_API_KEY
A key created in the dashboard with permission to send messages. Store it on your server.
WPKRYPT_TO
Your own test number. Include the country code.

PHP

<?php

$apiUrl = rtrim((string) getenv('WPKRYPT_API_URL'), '/');
$apiKey = (string) getenv('WPKRYPT_API_KEY');
$to = (string) getenv('WPKRYPT_TO');
if ($apiUrl === '' || $apiKey === '' || $to === '') {
    throw new RuntimeException('Set WPKRYPT_API_URL, WPKRYPT_API_KEY and WPKRYPT_TO.');
}

$request = curl_init($apiUrl.'/api/v1/messages');
curl_setopt_array($request, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer '.$apiKey,
        'Accept: application/json',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['to' => $to, 'text' => 'Merhaba'], JSON_THROW_ON_ERROR),
]);

$body = curl_exec($request);
if ($body === false) {
    throw new RuntimeException('Request outcome unknown; check message history before retrying.');
}
$status = curl_getinfo($request, CURLINFO_RESPONSE_CODE);
$result = json_decode($body, true, flags: JSON_THROW_ON_ERROR);
if ($status !== 202) {
    throw new RuntimeException('API error: '.($result['code'] ?? $status));
}
echo $result['data']['id'], PHP_EOL;

Node.js

const { WPKRYPT_API_URL: base, WPKRYPT_API_KEY: key, WPKRYPT_TO: to } = process.env;
if (!base || !key || !to) throw new Error('Set the wpkrypt environment variables.');

const response = await fetch(new URL('/api/v1/messages', base), {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${key}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ to, text: 'Merhaba' }),
  redirect: 'error',
  signal: AbortSignal.timeout(10_000),
});
const result = await response.json();
if (response.status !== 202) throw new Error(`API error: ${result.code ?? response.status}`);
console.log(result.data.id);

Python

import json
import os
from urllib.error import HTTPError
from urllib.request import HTTPRedirectHandler, Request, build_opener

base = os.environ["WPKRYPT_API_URL"].rstrip("/")
request = Request(
    base + "/api/v1/messages",
    data=json.dumps({"to": os.environ["WPKRYPT_TO"], "text": "Merhaba"}).encode(),
    headers={
        "Authorization": "Bearer " + os.environ["WPKRYPT_API_KEY"],
        "Accept": "application/json",
        "Content-Type": "application/json",
    },
    method="POST",
)

class NoRedirect(HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None


try:
    with build_opener(NoRedirect()).open(request, timeout=10) as response:
        if response.status != 202:
            raise RuntimeError(f"Unexpected status: {response.status}")
        print(json.load(response)["data"]["id"])
except HTTPError as error:
    result = json.load(error)
    raise RuntimeError(f"API error: {result.get('code', error.code)}") from None

HTTP 202 means the message was queued. Look up the message status with the returned ID or listen for webhook events. GET /api/v1/messages/{id}

402 indicates insufficient credits, 403 can indicate a permission, email verification or plan issue, and 422 indicates validation failure. Check message history before retrying a request that timed out.

API key permissions

Enable bulk sending when creating a key to grant campaign permissions. Managing webhooks and API keys requires a dashboard session.

PermissionOperation
messages:sendSend or schedule an individual message
messages:readList messages and look up their status
campaigns:writePreview, create or cancel a campaign
campaigns:readList campaigns and look up their status

Verify webhook signatures

Create a webhook in the dashboard and store the signing secret as WPKRYPT_WEBHOOK_SECRET on the receiving server. The secret is shown only on creation or rotation.

Join the X-Wpkrypt-Timestamp value, a period and the raw request body. Compute HMAC-SHA256 over those bytes, prepend sha256= and compare against X-Wpkrypt-Signature in constant time. Verify the signature before parsing the JSON.

Verify a webhook in PHP

<?php

$rawBody = file_get_contents('php://input');
$timestamp = $_SERVER['HTTP_X_WPKRYPT_TIMESTAMP'] ?? '';
$signature = $_SERVER['HTTP_X_WPKRYPT_SIGNATURE'] ?? '';
$secret = (string) getenv('WPKRYPT_WEBHOOK_SECRET');

if ($secret === '') {
    http_response_code(500);
    exit;
}

$expected = 'sha256='.hash_hmac('sha256', $timestamp.'.'.$rawBody, $secret);
if (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300
    || !hash_equals($expected, $signature)) {
    http_response_code(401);
    exit;
}

try {
    $event = json_decode($rawBody, true, flags: JSON_THROW_ON_ERROR);
} catch (JsonException) {
    http_response_code(400);
    exit;
}

// Persist or process $event idempotently before acknowledging.
http_response_code(204);

The example rejects timestamps more than five minutes in the past or future. Deliveries may be retried, so handle repeated events idempotently. Return 2xx after processing or durably recording the event. Use webhook.test in the dashboard to test your receiver.

API reference

The OpenAPI document lists request and response formats, permissions and error codes for message, campaign and webhook endpoints.

Open API reference