> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/xdr-5-api/cortex-platform/query-library.md).

# Query Library

APIs for managing XQL query libraries

## Get XQL Queries

> Retrieve a detailed list of XQL query libraries. You can filter by list of query names or by list of query tags.\
> \
> Requires the granular RBAC permission for this feature.

```json
{"openapi":"3.0.0","info":{"title":"Cortex XDR Platform APIs","version":"Cortex XDR 5.2"},"tags":[{"name":"Query Library","description":"APIs for managing XQL query libraries"}],"servers":[{"url":"https://api-yourfqdn"}],"paths":{"/public_api/xql_library/get":{"post":{"tags":["Query Library"],"summary":"Get XQL Queries","description":"Retrieve a detailed list of XQL query libraries. You can filter by list of query names or by list of query tags.\n\nRequires the granular RBAC permission for this feature.","parameters":[{"schema":{"type":"string"},"in":"header","name":"Authorization","description":"{api_key}","required":true},{"schema":{"type":"string"},"in":"header","name":"x-xdr-auth-id","description":"{api_key_id}","required":true}],"operationId":"post-public_api-xql_library-get","requestBody":{"content":{"application/json":{"schema":{"required":["request_data"],"type":"object","properties":{"request_data":{"type":"object","properties":{"extended_view":{"type":"boolean","description":"Whether to retrieve the detailed information on each XQL query.","default":false},"xql_query_names":{"type":"array","description":"An array of XQL query names to search for. Note: If searching by `xql_query_names`, you cannot search by `xql_query_tags` in the same call.","items":{"type":"string"}},"xql_query_tags":{"type":"array","description":"An array of XQL tag names to search for. Note: If searching by `xql_query_tags`, you cannot search by `xql_query_names` in the same call.","items":{"type":"string"}}}}}}}},"required":false},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"reply":{"type":"object","properties":{"queries_count":{"type":"integer"},"xql_queries":{"type":"array","items":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"description":{"type":"string"},"query_text":{"type":"string"},"created_at":{"type":"integer"},"created_by":{"type":"string"},"created_by_pretty":{"type":"string"},"query_metadata":{"type":"object","properties":{"is_valid":{"type":"boolean"},"query_calls":{"type":"array","items":{"type":"object","properties":{}}},"is_datamodel":{"type":"boolean"},"query_tables":{"type":"array","items":{"type":"string"}},"query_presets":{"type":"array","items":{"type":"object","properties":{}}}}},"is_private":{"type":"boolean"},"labels":{"type":"array","items":{"type":"string"}}}}}}}}}},"Example 1":{},"With extended view":{}}},"400":{"description":"Bad Request. Got an invalid JSON.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"401":{"description":"Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"402":{"description":"Unauthorized access. User does not have the required license type to run this API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"403":{"description":"Forbidden access. The provided API Key does not have the required RBAC permissions to run this API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"500":{"description":"Internal server error. A unified status for API communication type errors.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}}}}}},"components":{"schemas":{"reply":{"type":"object","title":"reply","description":"The query result upon error.","properties":{"err_code":{"type":"string","description":"HTTP response code."},"err_msg":{"type":"string","description":"Error message."},"err_extra":{"type":"string","description":"Additional information describing the error."}}}}}}
```

## Insert or update XQL queries

> Insert new XQL queries or update existing XQL queries.\
> \
> \*\*Note:\*\* You should use unique \`xql\_query\_name\` for each XQL query on a given tenant.\
> \
> Requires the granular RBAC permission for this feature.

```json
{"openapi":"3.0.0","info":{"title":"Cortex XDR Platform APIs","version":"Cortex XDR 5.2"},"tags":[{"name":"Query Library","description":"APIs for managing XQL query libraries"}],"servers":[{"url":"https://api-yourfqdn"}],"paths":{"/public_api/xql_library/insert":{"post":{"tags":["Query Library"],"summary":"Insert or update XQL queries","description":"Insert new XQL queries or update existing XQL queries.\n\n**Note:** You should use unique `xql_query_name` for each XQL query on a given tenant.\n\nRequires the granular RBAC permission for this feature.","parameters":[{"schema":{"type":"string"},"in":"header","name":"Authorization","description":"{api_key}","required":true},{"schema":{"type":"string"},"in":"header","name":"x-xdr-auth-id","description":"{api_key_id}","required":true}],"operationId":"post-public_api-xql_library-insert","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["request_data"],"properties":{"request_data":{"type":"object","required":["xql_queries"],"properties":{"xql_queries_override":{"type":"boolean","description":"When the `xql_query_name` already exists on the tenant, this field defines whether or not to overwrite the existing XQL query with the new content. When `true`, the query will be overwritten. When `false`, the query will not be updated and an error will be returned.","default":false},"xql_queries":{"type":"array","items":{"type":"object","required":["xql_query","xql_query_name"],"properties":{"xql_query":{"type":"string"},"xql_query_name":{"type":"string","description":"XQL query name should be unique."}}}},"xql_query_tags":{"type":"array","description":"XQL query tags are optional","items":{"type":"string"}}}}}}}},"required":false},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"reply":{"type":"object","properties":{"xql_queries_added":{"type":"array","description":"List of XQL queries that were added.","items":{"type":"string"}},"xql_queries_updated":{"type":"array","description":"List of XQL queries that were updated.","items":{"type":"string"}},"errors":{"type":"array","description":"List of errors received from additions/updates.","items":{"type":"string"}}}}}}},"Example 1":{}}},"400":{"description":"Bad Request. Got an invalid JSON.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"401":{"description":"Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"402":{"description":"Unauthorized access. User does not have the required license type to run this API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"403":{"description":"Forbidden access. The provided API Key does not have the required RBAC permissions to run this API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"500":{"description":"Internal server error. A unified status for API communication type errors.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}}}}}},"components":{"schemas":{"reply":{"type":"object","title":"reply","description":"The query result upon error.","properties":{"err_code":{"type":"string","description":"HTTP response code."},"err_msg":{"type":"string","description":"Error message."},"err_extra":{"type":"string","description":"Additional information describing the error."}}}}}}
```

## Delete XQL Queries

> Delete XQL queries. You can filter by list of query names or by list of query tags.\
> \
> Requires the granular RBAC permission for this feature.

```json
{"openapi":"3.0.0","info":{"title":"Cortex XDR Platform APIs","version":"Cortex XDR 5.2"},"tags":[{"name":"Query Library","description":"APIs for managing XQL query libraries"}],"servers":[{"url":"https://api-yourfqdn"}],"paths":{"/public_api/xql_library/delete":{"post":{"tags":["Query Library"],"summary":"Delete XQL Queries","description":"Delete XQL queries. You can filter by list of query names or by list of query tags.\n\nRequires the granular RBAC permission for this feature.","parameters":[{"schema":{"type":"string"},"in":"header","name":"Authorization","description":"{api_key}","required":true},{"schema":{"type":"string"},"in":"header","name":"x-xdr-auth-id","description":"{api_key_id}","required":true}],"operationId":"post-public_api-xql_library-delete","requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["request_data"],"properties":{"request_data":{"type":"object","properties":{"xql_query_names":{"type":"array","description":"List of XQL query names to delete. Note: If searching by `xql_query_names`, you cannot search by `xql_query_tags` in the same call.","items":{"type":"string"}},"xql_query_tags":{"type":"array","description":"List of XQL query tags. Note: If searching by `xql_query_tags`, you cannot search by `xql_query_names` in the same call.","items":{"type":"string"}}}}}}}},"required":false},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"reply":{"type":"object","properties":{"queries_count":{"type":"integer"},"xql_query_names":{"type":"array","items":{"type":"string"}},"errors":{"type":"array","items":{"type":"object","properties":{}}}}}}}},"Example 1":{}}},"400":{"description":"Bad Request. Got an invalid JSON.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"401":{"description":"Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"402":{"description":"Unauthorized access. User does not have the required license type to run this API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"403":{"description":"Forbidden access. The provided API Key does not have the required RBAC permissions to run this API.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}},"500":{"description":"Internal server error. A unified status for API communication type errors.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/reply"}}}}}}}},"components":{"schemas":{"reply":{"type":"object","title":"reply","description":"The query result upon error.","properties":{"err_code":{"type":"string","description":"HTTP response code."},"err_msg":{"type":"string","description":"Error message."},"err_extra":{"type":"string","description":"Additional information describing the error."}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/xdr-5-api/cortex-platform/query-library.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
