Note: These endpoints need NO API token — the purchase code is the credential, so the code you ship to buyers can call them directly.
Warning: Every answer is signed with Ed25519. Verify the signature and the nonce before trusting it. A module that only reads status can be fooled by a fake server or a hosts-file redirect that answers "success". See Signatures & fields.
Note: The right to USE the software never expires. When update support ends, verify still returns valid — only the updates block reports that renewal is due. An expired update period must never break a live site.
Important: item_id is required on activate, verify and deactivate. Every call is scoped to the calling item, so a buyer who types the code of another product into yours gets invalid_code — nothing is activated on that other licence and no slot is taken. Calls without item_id are refused with invalid_request.
#Endpoints
/api/license/activate/api/license/verify/api/license/deactivate/api/license/public-key| Parameter | Type | Description |
|---|---|---|
purchase_code required |
string | the code the buyer received |
item_id required |
integer | the ID of YOUR item — the number at the end of its SellMyCode URL (also shown in Workspace → My Items). Hard-code it in your product. A purchase code of any other item is answered exactly like an unknown code (invalid_code) and never activates or holds a slot. |
domain required |
string | the site running the software; scheme, www and path are stripped automatically |
nonce required |
string | 16–128 random characters (A-Z a-z 0-9 _ -), new for EVERY call. It is echoed inside the signed answer, so an old answer cannot be replayed. |
activation_token |
string | the token you received when this site was activated — required by deactivate; optional on verify and activate, where it adds an entitlement token to the answer |
#What your software must do
- Send a fresh random nonce with every call.
- Verify the signature over the payload string with the public key. If it fails, ignore the answer completely.
- Decode the payload and check that its nonce equals the one you sent, that
item.idis YOUR item and thatdomainis this site. One key signs answers for every product on SellMyCode, so a relay could pass on a genuine answer about another item or another site with your nonce in it. - On activate, store
activation_token— it is shown once, and deactivation, updates and entitlement tokens all need it. - On
activation_limit_reached, show the hint and a button that openstransfer_url(the item's support page), where the buyer asks you to free a slot. - On
license_blockedorsite_blocked, switch the licensed features off and show the hint withtransfer_url— these are authoritative signed answers, likeinvalid_code. - Keep the last verified answer. When we cannot be reached, answer 5xx, or rate limit you, keep running on it until its
grace_until— never treat an outage as "licence invalid". A signed error such asinvalid_codeornot_activatedis authoritative and should replace it.
// PHP 7.2+ (sodium is built in)
function sellmycode_license(string $action, array $fields): ?array
{
// kid => raw 32-byte public key (Base64): the active key and the standby "next" key
$keys = ['k1' => '5Uk3p1+J0PXzJkwS4wVFvTN9GcHpJzX5ClRI8zlI0yQ=', 'k2' => 'erOiojOdS5F/IfhPMO9gvjAvuEPVapIadTDaWU0z83o='];
$fields['nonce'] = bin2hex(random_bytes(16));
$ch = curl_init('https://sellmycode.net/api/license/' . $action);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_POSTFIELDS => http_build_query($fields),
]);
$res = json_decode((string) curl_exec($ch), true);
// unreachable, 5xx, unsigned or forged: return null and keep the cached state
if (!isset($res['payload'], $res['signature'], $keys[$res['kid'] ?? ''])
|| !sodium_crypto_sign_verify_detached(base64_decode($res['signature']), $res['payload'], base64_decode($keys[$res['kid']]))) {
return null;
}
$data = json_decode($res['payload'], true);
// must answer THIS request, not be an old answer replayed
if (($data['nonce'] ?? '') !== $fields['nonce']) {
return null;
}
// and be about THIS item and THIS site: one key signs for every product on SellMyCode
if (isset($data['item']['id']) && (int) $data['item']['id'] !== (int) $fields['item_id']) {
return null;
}
if (isset($data['domain']) && $data['domain'] !== sellmycode_domain($fields['domain'])) {
return null;
}
return $data;
}
// the domain as SellMyCode stores it: lower case, no scheme, path or www.
function sellmycode_domain(string $value): string
{
$host = parse_url(strpos($value, '://') === false ? 'http://' . $value : $value, PHP_URL_HOST);
return preg_replace('/^www\./', '', strtolower(trim((string) $host, '.')));
}
const ITEM_ID = 12345; // your item's ID on SellMyCode
// first run: activate and keep the token
$r = sellmycode_license('activate', ['purchase_code' => $code, 'item_id' => ITEM_ID, 'domain' => $_SERVER['HTTP_HOST']]);
if ($r && $r['status'] === 'success' && $r['activation_token']) {
save_setting('license_token', $r['activation_token']);
}
// daily: verify, cache the signed answer, run on it through an outage
$r = sellmycode_license('verify', ['purchase_code' => $code, 'item_id' => ITEM_ID, 'domain' => $_SERVER['HTTP_HOST']]);
if ($r && $r['code'] !== 'rate_limited') {
save_setting('license_state', $r);
}
$state = get_setting('license_state');
$licensed = $state && $state['status'] === 'success' && strtotime($state['grace_until']) > time();
// Node.js 18+
import crypto from 'node:crypto';
// kid => raw public key (Base64): the active key and the standby "next" key
const KEYS = {"k1":"5Uk3p1+J0PXzJkwS4wVFvTN9GcHpJzX5ClRI8zlI0yQ=","k2":"erOiojOdS5F/IfhPMO9gvjAvuEPVapIadTDaWU0z83o="};
const publicKey = (kid) => KEYS[kid] && crypto.createPublicKey({
format: 'jwk',
key: { kty: 'OKP', crv: 'Ed25519', x: Buffer.from(KEYS[kid], 'base64').toString('base64url') },
});
async function sellmycodeLicense(action, fields) {
const nonce = crypto.randomBytes(16).toString('hex');
let res;
try {
const r = await fetch('https://sellmycode.net/api/license/' + action, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ...fields, nonce }),
});
res = await r.json();
} catch { return null; }
if (!res.payload || !res.signature) return null;
const key = publicKey(res.kid);
if (!key) return null;
const ok = crypto.verify(null, Buffer.from(res.payload), key, Buffer.from(res.signature, 'base64'));
if (!ok) return null;
const data = JSON.parse(res.payload);
if (data.nonce !== nonce) return null;
// one key signs for every product on SellMyCode: check the item and the site too
if (data.item && data.item.id !== fields.item_id) return null;
const host = new URL(fields.domain.includes('://') ? fields.domain : 'http://' + fields.domain).hostname.replace(/^www\./, '');
if (data.domain && data.domain !== host) return null;
return data;
}
// fields always carry your item_id
const r = await sellmycodeLicense('verify', { purchase_code: code, item_id: 12345, domain: 'example.com' });
# Python 3 + requests + cryptography
import base64, json, secrets, requests
from urllib.parse import urlparse
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
# kid => raw public key (Base64): the active key and the standby "next" key
KEYS = {"k1":"5Uk3p1+J0PXzJkwS4wVFvTN9GcHpJzX5ClRI8zlI0yQ=","k2":"erOiojOdS5F/IfhPMO9gvjAvuEPVapIadTDaWU0z83o="}
def sellmycode_license(action, fields):
nonce = secrets.token_hex(16)
try:
res = requests.post("https://sellmycode.net/api/license/" + action, json=dict(fields, nonce=nonce), timeout=15).json()
key = Ed25519PublicKey.from_public_bytes(base64.b64decode(KEYS[res["kid"]]))
key.verify(base64.b64decode(res["signature"]), res["payload"].encode())
except Exception:
return None # unreachable, unsigned or forged
data = json.loads(res["payload"])
if data.get("nonce") != nonce:
return None
# one key signs for every product on SellMyCode: check the item and the site too
if "item" in data and data["item"]["id"] != fields["item_id"]:
return None
host = urlparse(fields["domain"] if "://" in fields["domain"] else "http://" + fields["domain"]).hostname or ""
if "domain" in data and data["domain"] != host.removeprefix("www."):
return None
return data
# fields always carry your item_id
r = sellmycode_license("verify", {"purchase_code": code, "item_id": 12345, "domain": "example.com"})
#Error codes
| Error code | HTTP | Meaning |
|---|---|---|
invalid_code |
403 | unknown, refunded or cancelled purchase code — or a code of another item than item_id (deliberately indistinguishable) |
activation_limit_reached |
403 | every slot is taken (paused sites included) — show hint and transfer_url; the author can free one |
license_blocked |
403 | the author blocked this whole licence over abuse — stop the licensed features and show the hint and transfer_url |
site_blocked |
403 | the author blocked this domain for the licence — it cannot activate again and still holds its slot (slot_bound = true); other domains of the code are unaffected |
not_activated |
403 | this domain is not licensed right now: never activated, paused (slot_bound = true — activate again) or revoked by the author (slot_released = true) |
invalid_activation_token |
403 | deactivate: the token does not belong to this site |
invalid_request |
400 | a parameter is missing or malformed — most often the nonce or item_id |
invalid_domain |
400 | the domain could not be parsed |
rate_limited |
429 | slow down and retry after retry_after seconds — not a licence problem, keep your cached state |
signing_unavailable |
503 | temporary, and the only unsigned answer — keep your cached state |
#Limits
30 calls per 10 minutes for each licence + domain, and 30 FAILED lookups per 10 minutes per IP. Valid calls do not count against the IP, so many sites sharing one hosting IP are not blocked.
Note: Set the number of allowed sites per licence when you publish the item (Activation limit, separately for Regular and Extended). Leave it empty for unlimited.
Developers