Skip to content
Verified

Read and summarize your logs

Pull a window of request logs, then the same window as grouped counts, for a status page or a support reply.

get_logs reads back the same account_log documents every call to /cpi writes for you, scoped to your own account: what was called, from where, and what came back. get_logs_counts answers a narrower question over the same window, how many, grouped, which is cheaper than paging through every row yourself when a support reply or a status widget only needs the shape of a period, not its detail.

Methods

POST/cpi/get_logs
user

Get Logs

Queries logs of a given type within a timestamp range, with optional search, paging, and status filters.

POST/cpi/get_logs_counts
user

Get Logs Counts

Returns grouped log counts by request type or response status within a timestamp range.

Walkthrough

Read a window of entries

log_type, log_date_from and log_date_to are the only declared fields, but the handler also reads an undeclared log_search (free text over the request/response bodies and headers) and log_status ('success' or 'failed', by HTTP status band). log_type: "account_log" scopes to this account automatically, you never pass uid yourself.

curl -s https://xuda.ai/cpi/get_logs \
  -H 'content-type: application/json' \
  -d '{
    "api_key": "YOUR_API_KEY",
    "log_type": "account_log",
    "log_date_from": 1735689600000,
    "log_date_to": 1738368000000,
    "log_status": "failed"
  }'
const res = await fetch('https://xuda.ai/cpi/get_logs', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    log_type: 'account_log',
    log_date_from: Date.UTC(2025, 0, 1),
    log_date_to: Date.UTC(2025, 1, 1),
    log_status: 'failed',
  }),
});
const { code, data } = await res.json();
if (code > 0) for (const row of data.docs) console.log(row.method, row.response_status_code);
import requests

res = requests.post(
    'https://xuda.ai/cpi/get_logs',
    json={
        'api_key': 'YOUR_API_KEY',
        'log_type': 'account_log',
        'log_date_from': 1735689600000,
        'log_date_to': 1738368000000,
        'log_status': 'failed',
    },
)
body = res.json()
if body['code'] > 0:
    for row in body['data']['docs']:
        print(row['method'], row['response_status_code'])

2. Get the same window as grouped counts

get_logs_counts also needs an undeclared request_type or response_status value to pick which grouped view it reads; sending neither is a refusal, not an empty result (see Errors). request_type is the log's own request_type field, 'POST' for every account_log row add_account_log writes today. The grouping key response_status builds against lives in a view definition this repo does not carry, confirm the values your own rows group under with get_logs first rather than guessing one.

curl -s https://xuda.ai/cpi/get_logs_counts \
  -H 'content-type: application/json' \
  -d '{
    "api_key": "YOUR_API_KEY",
    "log_type": "account_log",
    "log_date_from": 1735689600000,
    "log_date_to": 1738368000000,
    "request_type": "POST"
  }'
const res = await fetch('https://xuda.ai/cpi/get_logs_counts', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    log_type: 'account_log',
    log_date_from: Date.UTC(2025, 0, 1),
    log_date_to: Date.UTC(2025, 1, 1),
    request_type: 'POST',
  }),
});
const { code, data } = await res.json();
import requests

res = requests.post(
    'https://xuda.ai/cpi/get_logs_counts',
    json={
        'api_key': 'YOUR_API_KEY',
        'log_type': 'account_log',
        'log_date_from': 1735689600000,
        'log_date_to': 1738368000000,
        'request_type': 'POST',
    },
)
body = res.json()

The response

get_logs passes a Mango find result straight through, docs plus a bookmark for the next page:

json
{
  "code": 1,
  "data": {
    "docs": [
      {
        "_id": "log_9c21ff",
        "docType": "account_log",
        "ts": 1737042311422,
        "method": "create_contact",
        "source": "api",
        "channel": "api",
        "api_pk": "pk_7f2a...",
        "req_body": { "name": "Priya Shah", "email": "[email protected]" },
        "response_status_code": 200,
        "response_data": "{\"contact_id\":\"cnt_a91f0e\"}",
        "user_email": "[email protected]",
        "date_created": 1737042311422
      }
    ],
    "bookmark": "g1AAAABweJzLYWBg..."
  }
}

get_logs_counts passes a raw CouchDB grouped-view result through instead, rows of { key, value } where value is the count for that key. Which fields make up key is set by the view itself, not by this handler; treat it as an opaque group id and read value for the number.

Errors

Next