/
レポートエクスポートのためのスクリプト例
レポートエクスポートのためのスクリプト例
作成日 | 更新日 | 影響を受けるバージョン | 修正バージョン |
---|---|---|---|
|
| Management Portal | N/A |
説明
このページでは、Blancco Management Portal APIエンドポイント用のスクリプト例を紹介しています。
注意! ここで紹介するスクリプトは試験的なものです。単一のユースケースを念頭に構築されており、実働環境での使用は意図されていません。
お客様固有の環境で期待通り動作することを保証するものではありません。
管理された非実働環境でのみ実行することを推奨します。自己責任でご利用ください。
Python
動作要件:
- Python
- Requestsライブラリ
このスクリプトは複数レポートを1回に1レポートずつ (「size」パラメーターを1に設定) エクスポートします。最後のレポートをエクスポートした後に結果の要約を出力します。
スクリプト内のエンドポイントURL、APIキー、エクスポートフィルターおよびその他パラメーターは必要に応じ修正してください。
Example python script to export multiple pages of reports a single report at a time
import requests def execute_curl_request(cursor=None): url = 'https://api.eu-west-1.blancco.cloud/v1/report/export' headers = { 'Content-Type': 'application/json', 'X-BLANCCO-API-KEY': 'YOUR-API-KEY' } data = { "filter": { "date": { "gte": "2023-07-01T00:00:00Z" } }, "format": "XML", "container": "NONE", "size": 1 } if cursor: url += f"?cursor={cursor}" response = requests.post(url, headers=headers, json=data) return response def check_and_print_response(response): if response.status_code == 200: print(response.text) cursor_header = response.headers.get('x-blancco-cursor') return cursor_header, True else: print("Request failed with status code:", response.status_code) return None, False if __name__ == "__main__": cursor = None success_count = 0 failure_count = 0 while True: response = execute_curl_request(cursor) if success_count == 0: print("\n--------------------------------------------------") new_cursor, success = check_and_print_response(response) if success: success_count += 1 else: failure_count += 1 if new_cursor: cursor = new_cursor else: break print("\n--------------------------------------------------") print("All matching reports exported. Summary of exported reports:") print(f"Successful exports: {success_count}") print(f"Failed exports: {failure_count}")
, multiple selections available,