How to fetch audit logs via REST API beyond 1000 record limitation


プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。

*Fisheye および Crucible は除く

目的

Confluence’s audit log system restricts access to a maximum of 1000 records per request through its API endpoint /rest/api/audit. To retrieve more than 1000 records, we can employ pagination, making multiple API calls to sequentially gather additional sets of logs.


環境

Confluence 7.19.x

ソリューション

The below command can fetch audit logs from 1 to 1000 records. However, this endpoint is limited to 1000 records and can't be used for accessing all the available audit logs. This is due to the API endpoint  /rest/api/audit limitation.

curl -u <id>:<pass> -X GET "<Base_URL>/rest/api/audit?limit=1&start=1000" -H "Accept: application/json"


We can use the script below to fetch records iteratively beyond the 1000 limit. Please note the username, password, and base_url values must be changed.

#!/bin/bash

USERNAME="username"
PASSWORD="password"
API_ENDPOINT="<base_url>/rest/api/audit"
LIMIT=1000
TOTAL_RECORDS=10000

start=0
iteration=1

while [ $start -lt $TOTAL_RECORDS ]
do
    echo "Iteration: $iteration"

    current_limit=$((start + LIMIT))
    response=$(curl -u $USERNAME:$PASSWORD -X GET "$API_ENDPOINT?start=$start&limit=$current_limit" -H "Accept: application/json")
    records=$(echo "$response" | jq '.results[].creationDate')

    echo "$records"

    start=$((current_limit + 1))
    iteration=$((iteration + 1))
done



最終更新日 2024 年 6 月 27 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.