01
Get a key
The API is on paid plans (Ruly, Pro and Enterprise). An admin of your business opens API and webhooks in the Ruly app and makes a key. A key belongs to one business and only ever sees that business's records. A business can have 5 active keys at a time; make one per website or system so you can revoke one without touching the others.
The full key is shown once, right after you make it. Ruly keeps only a scrambled copy (a hash), so it can't show it again. If you lose it, revoke it and make a new one. A revoked key stops working at once.
Keep keys on your server. Never put a key in website or app code that browsers or phones download, and never in an address: the API refuses a key sent in the query string, because addresses end up in logs. The API sends no CORS headers, so browser code can't call it.
02
Authentication, limits and errors
Send the key in the Authorization header on every call. Bodies are JSON. Every response has Cache-Control: no-store.
Each key can make 1,000 calls an hour. Past that you get 429 with a Retry-After header in seconds. One address that sends 30 wrong keys in an hour also gets 429 for the rest of that hour. If your business moves to the free plan, calls get 403 with code plan.
Every error has the same shape: an error object with a code you can branch on and a message you can show. Messages for a yes are the same ones a person sees on a Ruly consent link, in the language you send.
| Status | Code | When |
|---|---|---|
| 400 | bad_json, bad_query | The body isn't a JSON object, or a query value is wrong |
| 401 | no_key, bad_key, key_in_url | No key, a wrong or revoked key, or a key in the address |
| 403 | plan, full | The business is on the free plan, or it can't take new records right now |
| 404 | not_found, purpose_closed, no_route | No record with that id in this business, a purpose that isn't live, or no such endpoint |
| 422 | name, contact, agreed, parent_needed | A field is missing or wrong, or the purpose is for children |
| 429 | rate_limit | Over 1,000 calls in the last hour for this key, or 30 wrong keys from one address |
| 503 | unavailable | Ruly couldn't answer right now. Try again in a minute |
export RULY_KEY="ruly_live_..." # from API and webhooks in the Ruly app
curl https://ruly.in/api/v1/purposes \
-H "Authorization: Bearer $RULY_KEY"{
"error": {
"code": "contact",
"message": "Please add your phone number or email."
}
}03
List purposes
GET purposes returns the consent links that can take a yes right now, the address of your public privacy page, and the version of your latest privacy notice. Use a purpose id when you record a yes. A purpose with minors true is for children: a parent has to confirm on the Ruly consent link, so the API can't record it.
curl https://ruly.in/api/v1/purposes \
-H "Authorization: Bearer $RULY_KEY"{
"privacy_page_url": "https://ruly.in/p/sharma-dental",
"notice_version": 3,
"data": [
{ "id": "c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6", "name": "Appointment reminders on WhatsApp", "minors": false }
]
}04
Record a yes
POST yeses records a yes from your own form. Ruly checks it under the same rules as a consent link: a name, a phone number or email, agreed set to true (the person ticked the box themselves), and a live purpose of your business. It is saved against your latest privacy notice with source api, the person gets the same receipt email with their withdraw link when the contact is an email, and you get the withdraw link back.
The API sends at most 10 emails a day for your account, across all its businesses. Every email counts: a receipt is one, and a withdrawal alert is one for each person it tells. Past that the yes or withdrawal still saves and shows in the app, and receipt_emailed is false: send the withdraw link to the person yourself. On a busy day an email the API sets off can wait in line and go out a little later.
Show the person your privacy notice, or link your privacy page, next to the box before they tick it. Send lang (en, hi and the other languages your notice has) to save the language they read it in; error messages come back in that language too.
curl -X POST https://ruly.in/api/v1/yeses \
-H "Authorization: Bearer $RULY_KEY" \
-H "Content-Type: application/json" \
-d '{
"purpose_id": "c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6",
"name": "Asha Rao",
"contact": "asha@example.com",
"agreed": true,
"lang": "en"
}'{
"id": "7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97",
"purpose_id": "c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6",
"notice_version": 3,
"created_at": "2026-12-02T10:15:04.512Z",
"withdraw_url": "https://ruly.in/p/sharma-dental/w/7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97.Xq3v",
"receipt_emailed": true
}05
Record a withdrawal
POST yeses/{id}/withdraw records that the person withdrew, for example from your own app's settings. Ruly saves it with withdrawn_via api and sends your business the usual withdrawal alert. Calling it again for the same yes is safe: you get 200 with already set to true and the first time.
curl -X POST https://ruly.in/api/v1/yeses/7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97/withdraw \
-H "Authorization: Bearer $RULY_KEY"{
"withdrawn_at": "2026-12-09T08:02:11.004Z",
"already": false
}06
Read yeses
GET yeses lists yeses newest first, 50 a page (limit 1 to 100). Filter with contact (an email, or a phone number in any format) and purpose_id. For the next page, send the next value as before; next is null on the last page. You can also send a time as before. GET yeses/{id} returns one. Erased people are never returned.
Each read that returns people's details is written to your access log as API key, under the person who made the key.
curl "https://ruly.in/api/v1/yeses?contact=asha@example.com&limit=20" \
-H "Authorization: Bearer $RULY_KEY"{
"data": [
{
"id": "7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97",
"purpose_id": "c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6",
"name": "Asha Rao",
"contact": "asha@example.com",
"lang": "en",
"source": "api",
"notice_version": 3,
"created_at": "2026-12-02T10:15:04.512Z",
"withdrawn_at": "2026-12-09T08:02:11.004Z",
"withdrawn_via": "api",
"withdraw_url": "https://ruly.in/p/sharma-dental/w/7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97.Xq3v"
}
],
"next": null
}curl https://ruly.in/api/v1/yeses/7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97 \
-H "Authorization: Bearer $RULY_KEY"07
Read requests
GET requests lists the requests people sent through your privacy page (to see, correct or delete their data, withdraw, name someone, or complain), newest first, with the same limit, before and next. Filter with status: open, in_progress, done or rejected. due_at is when your reply is due.
curl "https://ruly.in/api/v1/requests?status=open" \
-H "Authorization: Bearer $RULY_KEY"{
"data": [
{
"id": "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b",
"kind": "delete",
"status": "open",
"name": "Asha Rao",
"contact": "asha@example.com",
"details": "Please delete my records.",
"due_at": "2027-01-01T10:20:00+00:00",
"created_at": "2026-12-02T10:20:00+00:00",
"closed_at": null
}
],
"next": null
}08
Webhooks
An admin saves one https address for your business under API and webhooks in the app. Ruly sends it a POST with a JSON body when something happens, whether it came from a consent link, the app or the API. Addresses must be https on the usual port and can't point to a private or internal network. Redirects aren't followed.
Answer with any 2xx status within 5 seconds. Anything else, or no answer, counts as failed: Ruly tries again 1 hour, then 6 hours, then 24 hours later, and after that marks the delivery failed. The app shows the last 20 deliveries with each result, and has a Send a test button that sends a ping event. An admin can pick Send again on a failed delivery to send it once more, say after your server was down. That is one try: if it fails, the delivery stays failed with no more retries. Tests and resends together are 10 an hour.
The body is built when it is sent. If a person's record was erased in the meantime, nothing is sent for it.
| Event | When | data |
|---|---|---|
| yes.created | Someone said yes: on a consent link, a parent's confirmation, a yes added in the app, or through the API | The yes, same shape as GET yeses/{id} |
| yes.withdrawn | Someone withdrew: on the withdraw page, in the app or through the API | The yes, with withdrawn_at and withdrawn_via |
| request.created | Someone sent a request through your privacy page | The request, same shape as GET requests |
| ping | An admin pressed Send a test | A short message |
Content-Type: application/json
User-Agent: Ruly-Webhooks/1.0 (+https://ruly.in/docs/api)
Ruly-Event: yes.withdrawn
Ruly-Delivery: 5f6e7d8c-9b0a-4c1d-8e2f-3a4b5c6d7e8f
Ruly-Signature: t=1765274531,v1=4d2c...e91a{
"id": "5f6e7d8c-9b0a-4c1d-8e2f-3a4b5c6d7e8f",
"event": "yes.withdrawn",
"created_at": "2026-12-09T08:02:11.120Z",
"data": {
"id": "7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97",
"purpose_id": "c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6",
"name": "Asha Rao",
"contact": "asha@example.com",
"lang": "en",
"source": "api",
"notice_version": 3,
"created_at": "2026-12-02T10:15:04.512Z",
"withdrawn_at": "2026-12-09T08:02:11.004Z",
"withdrawn_via": "api",
"withdraw_url": "https://ruly.in/p/sharma-dental/w/7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97.Xq3v"
}
}09
Check the signature
Every webhook carries Ruly-Signature: t is the time it was signed in unix seconds, and v1 is the HMAC-SHA256, in hex, of t, a dot, and the exact body, made with your business's signing secret. The secret is random and made when you add the webhook. Only admins see it, under API and webhooks in the app. Keep it on your server like a key.
Check the signature on the raw body before you parse it, compare in constant time, and refuse a t more than 5 minutes from now. Make a new secret in the app if it ever leaks: the old one stops working at once, so put the new one on your server straight after. Removing the webhook and adding it again also gives a new secret.
import { createHmac, timingSafeEqual } from "node:crypto";
// rawBody is the request body exactly as it arrived, as a string. Parse the JSON only after this returns true.
export function verifyRuly(rawBody, header, secret) {
const parts = Object.fromEntries(String(header ?? "").split(",").map((p) => p.split("=")));
const t = Number(parts.t);
// Refuse a t older (or newer) than 5 minutes, so an old delivery can't be sent to you again.
if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > 300) return false;
const want = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest();
const got = Buffer.from(parts.v1 ?? "", "hex");
return got.length === want.length && timingSafeEqual(got, want);
}import express from "express";
import { verifyRuly } from "./verify-ruly.js";
const app = express();
// express.raw keeps the body as bytes, so the signature is checked on exactly what Ruly sent.
app.post("/ruly-webhook", express.raw({ type: "application/json" }), (req, res) => {
const ok = verifyRuly(req.body.toString("utf8"), req.get("Ruly-Signature"), process.env.RULY_WEBHOOK_SECRET);
if (!ok) return res.sendStatus(400);
const event = JSON.parse(req.body.toString("utf8"));
// event.id is the same on every retry of one delivery: skip it if you've handled it already.
if (event.event === "yes.withdrawn") {
// stop using event.data.contact for event.data.purpose_id
}
res.sendStatus(200);
});