フィルタリングによる監査イベントの取得
このコード・スニペットでは、フィルタリングを使用して監査イベントのリストを取得する方法について説明します。
パラメータ
クエリ・パラメータを使用して、返されるイベント・オブジェクトのリストをフィルタリングすることができます。指定可能なパラメータを以下の表に示す:
| クエリ・パラメータ | 説明 |
|---|---|
event_type | 監査イベントのタイプ: APP_CREATE, NUMBER_ASSIGNなどがある。をカンマ区切りで指定できる。 イベントの種類 ここにある。 |
search_text | JSON互換の検索文字列。監査イベント内の特定のテキストを検索します。 |
date_from | この日付(ISO-8601 形式)から Audit イベントを取得します。 |
date_to | この日付までの Audit イベントを取得します(ISO-8601 形式)。 |
page | 1ページから始まるページ番号。 |
size | ページあたりの要素数(1〜100、デフォルトは30)。 |
例
以下の置換可能な値が、便利な方法でサンプルコードに設定されていることを確認する必要があります:
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
SEARCH_TEXT | Some JSON compatible text to search for. For example, "number". |
DATE_FROM | Audit events starting from this ISO-8601 datetime value. For example, "2018-07-01". |
DATE_TO | Audit events up to this ISO-8601 datetime value. For example, "2018-08-01". |
次の例では アプリケーションの作成 そして 依存関係を初期化する 手続きは任意である。
Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
Create a file named get-events-with-filtering.sh and add the following code:
source "../config.sh"Write the code
Add the following to get-events-with-filtering.sh:
curl "https://api.nexmo.com/beta/audit/events?search_text=$SEARCH_TEXT&date_from=$DATE_FROM&date_to=$DATE_TO" \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET"Run your code
Save this file to your machine and run it:
Prerequisites
A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.
Install the CLI
Create an application
Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step
Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.
npm install @vonage/auditCreate a file named get-events-with-filtering.js and add the following code:
const { Audit } = require('@vonage/audit');
const auditClient = new Audit({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to get-events-with-filtering.js:
const run = async () => {
const filter = {
dateFrom: DATE_FROM,
dateTo: DATE_TO,
searchText: SEARCH_TEXT,
};
try {
for await (const event of auditClient.getEvents(filter)) {
console.log(event);
}
} catch (error) {
console.log(error);
}
};
run();Run your code
Save this file to your machine and run it:
試してみる
シェルでコマンドを実行する。この呼び出しにより、フィルタリングされた監査イベントのリストが取得される。