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.
# 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 RECEIVE | STATUS | DO THIS |
|---|---|---|
session.approved | approved | Let the user in. decision.decided_by: auto, manual or reuse. An analyst can still reverse it: then session.rejected follows |
session.manual_review | in_review | Show "we are checking". The session does not expire; session.approved or session.rejected follows |
session.rejected | declined | No 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.failed | in_progress | Nothing: the user retries in the SDK (3 retries). With declined instead, session.rejected follows |
session.resubmitted | resubmitted | Send the user a new link: POST /v1/sessions/{id}/sdk-link |
session.expired | expired · abandoned | Create a new session when the user returns |
| User came back after 15 min | not_started · in_progress | The link's token expired, the session did not: POST /v1/sessions/{id}/sdk-link (the old token stops working) |
session.kyc_expired | kyc_expired | Ask 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}.