Create Asset Tag Rules

Cortex Xpanse REST API

post /public_api/v1/assets/create_asset_tag_rules/

Create tag rules that apply tags automatically to assets that match your rule criteria, including any new assets that are attributed to your organization. Tag rules can be defined for IPv4 addresses and IPv4 ranges. These fields can be the same to denote a single IP address. If the list of IP addresses exceeds 100, Expander will create multiple tag rules, each with at most 100 IP addresses per rule.
Required License: Cortex Xpanse Expander

Request headers
authorization String required

api-key

Example: {{api_key}}
x-xdr-auth-id String required

api-key-id

Example: {{api_key_id}}
CLIENT REQUEST
curl -X 'POST'
-H 'Accept: application/json'
-H 'Content-Type: application/json'
-H 'authorization: {{api_key}}' -H 'x-xdr-auth-id: {{api_key_id}}'
'https://api-}/public_api/v1/assets/create_asset_tag_rules/'
-d '{ "request_data" : { "rule_name" : "rule_name", "ip_ranges" : [ { "to_ip" : "to_ip", "from_ip" : "from_ip" }, { "to_ip" : "to_ip", "from_ip" : "from_ip" } ], "tag_name" : "tag_name", "description" : "description" } }'
import http.client conn = http.client.HTTPSConnection("api-") payload = "{\"request_data\":{\"ip_ranges\":[{\"from_ip\":\"string\",\"to_ip\":\"string\"}],\"rule_name\":\"string\",\"description\":\"string\",\"tag_name\":\"string\"}}" headers = { 'authorization': "{{api_key}}", 'x-xdr-auth-id': "{{api_key_id}}", 'content-type': "application/json" } conn.request("POST", "%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
require 'uri' require 'net/http' require 'openssl' url = URI("https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) request["authorization"] = '{{api_key}}' request["x-xdr-auth-id"] = '{{api_key_id}}' request["content-type"] = 'application/json' request.body = "{\"request_data\":{\"ip_ranges\":[{\"from_ip\":\"string\",\"to_ip\":\"string\"}],\"rule_name\":\"string\",\"description\":\"string\",\"tag_name\":\"string\"}}" response = http.request(request) puts response.read_body
const data = JSON.stringify({ "request_data": { "ip_ranges": [ { "from_ip": "string", "to_ip": "string" } ], "rule_name": "string", "description": "string", "tag_name": "string" } }); const xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); } }); xhr.open("POST", "https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/"); xhr.setRequestHeader("authorization", "{{api_key}}"); xhr.setRequestHeader("x-xdr-auth-id", "{{api_key_id}}"); xhr.setRequestHeader("content-type", "application/json"); xhr.send(data);
HttpResponse<String> response = Unirest.post("https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/") .header("authorization", "{{api_key}}") .header("x-xdr-auth-id", "{{api_key_id}}") .header("content-type", "application/json") .body("{\"request_data\":{\"ip_ranges\":[{\"from_ip\":\"string\",\"to_ip\":\"string\"}],\"rule_name\":\"string\",\"description\":\"string\",\"tag_name\":\"string\"}}") .asString();
import Foundation let headers = [ "authorization": "{{api_key}}", "x-xdr-auth-id": "{{api_key_id}}", "content-type": "application/json" ] let parameters = ["request_data": [ "ip_ranges": [ [ "from_ip": "string", "to_ip": "string" ] ], "rule_name": "string", "description": "string", "tag_name": "string" ]] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume()
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\"request_data\":{\"ip_ranges\":[{\"from_ip\":\"string\",\"to_ip\":\"string\"}],\"rule_name\":\"string\",\"description\":\"string\",\"tag_name\":\"string\"}}", CURLOPT_HTTPHEADER => [ "authorization: {{api_key}}", "content-type: application/json", "x-xdr-auth-id: {{api_key_id}}" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
CURL *hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(hnd, CURLOPT_URL, "https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/"); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "authorization: {{api_key}}"); headers = curl_slist_append(headers, "x-xdr-auth-id: {{api_key_id}}"); headers = curl_slist_append(headers, "content-type: application/json"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"request_data\":{\"ip_ranges\":[{\"from_ip\":\"string\",\"to_ip\":\"string\"}],\"rule_name\":\"string\",\"description\":\"string\",\"tag_name\":\"string\"}}"); CURLcode ret = curl_easy_perform(hnd);
var client = new RestClient("https://api-/%7B%7Bfqdn%7D%7D/public_api/v1/assets/create_asset_tag_rules/"); var request = new RestRequest(Method.POST); request.AddHeader("authorization", "{{api_key}}"); request.AddHeader("x-xdr-auth-id", "{{api_key_id}}"); request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", "{\"request_data\":{\"ip_ranges\":[{\"from_ip\":\"string\",\"to_ip\":\"string\"}],\"rule_name\":\"string\",\"description\":\"string\",\"tag_name\":\"string\"}}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);
Body parameters
required
application/json
request_dataobjectrequired

A dictionary containing the API request fields.

ip_rangesarray

List of dictionaries containing "from_ip" and "to_ip" to define an IP range. These fields can be the same to denote a single IP address.
For example,
"from_ip": "1.1.1.1", "to_ip": "1.1.1.3".'

[
from_ipstring
to_ipstring
Free-Form object
]
rule_namestring

Name of the tag rule. Will use tag_name if left empty.

descriptionstring

(Optional) Description of the tag rule.

tag_namestring

Name of the tag to be used to tag assets. If a rules-based tag with the same name already exists, it will use that tag. If not, a new rules-based tag will be created.

Free-Form object
Free-Form object
REQUEST
{ "request_data": { "ip_ranges": [ { "from_ip": "example", "to_ip": "example" } ], "rule_name": "example", "description": "example", "tag_name": "example" } }
Responses

OK

Body
application/json
replystring
Free-Form object
RESPONSE
{ "reply": "example" }

Bad Request. Got an invalid JSON.

Body
application/json
replyobject

The query results upon error.

err_codestring

HTTP response code.

err_msgstring

Error message.

err_extrastring

Additional information describing the error.

Free-Form object
Free-Form object
RESPONSE
{ "reply": { "err_code": "example", "err_msg": "example", "err_extra": "example" } }

Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters.

Body
application/json
replyobject

The query results upon error.

err_codestring

HTTP response code.

err_msgstring

Error message.

err_extrastring

Additional information describing the error.

Free-Form object
Free-Form object
RESPONSE
{ "reply": { "err_code": "example", "err_msg": "example", "err_extra": "example" } }

Unauthorized access. User does not have the required license type to run this API.

Body
application/json
replyobject

The query results upon error.

err_codestring

HTTP response code.

err_msgstring

Error message.

err_extrastring

Additional information describing the error.

Free-Form object
Free-Form object
RESPONSE
{ "reply": { "err_code": "example", "err_msg": "example", "err_extra": "example" } }

Forbidden access. The provided API Key does not have the required RBAC permissions to run this API.

Body
application/json
replyobject

The query results upon error.

err_codestring

HTTP response code.

err_msgstring

Error message.

err_extrastring

Additional information describing the error.

Free-Form object
Free-Form object
RESPONSE
{ "reply": { "err_code": "example", "err_msg": "example", "err_extra": "example" } }

Unprocessable Entity

Body
application/json
codeinteger

Error code

statusstring

Error name

messagestring

Error message

errorsobject

Errors

RESPONSE
{ "code": 0, "status": "example", "message": "example", "errors": {} }

Internal server error. A unified status for API communication type errors.

Body
application/json
replyobject

The query results upon error.

err_codestring

HTTP response code.

err_msgstring

Error message.

err_extrastring

Additional information describing the error.

Free-Form object
Free-Form object
RESPONSE
{ "reply": { "err_code": "example", "err_msg": "example", "err_extra": "example" } }