# \[Kibana API\] Cannot list rules using Kibana API, successfull response, empty data

**URL:** <https://discuss.elastic.co/t/kibana-api-cannot-list-rules-using-kibana-api-successfull-response-empty-data/363414>\
**Category:** Kibana\
**Tags:** elastic-stack-security\
**Created:** [July 19, 2024, 10:36am UTC](https://discuss.elastic.co/t/kibana-api-cannot-list-rules-using-kibana-api-successfull-response-empty-data/363414 "2024-07-19T10:36:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wocek](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@wocek](https://discuss.elastic.co/u/wocek)\
**Post date:** [July 19, 2024, 10:36am UTC](https://discuss.elastic.co/t/kibana-api-cannot-list-rules-using-kibana-api-successfull-response-empty-data/363414/1 "2024-07-19T10:36:44Z")

</div>

Hi all!

I'm having a peculiar problem with Kibana API. I'm writing a powershell script to manage my rules/alerts. Here's the problem:

I want to hit this endpoint `/api/alerting/rules/_find`  
to retrieve list of rules that are currently deployed in the stack. I can easily retrieve it using Dev Console but when I'm trying to execute Invoke-RestMethod with powershell all I'm getting is

```auto
{
    "page": 1,
    "total": 0,
    "per_page": 10,
    "data": [

             ]
}

```

I have created two API Keys - first as elastic superuser, second as kibana\_admin, with no restriction on priveledges and neither gives results.  
This is my piece of code:

```auto
$headers = @{
    'kbn-xsrf' = 'true'
    'Authorization' = "ApiKey $KibanaAPIKey"
}

$get_get_rules_api_call = "/api/alerting/rules/_find"
Invoke-RestMethod -Method GET -Headers $headers -Uri $https://<kibana_host>:<kibana_port>$get_get_rules_api_call -ContentType "text/json" | ConvertTo-Json

```

I was also trying with basic authentication, with both elastic superuser and kibana\_admin but to no avail. With basic authentication I'm getting unauthorized error.

```auto
$Token = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("username:password"))

$headers = @{
    'kbn-xsrf' = 'true'
    'Authorization' = "Basic $Token"
}

$get_get_rules_api_call = "/api/alerting/rules/_find"
Invoke-RestMethod -Method GET -Headers $headers -Uri $https://<kibana_host>:<kibana_port>$get_get_rules_api_call -ContentType "text/json" | ConvertTo-Json

```

```auto
Invoke-RestMethod : {"statusCode":401,"error":"Unauthorized","message":"[security_exception\n\tRoot causes:\n\t\tsecurity_exception: unable t
o authenticate user [k\u0000i\u0000b\u0000a\u0000n\u0000a\u0000_\u0000a\u0000p\u0000i\u0000_\u0000c\u0000a\u0000l\u0000l\u0000s\u0000_\u0000u
\u0000s\u0000e\u0000r\u0000] for REST request [/_security/_authenticate]]: unable to authenticate user [k\u0000i\u0000b\u0000a\u0000n\u0000a\
u0000_\u0000a\u0000p\u0000i\u0000_\u0000c\u0000a\u0000l\u0000l\u0000s\u0000_\u0000u\u0000s\u0000e\u0000r\u0000] for REST request [/_security/
_authenticate]"}

```

Any help would be grealty appreciated
