דילוג לתוכן
אומת

קריאה וסיכום של הלוגים

שליפת חלון של לוגי בקשות, ואז אותו חלון כספירות מקובצות, לדף סטטוס או לתשובת תמיכה.

get_logs קוראת בחזרה את אותם מסמכי account_log שכל קריאה ל-/cpi כותבת בשבילכם, ברמת החשבון שלכם בלבד: מה נקרא, מאיפה, ומה חזר. get_logs_counts עונה על שאלה צרה יותר על אותו חלון, כמה, מקובץ, וזה זול יותר מלדפדף בכל שורה בעצמכם כשתשובת תמיכה או וידג'ט סטטוס צריכים רק את צורת התקופה ולא את פרטיה.

שיטות

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.

הדרכה צעד אחר צעד

קוראים חלון של רשומות

log_type, log_date_from ו-log_date_to הם השדות היחידים המוצהרים, אבל ה-handler קורא גם log_search לא מוצהר (טקסט חופשי על גופי הבקשה והתשובה ועל הכותרות) ואת log_status ('success' או 'failed', לפי טווח סטטוס HTTP). log_type: "account_log" מצמצם לחשבון הזה אוטומטית, אתם אף פעם לא מעבירים uid בעצמכם.

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_logs_counts צריכה גם היא ערך לא מוצהר request_type או response_status כדי לבחור איזו תצוגה מקובצת לקרוא; שליחה של אף אחד מהם היא סירוב, לא תוצאה ריקה (ראו שגיאות). request_type הוא שדה request_type של הלוג עצמו, 'POST' לכל שורת account_log ש-add_account_log כותבת כיום. מפתח הקיבוץ ש-response_status בונה לפיו נמצא בהגדרת תצוגה שהמאגר הזה לא נושא, כדאי לאשר איזה ערכים השורות שלכם מקובצות תחתם עם get_logs קודם, ולא לנחש אחד.

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()

התשובה

get_logs מעבירה תוצאת find של Mango ישירות, docs ועוד bookmark לעמוד הבא:

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 מעבירה במקום זאת תוצאה גולמית של תצוגה מקובצת ב-CouchDB, rows של { key, value } כש-value הוא הספירה של אותו מפתח. אילו שדות מרכיבים את key נקבע על ידי התצוגה עצמה, לא על ידי ה-handler הזה; יש להתייחס אליו כאל מזהה קבוצה אטום ולקרוא את value בשביל המספר.

שגיאות

הבא