Menu

API integration

Scenario: backend + hosted flow

A complete backend for the hosted link, iframe or mobile SDK integration: create the session, hand over the link, receive the webhook and act on the decision. Replace the functions you do not have (save_session, remember_event, enqueue, mark_verified …) with your own database and job queue.

What happensEnd userYour backendIDottaEnd userYour backendIDotta1. POST /kyc/start2. POST /v1/sessions3. 201 session_id + sdk_url4. sdk_url5. Document + liveness in the WebSDK6. webhook session.approved7. GET /v1/sessions/{id}8. status: approved
# Python 3.10+   pip install flask requests   run: flask --app server run
import json, os, uuid
import requests
from flask import Flask, abort, request

API = "https://api.idotta.com"
API_KEY = os.environ["IDOTTA_API_KEY"]                # idv_test_… / idv_live_… (server only)
WEBHOOK_SECRET = os.environ["IDOTTA_WEBHOOK_SECRET"]  # whsec_…
app = Flask(__name__)

def idotta(method, path, **kw):
    r = requests.request(method, API + path, headers={"X-Api-Key": API_KEY, **kw.pop("headers", {})}, timeout=15, **kw)
    r.raise_for_status()
    return r.json()

# 1) The user clicks "Verify": create the session on your backend
@app.post("/kyc/start")
def kyc_start():
    user_id = request.json["user_id"]           # your own user id
    key = str(uuid.uuid4())                     # one key per new session
    for attempt in range(3):                    # a timed-out create is safe to repeat with the same key
        try:
            s = idotta("POST", "/v1/sessions", headers={"Idempotency-Key": key},
                       json={"applicant_external_id": user_id, "modules": ["document", "liveness"]})
            break
        except (requests.ConnectionError, requests.Timeout):
            if attempt == 2: raise
    save_session(user_id, s["session_id"], s["status"])   # your database
    return {"sdk_url": s["sdk_url"]}            # 2) redirect, new tab or iframe

# 3) The decision arrives as a signed webhook
@app.post("/webhooks/idotta")
def webhook():
    raw = request.get_data()                    # raw bytes: do not re-serialise the JSON
    if not verify(raw, request.headers.get("X-Signature"), WEBHOOK_SECRET):
        abort(400)
    event = json.loads(raw)
    if not remember_event(event["event_id"]):   # False = already processed (retries repeat events)
        return "", 200
    if event.get("session_id"):
        enqueue(sync_session, event["session_id"])   # answer within 10 s, work in the background
    return "", 200

# 4) Act on the current status read from the API (so event order does not matter)
def sync_session(session_id):
    s = idotta("GET", f"/v1/sessions/{session_id}")
    status = s["status"]
    if status == "approved":
        mark_verified(s["applicant_external_id"])
    elif status == "declined":
        mark_declined(s["applicant_external_id"])          # final: no retry in this session
    elif status == "in_review":
        mark_pending(s["applicant_external_id"])           # an analyst decides; another webhook follows
    elif status == "resubmitted":                          # an analyst asked for steps again
        link = idotta("POST", f"/v1/sessions/{session_id}/sdk-link", json={})
        send_link_to_user(s["applicant_external_id"], link["sdk_url"])
    elif status in ("expired", "abandoned"):
        allow_new_attempt(s["applicant_external_id"])      # create a new session when the user returns

import hashlib, hmac, time

def verify(raw_body: bytes, header: str | None, secret: str) -> bool:
    try:
        parts = dict(p.split("=", 1) for p in (header or "").split(","))
        t = int(parts["t"])
    except (KeyError, ValueError):
        return False
    if abs(time.time() - t) > 300:  # 5 min: rejects a replayed old request
        return False
    signed = f"{t}.".encode() + raw_body  # the raw bytes: do not re-serialise the JSON
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(parts.get("v1", ""), expected)

Every branch

YOU RECEIVESTATUSDO THIS
session.approvedapprovedLet the user in. decision.decided_by: auto, manual or reuse. An analyst can still reverse it: then session.rejected follows
session.manual_reviewin_reviewShow "we are checking". The session does not expire; session.approved or session.rejected follows
session.rejecteddeclinedNo retry in this session; create a new one only if your policy allows. An analyst can still reverse it: then session.approved follows
document.rejected · liveness.failedin_progressNothing: the user retries in the SDK (3 retries). With declined instead, session.rejected follows
session.resubmittedresubmittedSend the user a new link: POST /v1/sessions/{id}/sdk-link
session.expiredexpired · abandonedCreate a new session when the user returns
User came back after 15 minnot_started · in_progressThe link's token expired, the session did not: POST /v1/sessions/{id}/sdk-link (the old token stops working)
session.kyc_expiredkyc_expiredAsk for re-verification with a new session
applicant.aml_alert—Ongoing monitoring hit for an approved user (no session_id); review it in the panel
wallet_screening.completed—A DotAML wallet screening finished (async or bulk). Body: screening_id, status, score, level, outcome, recommended_action, your customer_id and timestamps — no session_id, no address or counterparty; fetch the full report with GET /v1/wallet-screenings/{id}
wallet_screening.failed—A DotAML wallet screening could not be produced (data sources exhausted); it is not charged. Screen the address again in a few minutes

Missed a webhook (your server was down)? GET /v1/webhooks/deliveries lists what was sent and failed; fetch those sessions with GET /v1/sessions/{id}.