Sample Code

This page uses the web moderation task submission API as an example to show how to generate a signature and send a request.

For the API specification, see Web Moderation Task Submission.

For the signature rule, see Request Signature.

curl Example

curl -X POST 'https://msafe.ilivedata.com/api/v1/media/web/submit' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Accept: application/json;charset=UTF-8' \
  -H 'X-AppId: 82100001' \
  -H 'X-TimeStamp: 2026-01-31T07:59:03Z' \
  -H 'Authorization: *****' \
  -d '{"url":"https://example.com/page.html","strategyId":"DEFAULT"}'

The Authorization value must be calculated from the request body, request path, X-AppId, and X-TimeStamp. Do not use ***** directly.

Python Example

The following example uses the Python standard library to generate the signature and submit a web moderation task.

import base64
import hashlib
import hmac
import json
import urllib.request
from datetime import datetime, timezone


APP_ID = "82100001"
SECRET_KEY = "your_secret_key"
HOST = "msafe.ilivedata.com"
URI = "/api/v1/media/web/submit"
URL = f"https://{HOST}{URI}"

body = {
    "url": "https://example.com/page.html",
    "strategyId": "DEFAULT",
}

json_body = json.dumps(body, separators=(",", ":"), ensure_ascii=False)
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
body_hash = hashlib.sha256(json_body.encode("utf-8")).hexdigest()

string_to_sign = "\n".join([
    "POST",
    HOST,
    URI,
    body_hash,
    f"X-AppId:{APP_ID}",
    f"X-TimeStamp:{timestamp}",
])

authorization = base64.b64encode(
    hmac.new(
        SECRET_KEY.encode("utf-8"),
        string_to_sign.encode("utf-8"),
        hashlib.sha256,
    ).digest()
).decode("utf-8")

request = urllib.request.Request(
    URL,
    data=json_body.encode("utf-8"),
    method="POST",
    headers={
        "Content-Type": "application/json;charset=UTF-8",
        "Accept": "application/json;charset=UTF-8",
        "X-AppId": APP_ID,
        "X-TimeStamp": timestamp,
        "Authorization": authorization,
    },
)

with urllib.request.urlopen(request, timeout=10) as response:
    print(response.status)
    print(response.read().decode("utf-8"))

Successful response example:

{
  "errorCode": 0,
  "taskId": "task_**************************",
  "status": "PROCESSING"
}