Skip to content

Create a Single Data Access Rule



POST /api/v1/logging_query_rule/add

Overview

Create a log access rule (legacy v2 declaration).

Before Calling and Usage Steps

First determine the data domain, roles, sources, and DQL conditions, then create the rule with a unique name. A new rule with status=0 is immediately enabled; a successful write does not prove that the source has data or that the final member permissions meet expectations.

The current v2 declaration and the legacy API have the same method and URL; actual HTTP requests match the legacy endpoint first. Passing regionCode returns ft.ParameterValidationFailed as an unknown Body field. The regionCode in the declaration table on this page reflects the historical v2 contract and cannot currently be used to invoke cross-site capabilities. The executable example below uses valid fields of the legacy endpoint at the same path and does not pass regionCode; the response is also the save result from the legacy endpoint. For capabilities that require an explicit site, use the reachable generic create API data_query_rule.add_v2 or the console; do not attempt to add a fictitious /v2 path.

Writes replace the configuration, commit to the database, then clear the rule cache and record an audit entry; cross-site validation may also read/update resource information. These steps are not a single atomic transaction. After a 500/timeout, first check the list/details to verify whether the rule has been saved, to avoid blindly creating duplicates.

Saving a rule affects the data query scope/result masking for subsequent matching identities. It does not modify, delete, or backfill raw data, nor does it add basic query permissions for roles. Multiple roles and rules are merged according to query-side policies; final permissions cannot be inferred from a single rule alone. Owner is exempt; the administrator and the workspace's "Data Access Scope Restriction" setting changes how no-matching-role cases are handled. Acceptance should use actual queries from a representative member. The rule cache is invalidated after saving, but not all in-flight queries are guaranteed to switch immediately.

Request Headers

Parameter Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or enter: Obtain an OpenAPI key with this operation permission from API Key Management in the target workspace.

Body Request Parameters

Parameter Type Required Description
indexes[*] string Array members are recommended to be non-empty strings; the original declaration did not enforce each item, and an incorrect type can cause a 500.
Example: default
How to obtain or enter: A single log index UUID/default, or an authorized wksp_source:lgim_index.
roleUUIDs[*] string Use a valid role; do not use an account UUID.
Example: role_example
How to obtain or enter: A role UUID available in this workspace, or a standalone *.
extend.custom key any Any serializable JSON value; not an additional effective condition.
Example: production
How to obtain or enter: A display/edit context defined by the caller; keep it consistent with the actual conditions.
reExprs[*] json It is recommended to use only name/enable/reExpr. The original declaration did not enforce the structure of array elements; non-objects can cause a 500.
Example: {"name": "token", "enable": true, "reExpr": "tkn_[0-9A-Za-z]+"}
How to obtain or enter: Each object defines one masking expression.
reExprs[*].name string Optional display name; it is not used as the matching expression. Omitting it does not affect regex matching.
Example: token
How to obtain or enter: A custom regex display name defined by the business side.
reExprs[*].enable boolean It is recommended to use an explicit boolean. If omitted, it is treated as disabled; disabled regexes must still be syntactically valid.
Example: true
How to obtain or enter: Use true when it needs to be applied; use false when it is temporarily stored but not applied.
reExprs[*].reExpr string A non-empty regex is recommended. Currently, if omitted, it is checked as an empty string; do not rely on the server to complete a valid expression.
Example: tkn_[0-9A-Za-z]+
How to obtain or enter: The actual sensitive content pattern; when using a JSON string, backslashes must be doubled.
name string Optional; when omitted/empty string, an attempt is made to generate based on the caller identity display name and the current Unix seconds. Modification also regenerates it and does not retain the old name. Maximum 64 counting units (ASCII/half-width katakana: 1; other characters: 2); both enabled and disabled rules of the same type participate in duplicate-name checks.
Allow null: False
Allow empty string: False
Maximum length: 64
Example: production_only
How to obtain or enter: Named by the business side; first check existing names of the same type in the Log Access Rule List.
desc string Optional, up to 256 of the same counting units; if omitted/empty string, it is cleared to empty; modification does not retain the original value.
Allow null: False
Allow empty string: True
Maximum length: 256
Example: Only allow viewing production environment data.
How to obtain or enter: The business side enters the rule purpose and applicable objects.
regionCode string Y Required in the v2 declaration: source site code. Log indexes of the same rule must belong to the same site and be consistent with this value. The legacy endpoint does not accept this field. Data access rules do not replace cross-site/cross-workspace authorization; cross-site events must have a valid authorization that includes keyevent or *. Note the actual reachability description for the duplicate route below.
Allow null: False
Allow empty string: False
Example: example-region
How to obtain or enter: Confirm the actual regionCode from the target source site and a valid Cross-workspace Authorization List; the current site also uses its official code, not the example literal value.
indexes array Y Log index identifier array; required for this module; ["*"] means all available log indexes. It is recommended to use * alone; [] does not mean all. Use UUIDs for regular indexes, not names. Saving a rule does not create workspace or site authorization.
Allow null: False
Example: ["default"]
How to obtain or enter: Get the UUID from the Log Index List; use default for the default index; for cross-workspace, use the authorized source workspace UUID:index UUID.
roleUUIDs array Y Required role UUID array; ["*"] means all roles; [] matches no roles. Owner is still not subject to data access restrictions. Regular UUIDs are checked for existence by scope, but the role status is not guaranteed to be 0, and basic query permissions must still be granted separately.
Allow null: False
Example: ["role_example"]
How to obtain or enter: Get a role UUID of this workspace from the Role List; you can use the Workspace Member List to verify the member's actual roles.
conditions string Y Required log filter expression, not a complete query or outer braces; it is recommended not to exceed 4048 characters. The current logging path does not fully parse the E query rules of keyevent; a successful save does not guarantee that all subsequent queries can be executed.
Allow null: False
Example: `env` = 'production'
How to obtain or enter: Build the DQL filter condition from the actual tags/fields of the target data; verify it first with a query on the same source.
extend json Optional arbitrary JSON echo; default {}. There are no uniformly required child keys or units; the server does not automatically generate conditions from it. Modifications replace it entirely; do not store credentials.
Allow null: False
Example: {}
How to obtain or enter: The client saves the echo configuration as needed by its own editor; use {} when not needed.
logic string Y Compatibility echo field, usually and/or; required in the create declaration, can be omitted on modification. If omitted, an empty string is saved; the filter that actually takes effect uses conditions directly. Changing logic does not rewrite conditions, and the merging of multiple roles/rules is not controlled by this field.
Allow null: False
Example: and
How to obtain or enter: Keep it consistent with the condition combination method in the client filter editor.
maskFields string Optional; if omitted, an empty string means no field masking is configured for this rule; omitting it on modification clears it. When fields are selected and reExprs=[], non-null values have the entire field masked as ***. When a non-empty regex list is provided, only enabled regexes are applied; all disabled is not the same as full-field masking. It is recommended to keep it ≤256 characters to fit the storage column.
Allow null: False
Allow empty string: True
Example: message
How to obtain or enter: Select from the actual field names in query results; separate multiple fields with English commas, for example message,user_email; when * selects all, it must be used alone and not mixed with specific fields.
reExprs array Optional; default []; modifications replace it entirely. On save, every regex is validated, including items with enable=false; an invalid regex returns ft.ErrorRegularExpression. Do not use a standalone * to represent any string; use .*. When selected fields have no regex, the entire field is ***. Regexes only process matching fragments in string content and replace the matched content with ***. Save validation differs from the execution engine; after a successful save, still verify with representative queries.
Allow null: False
Example: [{"name": "token", "enable": true, "reExpr": "tkn_[0-9A-Za-z]+"}]
How to obtain or enter: Write a regex executable by Python re according to the sensitive value format, and validate it first with masked samples; use it together with maskFields.

Additional Parameter Notes

Data notes.*

1. Role-authorized access notes 1. A specified role can query only data within the specified query scope. 2. If a user has multiple roles and any of the user's roles is not among the roles in this rule, this data access rule does not take effect for that user, meaning the query scope is not restricted. 3. Multiple log data access rules within a workspace have an OR relationship.

2. Request parameter notes

Parameter type Required Description
name string Y Name
desc String N Description
indexes array Y Log index information. For index authorization outside this workspace (must be authorized through workspace authorization), use workspace UUID:index UUID, e.g. ["wksp_111:lgim_222", "wksp_333:lgim_444"]
roleUUIDs array Y Role UUID list
conditions string N Filter condition for the actually used data scope, e.g. "device IN ['PC'] and session_has_replay IN ['1']"
extend dict Y Extension field that stores the structured content of conditions, used for frontend page display, e.g. {"device": [ "PC"], "session_has_replay": [1]}
logic string N Logic field, and/or, used to connect filter conditions
maskFields string N Masked fields; separate multiple fields with commas
reExprs array N Regular expressions, e.g. [{"name":"1111","enable":true,"reExpr":"tkn_[\da-z]*"},{"name":"liuyltest","enable":true,"reExpr":"test"}]
regionCode string Y Site code (can be obtained through the workspace/website/list API). Site information for the data access configuration; by default, data of the current site is authorized.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/logging_query_rule/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"production_only","desc":"仅允许查看生产环境数据。","indexes":["default"],"roleUUIDs":["role_example"],"conditions":"`env` = '"'"'production'"'"'","extend":{},"logic":"and","maskFields":"message","reExprs":[{"name":"token","enable":true,"reExpr":"tkn_[0-9A-Za-z]+"}]}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content.id integer or null Record number; creation returns a pre-commit snapshot and may be null; use uuid for subsequent operations.
content.uuid string lqrl_ rule UUID; both modules share the same entity and identifier.
content.workspaceUUID string Workspace to which this rule belongs, distinct from the source workspace.
content.status integer 0 enabled, 2 disabled, 3 deleted; reads by this module include only non-deleted records.
content.creator string Creator identity.
content.updator string Last updater identity; may be empty initially.
content.createAt integer Creation Unix seconds.
content.updateAt integer Update Unix seconds; -1 if not updated.
content.deleteAt integer Deletion Unix seconds; -1 if not deleted.
content.name string Saved value: Optional; when omitted/empty string, an attempt is made to generate based on the caller identity display name and the current Unix seconds. Modification also regenerates it and does not retain the old name. Maximum 64 counting units (ASCII/half-width katakana: 1; other characters: 2); both enabled and disabled rules of the same type participate in duplicate-name checks.
content.desc string Saved value: Optional, up to 256 of the same counting units; if omitted/empty string, it is cleared to empty; modification does not retain the original value.
content.indexes array Currently saved log index identifier array; ["*"] means all available log indexes; still subject to actual source authorization.
content.indexes[] string Saved value: Array members are recommended to be non-empty strings; the original declaration did not enforce each item, and an incorrect type can cause a 500.
content.roleUUIDs array Currently saved applicable role UUID array; ["*"] means all roles; [] matches no roles; basic permissions must still be granted independently.
content.roleUUIDs[] string Saved value: Use a valid role; do not use an account UUID.
content.conditions string Currently saved log filter expression; this read does not re-execute event E query validation.
content.extend json Saved value: Optional arbitrary JSON echo; default {}. There are no uniformly required child keys or units; the server does not automatically generate conditions from it. Modifications replace it entirely; do not store credentials.
content.extend.custom key any Saved value: Any serializable JSON value; not an additional effective condition.
content.logic string Saved value: Compatibility echo field, usually and/or; required in the create declaration, can be omitted on modification. If omitted, an empty string is saved; the filter that actually takes effect uses conditions directly. Changing logic does not rewrite conditions, and the merging of multiple roles/rules is not controlled by this field.
content.maskFields string Saved value: Optional; if omitted, an empty string means no field masking is configured for this rule; omitting it on modification clears it. When fields are selected and reExprs=[], non-null values have the entire field masked as ***. When a non-empty regex list is provided, only enabled regexes are applied; all disabled is not the same as full-field masking. It is recommended to keep it ≤256 characters to fit the storage column.
content.reExprs array Saved value: Optional; default []; modifications replace it entirely. On save, every regex is validated, including items with enable=false; an invalid regex returns ft.ErrorRegularExpression. Do not use a standalone * to represent any string; use .*. When selected fields have no regex, the entire field is ***. Regexes only process matching fragments in string content and replace the matched content with ***. Save validation differs from the execution engine; after a successful save, still verify with representative queries.
content.reExprs[] json Saved value: It is recommended to use only name/enable/reExpr; the original declaration did not enforce the structure of array elements; non-objects can cause a 500.
content.reExprs[].name string Saved value: Optional display name; it is not used as the matching expression. Omitting it does not affect regex matching.
content.reExprs[].enable boolean Saved value: It is recommended to use an explicit boolean. If omitted, it is treated as disabled; disabled regexes must still be syntactically valid.
content.reExprs[].reExpr string Saved value: A non-empty regex is recommended. Currently, if omitted, it is checked as an empty string; do not rely on the server to complete a valid expression.
content.sources array Compatibility entity field; for log-specific creation, saves as an empty array; modification does not assign a value and keeps existing content; this API does not accept sources input.
content.sources[] string Saved value: A single source interpreted according to the parent type; a non-empty string is recommended.
content.type string Fixed to logging; this log-specific API does not accept type input.
content.regionCode string Currently saved log source site code; historical empty strings are treated as the current site; does not mean source authorization was created.
content.declaration object or null Workspace common declaration attached to non-empty business objects; may be null or an empty object when not configured; empty objects are not added.
{
  "code": 200,
  "content": {
    "id": null,
    "uuid": "lqrl_example",
    "workspaceUUID": "wksp_example",
    "name": "production_only",
    "desc": "仅允许查看生产环境数据。",
    "type": "logging",
    "indexes": [
      "default"
    ],
    "sources": [],
    "roleUUIDs": [
      "role_example"
    ],
    "conditions": "`env` = 'production'",
    "extend": {},
    "logic": "and",
    "maskFields": "message",
    "reExprs": [
      {
        "name": "token",
        "enable": true,
        "reExpr": "tkn_[0-9A-Za-z]+"
      }
    ],
    "regionCode": "",
    "status": 0,
    "creator": "wsak_example",
    "updator": "",
    "createAt": 1785427200,
    "updateAt": -1,
    "deleteAt": -1,
    "declaration": {}
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed Request field missing, or field value violates the declared validation conditions Parameter parsing failed Check parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Request JSON syntax invalid Request JSON format error Fix the JSON according to content.reason, line, and column.
404 ft.NoInitOtherNodeCfg No available source site address found when reading or validating remote index/RUM application metadata Other node configuration not initialized Ask the administrator to check source site configuration, reachable addresses, and valid cross-workspace authorization, then retry.
400 ft.NameRepeat A non-deleted rule with the same name and type exists in this workspace Name already exists Change the name, or update the existing UUID after verification.
400 ft.ErrorRegularExpression Any regex is invalid, including disabled items Invalid regular expression Fix all reExpr values and submit again; do not use a standalone *.
400 ft.InvalidRoleUUID The given role UUID is not within the allowed workspace scope or the role identifier is invalid Invalid role UUID: {} Obtain a valid identifier from the current workspace role list; when all roles are needed, explicitly use the wildcard configuration supported on this page and do not enter an account UUID.
400 ft.InvalidLoggingIndex The resolved regular index of the source workspace at the current site does not exist/has been deleted Invalid index:{} Use a valid index UUID/default and verify authorization.
400 ft.InvalidRegionDataQueryRuleIndex The indexes of this log rule mix multiple sites, or the index site does not match the source site {} site index information is invalid Configure separately by site and verify the source authorization and site of each log index.
500 ft.InternalServerError Array item shape mismatch, field exceeds storage length, downstream generic 5xx, database failure, or post-commit cache failure Internal error Check the structure and lengths in this document, read the current configuration to confirm whether it has been persisted, then decide whether to retry; provide traceId.

Feedback

Is this page helpful?