ruly

Developers

Ruly's consent screen in your app

Updated 2 December 2026

On paid plans, your server asks Ruly for a consent screen, your app opens it in a webview, and the person reads your notice and ticks each purpose on Ruly's screen in their language. Ruly then sends the app to a return address you registered, with a signed answer your server confirms with one call.

01

How it works

The screen is on paid plans (Ruly, Pro and Enterprise), like the rest of the API. It uses the same API keys and the same rules as a Ruly consent link: every yes it records is a normal yes, with a withdraw link and a yes.created webhook. Receipt emails for screen yeses count toward the same 10 emails a day as the API: past that the yes still saves without a receipt email.

  • 1. Register a return address

    An admin adds it on the Mobile app consent card under API and webhooks in the Ruly app: an https address on your own domain or your app's own scheme, such as myapp://consent. Up to 5. The address can't already use the names session, status, state, t or sig.

  • 2. Your server starts a screen

    It calls POST consent-sessions with your secret key, the purposes to ask for and the return address. Ruly answers with a url that works for 30 minutes.

  • 3. Your app opens the url

    In a webview, or in Custom Tabs on Android or ASWebAuthenticationSession on iOS. The person sees your business name, your notice, one unticked box per purpose and a language picker.

  • 4. Ruly sends the app back

    After I agree or Not now, the screen goes to your return address with session, status, state, t and sig. Your app catches that address and stops there.

  • 5. Your server confirms

    The app hands the address to your server. The server checks sig, or calls GET consent-sessions/{id}, and only then treats the answer as given.

02

Keep secrets on your server

Your secret API key and your webhook signing secret stay on your server. Never put either one in app code: anyone can pull them out of an app download. The app only ever sees the screen url and the return address.

Don't trust the return address alone in the app. Anyone can open your app's scheme with any query. Your server decides, with the sig check or the confirm call below.

03

Start a screen

POST consent-sessions with purpose_ids (1 to 10 live purposes of your business, from GET purposes), redirect_uri (one of your return addresses, exactly as it shows on the card), and optionally state, name, contact and lang.

state is any text up to 200 characters that comes back to you unchanged, such as your own user id or a random value you check on return. name and contact follow the consent link's rules (up to 120 and 160 characters, a 10 digit phone number or an email). state, name and contact are plain text: no line breaks or other control characters. Send them if you know them and the screen shows them filled in; leave them out and the screen asks. lang picks the screen's first language; the person can change it.

A purpose for children can't use this screen: a parent has to confirm on the Ruly consent link. You need a published privacy notice, because the screen shows it.

Request (from your server)
curl -X POST https://ruly.in/api/v1/consent-sessions \
  -H "Authorization: Bearer $RULY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "purpose_ids": ["c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6"],
    "redirect_uri": "myapp://consent",
    "state": "user-8841",
    "name": "Asha Rao",
    "contact": "asha@example.com",
    "lang": "hi"
  }'
201 response
{
  "id": "3f9a7c21-6b4e-4d8a-9c15-7e2b0d4f8a63",
  "url": "https://ruly.in/p/sharma-dental/app/3f9a7c21-6b4e-4d8a-9c15-7e2b0d4f8a63.Kq7w",
  "expires_at": "2026-12-02T10:45:04.512Z"
}

04

Open it in your app

Load url in a webview and watch every address it goes to. When it reaches your return address, stop loading, close the screen and send the full address to your server. These are short sketches: myapp://consent stands for your own return address, and sendToServer for your own call.

Custom Tabs on Android and ASWebAuthenticationSession on iOS work too, and show the address bar so the person can see the page is on ruly.in.

Android WebView
// Kotlin, android.webkit.WebView
webView.webViewClient = object : WebViewClient() {
  override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
    val url = request.url.toString()
    if (url.startsWith("myapp://consent")) {
      // Send url to your server: it checks the answer, then tell the app what happened.
      sendToServer(url)
      finish()
      return true
    }
    return false
  }
}
webView.settings.javaScriptEnabled = true
webView.loadUrl(screenUrl) // the url your server got from Ruly
iOS WKWebView
// Swift, WKWebView
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction,
             decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
  if let url = navigationAction.request.url, url.scheme == "myapp", url.host == "consent" {
    // Send url to your server: it checks the answer, then tell the app what happened.
    sendToServer(url.absoluteString)
    dismiss(animated: true)
    decisionHandler(.cancel)
    return
  }
  decisionHandler(.allow)
}

webView.navigationDelegate = self
webView.load(URLRequest(url: URL(string: screenUrl)!))
React Native
// React Native, react-native-webview
<WebView
  source={{ uri: screenUrl }}
  onShouldStartLoadWithRequest={(req) => {
    if (req.url.startsWith("myapp://consent")) {
      // Send req.url to your server: it checks the answer, then tell the app what happened.
      sendToServer(req.url);
      navigation.goBack();
      return false;
    }
    return true;
  }}
/>

05

The return address

Ruly adds session, status (agreed or declined), state (empty if you sent none), t (the time in unix seconds) and sig to your return address. If your address already has a query, it is kept and these come after it. Values are URL encoded, so read them with a URL parser.

sig is the HMAC-SHA256, in hex, of t, session, status and state joined with dots, made with your webhook signing secret (the same one that signs webhooks, under API and webhooks in the app). If your business has no webhook yet there is no signing secret, so there is no sig: confirm with the GET call instead.

If you remove a return address, screens started with it close and send nothing back. If the screen sits unanswered for 30 minutes it closes, and the person sees a message to go back to the app. Nothing comes back to your address: start a new screen.

Return address
myapp://consent?session=3f9a7c21-6b4e-4d8a-9c15-7e2b0d4f8a63&status=agreed&state=user-8841&t=1764671104&sig=9be1...04c7
verify-ruly-return.js (Node 18 or later, on your server)
import { createHmac, timingSafeEqual } from "node:crypto";

// returnUrl is the full address your app was sent back to. Run this on your server, never in the app.
export function verifyRulyReturn(returnUrl, secret) {
  const q = new URL(returnUrl).searchParams;
  const t = Number(q.get("t"));
  // Refuse a t older than 10 minutes (or more than a minute ahead), so an old answer can't be sent to you again.
  const age = Date.now() / 1000 - t;
  if (!Number.isInteger(t) || age > 600 || age < -60) return false;
  // Only Ruly's own shapes, so no value can borrow a dot from another one.
  if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(q.get("session") ?? "")) return false;
  if (!["agreed", "declined"].includes(q.get("status"))) return false;
  const signed = [q.get("t"), q.get("session"), q.get("status"), q.get("state") ?? ""].join(".");
  const want = createHmac("sha256", secret).update(signed).digest();
  const got = Buffer.from(q.get("sig") ?? "", "hex");
  return got.length === want.length && timingSafeEqual(got, want);
}

06

Confirm the answer

GET consent-sessions/{id} is the answer to trust. status is open, agreed, declined or expired. consent_ids are the yeses the person gave, one per ticked purpose: read each with GET yeses/{id}, or wait for its yes.created webhook. A session of another business gives 404. Sessions are kept for 30 days; the yeses stay like any other yes.

Request (from your server)
curl https://ruly.in/api/v1/consent-sessions/3f9a7c21-6b4e-4d8a-9c15-7e2b0d4f8a63 \
  -H "Authorization: Bearer $RULY_KEY"
200 response
{
  "id": "3f9a7c21-6b4e-4d8a-9c15-7e2b0d4f8a63",
  "status": "agreed",
  "purpose_ids": ["c4e9a1d2-3b7f-4e85-a6c0-91d2f3b4a5e6"],
  "consent_ids": ["7b0c2f8e-5d1a-4c3b-9e6f-2a8d4b1c0e97"],
  "state": "user-8841",
  "created_at": "2026-12-02T10:15:04.512Z",
  "expires_at": "2026-12-02T10:45:04.512Z",
  "done_at": "2026-12-02T10:16:40.031Z"
}

07

Errors

Errors have the same shape as the rest of the API: an error object with a code and a message. Keys, plans and limits work as on the API docs.

StatusCodeWhen
400purpose_idspurpose_ids is missing, empty, or has more than 10
400redirect_not_registeredredirect_uri is missing or isn't one of your return addresses, matched exactly
400statestate isn't text, or is over 200 characters
403planThe business is on the free plan
404purpose_closed, not_foundA purpose that isn't live in this business, or no session with that id in this business
409no_noticeThe business hasn't published a privacy notice yet
422name, contact, parent_neededname or contact is wrong, or a purpose is for children

This is general information, not legal advice. For your exact case, talk to a lawyer.

Questions people ask, answered

Which plans have the app consent screen?+

Paid plans: Ruly, Pro and Enterprise, the same as the API.

Can my app call Ruly directly?+

No. Starting a screen needs your secret key, so your server makes that call and gives the app only the url. The app sends the return address back to your server to check.

Does the screen set cookies or open new tabs?+

No. It sets no cookies and opens nothing in a new tab, so it works inside a plain webview. The full notice opens on the same screen.

What if the person taps I agree twice?+

Each purpose is recorded once. The second tap finds the screen already answered.

Keep reading

Know where you stand in 2 minutes.

Answer 12 plain questions about your business. Get a score, what is missing, and a to-do list for 13 May 2027. Free, no sign up.