[access-wallarm-api-docs]: overview.md#your-own-api-client
[application-docs]: ../user-guides/settings/applications.md
# Wallarm APIリクエスト例
以下はWallarm API使用例の一部です。US cloud [US Cloud](https://apiconsole.us1.wallarm.com/)またはEU cloud [EU Cloud](https://apiconsole.eu1.wallarm.com/)向けのAPI Reference UIよりコード例を生成することもできます。経験豊富なユーザーはブラウザのDeveloper console(「Network」タブ)を使用して、WallarmアカウントのUIがpublic APIよりデータを取得する際にどのAPIエンドポイントとリクエストが使用されているかを迅速に確認することができます。Developer consoleの起動方法についての詳細は、公式ブラウザドキュメント([Safari](https://support.apple.com/guide/safari/use-the-developer-tools-in-the-develop-menu-sfri20948/mac)、[Chrome](https://developers.google.com/web/tools/chrome-devtools/)、[Firefox](https://developer.mozilla.org/en-US/docs/Tools)、[Vivaldi](https://help.vivaldi.com/article/developer-tools/))をご参照ください。
## 過去24時間以内に検出された最初の50件の攻撃の取得
`TIMESTAMP`を[Unix Timestamp](https://www.unixtimestamp.com/)形式に変換した24時間前の日付に置き換えてください。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/attack" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"filter\": { \"clientid\": [YOUR_CLIENT_ID], \"time\": [[TIMESTAMP, null]] }, \"offset\": 0, \"limit\": 50, \"order_by\": \"last_time\", \"order_desc\": true}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/attack" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"filter\": { \"clientid\": [YOUR_CLIENT_ID], \"time\": [[TIMESTAMP, null]] }, \"offset\": 0, \"limit\": 50, \"order_by\": \"last_time\", \"order_desc\": true}"
```
## 多数の攻撃(100件以上)の取得
攻撃およびヒットのレコードが100件以上含まれる場合、大規模なデータセットを一度に取得するのではなく、より小さな部分に分けて取得する方がパフォーマンスの最適化に有効です。該当するWallarm APIエンドポイントは100件ずつのカーソルベースのページネーションに対応しています。
この手法では、データセット内の特定のアイテムを指すポインタを返し、続くリクエストではサーバーがそのポインタ以降の結果を返す形となります。カーソルページネーションを有効にするには、リクエストパラメータに`"paging": true`を含めてください。
以下はカーソルページネーションを使用して`<TIMESTAMP>`以降に検出された全ての攻撃を取得するAPI呼び出しの例です:
=== "EU Cloud"
```bash
curl -k 'https://api.wallarm.com/v2/objects/attack' \
-X POST \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{"paging": true, "filter": {"clientid": [<YOUR_CLIENT_ID>], "vulnid": null, "time": [[<TIMESTAMP>, null]], "!state": "falsepositive"}}'
```
=== "US Cloud"
```bash
curl -k 'https://us1.api.wallarm.com/v2/objects/attack' \
-X POST \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{"paging": true, "filter": {"clientid": [<YOUR_CLIENT_ID>], "vulnid": null, "time": [[<TIMESTAMP>, null]], "!state": "falsepositive"}}'
```
このリクエストは、最新の100件の攻撃情報を新しい順から古い順に並べて返します。さらに、レスポンスには次の100件の攻撃の取得開始位置を示す`cursor`パラメータが含まれています。
次の100件の攻撃を取得するには、同様のリクエストに前回のレスポンスからコピーしたポインタ値を持つ`cursor`パラメータを追加してください。例えば:
=== "EU Cloud"
```bash
curl -k 'https://api.wallarm.com/v2/objects/attack' \
-X POST \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{"cursor":"<POINTER_FROM_PREVIOUS_RESPONSE>", "paging": true, "filter": {"clientid": [<YOUR_CLIENT_ID>], "vulnid": null, "time": [[<TIMESTAMP>, null]], "!state": "falsepositive"}}'
```
=== "US Cloud"
```bash
curl -k 'https://us1.api.wallarm.com/v2/objects/attack' \
-X POST \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{"cursor":"<POINTER_FROM_PREVIOUS_RESPONSE>", "paging": true, "filter": {"clientid": [<YOUR_CLIENT_ID>], "vulnid": null, "time": [[<TIMESTAMP>, null]], "!state": "falsepositive"}}'
```
さらに結果のページを取得するには、前回のレスポンスから取得した`cursor`パラメータの値を含めたリクエストを実行してください。
以下はカーソルページネーションを使用して攻撃を取得するPythonコード例です:
=== "EU Cloud"
```python
import json
from pprint import pprint as pp
import requests
client_id = <YOUR_CLIENT_ID>
ts = <TIMESTAMP> # UNIX time
url = "https://api.wallarm.com/v2/objects/attack"
headers = {
"X-WallarmApi-Token": "<YOUR_TOKEN>",
"Content-Type": "application/json",
}
payload = {
"paging": True,
"filter": {
"clientid": [client_id],
"vulnid": None,
"time": [[ts, None]],
"!state": "falsepositive",
},
}
while True:
response = requests.post(url, headers=headers, json=payload)
data = response.json()
cursor = data.get("cursor")
if not cursor:
break
pp(data)
payload["cursor"] = cursor
```
=== "US Cloud"
```python
import json
from pprint import pprint as pp
import requests
client_id = <YOUR_CLIENT_ID>
ts = <TIMESTAMP> # UNIX time
url = "https://us1.api.wallarm.com/v2/objects/attack"
headers = {
"X-WallarmApi-Token": "<YOUR_TOKEN>",
"X-WallarmAPI-Secret": "<YOUR_SECRET_KEY>",
"Content-Type": "application/json",
}
payload = {
"paging": True,
"filter": {
"clientid": [client_id],
"vulnid": None,
"time": [[ts, None]],
"!state": "falsepositive",
},
}
while True:
response = requests.post(url, headers=headers, json=payload)
data = response.json()
cursor = data.get("cursor")
if not cursor:
break
pp(data)
payload["cursor"] = cursor
```
## 過去24時間以内に確認された最初の50件のインシデントの取得
このリクエストは攻撃一覧の取得例と非常に類似していますが、リクエストに`"!vulnid": null`が追加されています。この項目は、脆弱性IDが指定されていない全ての攻撃を無視するようAPIに指示し、これによりシステムは攻撃とインシデントを区別します。
`TIMESTAMP`を[Unix Timestamp](https://www.unixtimestamp.com/)形式に変換した24時間前の日付に置き換えてください。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/attack" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"filter\": { \"clientid\": [YOUR_CLIENT_ID], \"\!vulnid\": null, \"time\": [[TIMESTAMP, null]] }, \"offset\": 0, \"limit\": 50, \"order_by\": \"last_time\", \"order_desc\": true}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/attack" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"filter\": { \"clientid\": [YOUR_CLIENT_ID], \"\!vulnid\": null, \"time\": [[TIMESTAMP, null]] }, \"offset\": 0, \"limit\": 50, \"order_by\": \"last_time\", \"order_desc\": true}"
```
## 過去24時間以内にステータス「active」の最初の50件の脆弱性の取得
`TIMESTAMP`を[Unix Timestamp](https://www.unixtimestamp.com/)形式に変換した24時間前の日付に置き換えてください。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/vuln" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"limit\":50, \"offset\":0, \"filter\":{\"clientid\":[YOUR_CLIENT_ID], \"testrun_id\":null, \"validated\":true, \"time\":[[TIMESTAMP, null]]}}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/vuln" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"limit\":50, \"offset\":0, \"filter\":{\"clientid\":[YOUR_CLIENT_ID], \"testrun_id\":null, \"validated\":true, \"time\":[[TIMESTAMP, null]]}}"
```
## 全ての設定済みルールの取得
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/hint" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"filter\":{\"clientid\": [YOUR_CLIENT_ID]},\"order_by\": \"updated_at\",\"order_desc\": true,\"limit\": 1000,\"offset\": 0}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/hint" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"filter\":{\"clientid\": [YOUR_CLIENT_ID]},\"order_by\": \"updated_at\",\"order_desc\": true,\"limit\": 1000,\"offset\": 0}"
```
## すべてのルールの条件のみの取得
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/action" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"filter\": { \"clientid\": [YOUR_CLIENT_ID] }, \"offset\": 0, \"limit\": 1000}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/action" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"filter\": { \"clientid\": [YOUR_CLIENT_ID] }, \"offset\": 0, \"limit\": 1000}"
```
## 特定の条件に紐付くルールの取得
特定の条件を指すには、そのIDを使用してください。すべてのルールの条件をリクエストする際に取得できます(上記参照)。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/hint" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"filter\":{\"clientid\": [YOUR_CLIENT_ID],\"actionid\": YOUR_CONDITION_ID},\"limit\": 1000,\"offset\": 0}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/hint" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"filter\":{\"clientid\": [YOUR_CLIENT_ID],\"actionid\": YOUR_CONDITION_ID},\"limit\": 1000,\"offset\": 0}"
```
## `/my/api/*`への全リクエストをブロックするためのバーチャルパッチの作成
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/hint/create" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"clientid\": YOUR_CLIENT_ID, \"type\": \"vpatch\", \"action\": [ {\"type\":\"equal\",\"value\":\"my\",\"point\":[\"path\",0]}, {\"type\":\"equal\",\"value\":\"api\",\"point\":[\"path\",1]}], \"validated\": false, \"point\": [ [ \"header\", \"HOST\" ] ], \"attack_type\": \"any\"}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/hint/create" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"clientid\": YOUR_CLIENT_ID, \"type\": \"vpatch\", \"action\": [ {\"type\":\"equal\",\"value\":\"my\",\"point\":[\"path\",0]}, {\"type\":\"equal\",\"value\":\"api\",\"point\":[\"path\",1]}], \"validated\": false, \"point\": [ [ \"header\", \"HOST\" ] ], \"attack_type\": \"any\"}"
```
## 特定のapplication instance IDに対して`/my/api/*`への全リクエストをブロックするバーチャルパッチの作成
このリクエストを送信する前にapplicationが[設定](../user-guides/settings/applications.md)されている必要があります。`action.point[instance].value`に既存のapplicationのIDを指定してください。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/hint/create" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"type\":\"vpatch\",\"action\":[{\"point\":[\"instance\"],\"type\":\"equal\",\"value\":\"-1\"},{\"point\":[\"path\",0],\"type\":\"equal\",\"value\":\"my\"},{\"point\":[\"path\",1],\"type\":\"equal\",\"value\":\"api\"}],\"clientid\":YOUR_CLIENT_ID,\"validated\":false,\"point\":[[\"header\",\"HOST\"]],\"attack_type\":\"any\"}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/hint/create" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"type\":\"vpatch\",\"action\":[{\"point\":[\"instance\"],\"type\":\"equal\",\"value\":\"-1\"},{\"point\":[\"path\",0],\"type\":\"equal\",\"value\":\"my\"},{\"point\":[\"path\",1],\"type\":\"equal\",\"value\":\"api\"}],\"clientid\":YOUR_CLIENT_ID,\"validated\":false,\"point\":[[\"header\",\"HOST\"]],\"attack_type\":\"any\"}"
```
## 特定の`X-FORWARDED-FOR`ヘッダーの値を持つリクエストを攻撃と見なすルールの作成
以下のリクエストは、正規表現に基づく[カスタムアタックインジケータ](../user-guides/rules/regex-rule.md) `^(~(44[.]33[.]22[.]11))$`を作成します。
もし`MY.DOMAIN.COM`ドメインへのリクエストに`X-FORWARDED-FOR: 44.33.22.11`のHTTPヘッダーが含まれている場合、Wallarmノードはこれらをスキャナー攻撃と見なし、該当する[filtration mode](../admin-en/configure-wallarm-mode.md)が設定されていれば攻撃をブロックします。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/hint/create" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"type\":\"regex\",\"action\":[{\"point\":[\"header\",\"HOST\"],\"type\":\"equal\",\"value\":\"MY.DOMAIN.NAME\"}],\"clientid\":YOUR_CLIENT_ID,\"validated\":false,\"comment\":\"comment\",\"point\":[[\"header\",\"X-FORWARDED-FOR\"]],\"attack_type\":\"scanner\",\"regex\":\"^\(~\(44[.]33[.]22[.]11\)\)$\"}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/hint/create" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"type\":\"regex\",\"action\":[{\"point\":[\"header\",\"HOST\"],\"type\":\"equal\",\"value\":\"MY.DOMAIN.NAME\"}],\"clientid\":YOUR_CLIENT_ID,\"validated\":false,\"comment\":\"comment\",\"point\":[[\"header\",\"X-FORWARDED-FOR\"]],\"attack_type\":\"scanner\",\"regex\":\"^\(~\(44[.]33[.]22[.]11\)\)$\"}"
```
## 特定のapplicationに対してfiltration modeをmonitoringに設定するルールの作成
以下のリクエストは、IDが`3`の[application](../user-guides/settings/applications.md)向けに、ノードがトラフィックをフィルタリングする[ルールの作成](../admin-en/configure-wallarm-mode.md#endpoint-targeted-filtration-rules-in-wallarm-console)をmonitoringモードで実施します。
=== "US Cloud"
```bash
curl 'https://us1.api.wallarm.com/v1/objects/hint/create' -H 'X-WallarmApi-Token: <YOUR_TOKEN>' -H "accept: application/json" -H "Content-Type: application/json" --data-raw '{"clientid":<YOUR_CLIENT_ID>,"type":"wallarm_mode","mode":"monitoring","validated":false,"action":[{"point":["instance"],"type":"equal","value":"3"}]}'
```
=== "EU Cloud"
```bash
curl 'https://api.wallarm.com/v1/objects/hint/create' -H 'X-WallarmApi-Token: <YOUR_TOKEN>' -H "accept: application/json" -H "Content-Type: application/json" --data-raw '{"clientid":<YOUR_CLIENT_ID>,"type":"wallarm_mode","mode":"monitoring","validated":false,"action":[{"point":["instance"],"type":"equal","value":"3"}]}'
```
## ルールIDによるルールの削除
削除するルールIDは[全ての設定済みルールの取得](#get-all-configured-rules)時にコピーできます。また、ルール作成リクエストのレスポンスパラメータ`id`にもルールIDが返されます。
=== "US cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://us1.api.wallarm.com/v1/objects/hint/delete" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"filter\":{\"clientid\":[YOUR_CLIENT_ID],\"id\": YOUR_RULE_ID}}"
```
=== "EU cloud"
```{.bash .wrapped-code}
curl -v -X POST "https://api.wallarm.com/v1/objects/hint/delete" -H "X-WallarmApi-Token: <YOUR_TOKEN>" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"filter\":{\"clientid\":[YOUR_CLIENT_ID],\"id\": YOUR_RULE_ID}}"
```
## IPリストオブジェクトの取得、追加、削除のためのAPI呼び出し
以下は[IPリスト](../user-guides/ip-lists/overview.md)オブジェクトを取得、追加、削除するAPI呼び出しの例です。
### APIリクエストパラメータ
IPリストの読み取りおよび変更のためにAPIリクエストに渡すパラメータ:
| Parameter | Description |
| --------- | ----------- |
| `X-WallarmApi-Token` | Token to [access Wallarm API][access-wallarm-api-docs], copy it from Wallarm Console → **Settings** → **API tokens**. |
| `clientid` | ID of an account in Wallarm Cloud to populate/read IP list.
| `ip_rule.list` | The IP list type to add objects, can be: `black` (for denylist), `white` (for allowlist), `gray` (for graylist). |
| `ip_rule.rule_type` | The type of objects to add to the list:<ul><li>`ip_range` if adding particular IPs or subnets</li><li>`country` if adding countries or regions</li><li>`proxy_type` if adding proxy services (`VPN`, `SES`, `PUB`, `WEB`, `TOR`)</li><li>`datacenter` for other source types (`rackspace`, `tencent`, `plusserver`, `ovh`, `oracle`, `linode`, `ibm`, `huawei`, `hetzner`, `gce`, `azure`, `aws`, `alibaba`)</li></ul> |
| `ip_rule.subnet`<br>(`rule_type:"ip_range"`) | IP or subnet to add to the list, e.g. `"1.1.1.1"`. |
| `ip_rule.source_values`<br>(for other `rule_type` values) | One of the options:<ul><li>If `rule_type:"country"` - array of countries in the [ISO-3166 format](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes), e.g. `["AX","AL"]`.</li><li>If `rule_type:"proxy_type"` - array of proxy services, e.g. `["VPN","PUB"]`.</li><li>If `rule_type:"datacenter"` - array of other source types, e.g. `["rackspace","huawei"]`.</li></ul> |
| `ip_rule.pools` | Array of [application IDs][application-docs] to allow or restrict access for IPs, e.g. `[3,4]` for applications IDs 3 and 4 or `[0]` for all applications.
| `ip_rule.expired_at` | [Unix Timestamp](https://www.unixtimestamp.com/) date for IPs to be removed from the list. The maximum value is forever (`33223139044`). |
| `reason` | Reason to allow or restrict access for IPs.
| `force` | If `true` and some objects specified in the request are already in the IP list, the script will overwrite them. |
### `.csv`ファイルからのエントリをリストに追加
`.csv`ファイルからIPまたはサブネットをリストに追加するには、以下のbashスクリプトを使用してください:
=== "US Cloud"
```bash
#!/bin/bash
UUID="<YOUR_UUID>"
SECRET="<YOUR_SECRET_KEY>"
CLIENT="<YOUR_CLIENT_ID>"
LIST="<TYPE_OF_IP_LIST>"
PATH_TO_CSV_FILE="<PATH_TO_CSV_FILE>" # path to the CSV file with IPs or subnets
APPLICATIONS="<APP_IDS_THROUGH_COMMA>"
REMOVE_DATE="TIMESTAMP_REMOVE_DATE"
REASON='<REASON>'
API="us1.api.wallarm.com"
index=0
while read line; do
subnets[$index]="$line"
index=$(($index+1))
done < "$PATH_TO_CSV_FILE"
for i in ${subnets[@]}; do
currentDate=`date -u +%s`
time=$REMOVE_DATE
remove_date=$(($currentDate+$time))
curl -X POST \
https://$API/v4/ip_rules \
-H "Content-Type: application/json" \
-H "X-WallarmApi-Token: <YOUR_TOKEN>" \
-d '{
"clientid": '$CLIENT',
"ip_rule": {
"list": "'$LIST'",
"rule_type": "ip_range",
"subnet": "'$i'",
"expired_at": '$remove_date',
"pools": [
'$APPLICATIONS'
],
"reason": "'"$REASON"'"
},
"force": false
}'
done
```
=== "EU Cloud"
```bash
#!/bin/bash
UUID="<YOUR_UUID>"
SECRET="<YOUR_SECRET_KEY>"
CLIENT="<YOUR_CLIENT_ID>"
LIST="<TYPE_OF_IP_LIST>"
PATH_TO_CSV_FILE="<PATH_TO_CSV_FILE>" # path to the CSV file with IPs or subnets
APPLICATIONS="<APP_IDS_THROUGH_COMMA>"
REMOVE_DATE="TIMESTAMP_REMOVE_DATE"
REASON='<REASON>'
API="api.wallarm.com"
index=0
while read line; do
subnets[$index]="$line"
index=$(($index+1))
done < "$PATH_TO_CSV_FILE"
for i in ${subnets[@]}; do
currentDate=`date -u +%s`
time=$REMOVE_DATE
remove_date=$(($currentDate+$time))
curl -X POST \
https://$API/v4/ip_rules \
-H "Content-Type: application/json" \
-H "X-WallarmApi-Token: <YOUR_TOKEN>" \
-d '{
"clientid": '$CLIENT',
"ip_rule": {
"list": "'$LIST'",
"rule_type": "ip_range",
"subnet": "'$i'",
"expired_at": '$remove_date',
"pools": [
'$APPLICATIONS'
],
"reason": "'"$REASON"'"
},
"force": false
}'
done
```
### 単一のIPまたはサブネットをリストに追加
To add particular IPs or subnets to the IP list, send the following request for each IP/subnet:
=== "US Cloud"
```bash
curl 'https://us1.api.wallarm.com/v4/ip_rules' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"clientid":<YOUR_CLIENT_ID>,"force":false,"ip_rule":{"list":"<TYPE_OF_IP_LIST>","reason":"<REASON_TO_ADD_ENTRIES_TO_LIST>","pools":[<ARRAY_OF_APP_IDS>],"expired_at":<TIMESTAMP_REMOVE_DATE>,"rule_type":"ip_range","subnet":"<IP_OR_SUBNET>"}}'
```
=== "EU Cloud"
```bash
curl 'https://api.wallarm.com/v4/ip_rules' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"clientid":<YOUR_CLIENT_ID>,"force":false,"ip_rule":{"list":"<TYPE_OF_IP_LIST>","reason":"<REASON_TO_ADD_ENTRIES_TO_LIST>","pools":[<ARRAY_OF_APP_IDS>],"expired_at":<TIMESTAMP_REMOVE_DATE>,"rule_type":"ip_range","subnet":"<IP_OR_SUBNET>"}}'
```
### 複数の国をリストに追加
=== "US Cloud"
```bash
curl 'https://us1.api.wallarm.com/v4/ip_rules' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"clientid":<YOUR_CLIENT_ID>,"ip_rule":{"list":"<TYPE_OF_IP_LIST>","rule_type":"country","source_values":[<ARRAY_OF_COUNTRIES_REGIONS>],"pools":[<ARRAY_OF_APP_IDS>],"expired_at":"<TIMESTAMP_REMOVE_DATE>","reason":"<REASON_TO_ADD_ENTRIES_TO_LIST>"},"force":false}'
```
=== "EU Cloud"
```bash
curl 'https://api.wallarm.com/v4/ip_rules' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"clientid":<YOUR_CLIENT_ID>,"ip_rule":{"list":"<TYPE_OF_IP_LIST>","rule_type":"country","source_values":[<ARRAY_OF_COUNTRIES_REGIONS>],"pools":[<ARRAY_OF_APP_IDS>],"expired_at":"<TIMESTAMP_REMOVE_DATE>","reason":"<REASON_TO_ADD_ENTRIES_TO_LIST>"},"force":false}'
```
### 複数のプロキシサービスをリストに追加
=== "US Cloud"
```bash
curl 'https://us1.api.wallarm.com/v4/ip_rules' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"clientid":<YOUR_CLIENT_ID>,"ip_rule":{"list":"<TYPE_OF_IP_LIST>","rule_type":"proxy_type","source_values":[<ARRAY_OF_PROXY_SERVICES>],"pools":[<ARRAY_OF_APP_IDS>],"expired_at":"<TIMESTAMP_REMOVE_DATE>","reason":"<REASON_TO_ADD_ENTRIES_TO_LIST>"},"force":false}'
```
=== "EU Cloud"
```bash
curl 'https://api.wallarm.com/v4/ip_rules' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data-raw '{"clientid":<YOUR_CLIENT_ID>,"ip_rule":{"list":"<TYPE_OF_IP_LIST>","rule_type":"proxy_type","source_values":[<ARRAY_OF_PROXY_SERVICES>],"pools":[<ARRAY_OF_APP_IDS>],"expired_at":"<TIMESTAMP_REMOVE_DATE>","reason":"<REASON_TO_ADD_ENTRIES_TO_LIST>"},"force":false}'
```
### IPリストからオブジェクトの削除
オブジェクトはそのIDによってIPリストから削除されます。
オブジェクトのIDを取得するには、IPリスト内容をリクエストして、レスポンスから該当オブジェクトの`objects.id`をコピーしてください:
=== "US Cloud"
```bash
curl 'https://us1.api.wallarm.com/v4/ip_rules?filter%5Bclientid%5D=<YOUR_CLIENT_ID>&filter%5Blist%5D=<TYPE_OF_IP_LIST>&offset=0&limit=50' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>'
```
=== "EU Cloud"
```bash
curl 'https://api.wallarm.com/v4/ip_rules?filter%5Bclientid%5D=<YOUR_CLIENT_ID>&filter%5Blist%5D=<TYPE_OF_IP_LIST>&offset=0&limit=50' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>'
```
オブジェクトIDを取得したら、以下のリクエストを送信してリストから削除してください:
=== "US Cloud"
```bash
curl 'https://us1.api.wallarm.com/v4/ip_rules' \
-X 'DELETE' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
--data-raw '{"filter":{"clientid":<YOUR_CLIENT_ID>,"id":[<OBJECT_ID_TO_DELETE>]}}'
```
=== "EU Cloud"
```bash
curl 'https://api.wallarm.com/v4/ip_rules' \
-X 'DELETE' \
-H 'X-WallarmApi-Token: <YOUR_TOKEN>' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
--data-raw '{"filter":{"clientid":<YOUR_CLIENT_ID>,"id":[<OBJECT_ID_TO_DELETE>]}}'
```
複数のオブジェクトを一度に削除する際は、削除リクエストの中でIDを配列として渡すことが可能です。