# Call elasticsearch API from custom Kibana plugin with relative url

**URL:** <https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980>\
**Category:** Security\
**Created:** [September 10, 2021, 10:21am UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980 "2021-09-10T10:21:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![disha27](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@disha27](https://forum.opensearch.org/u/disha27)\
**Post date:** [September 10, 2021, 10:21am UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/1 "2021-09-10T10:21:03Z")

</div>

I have created a custom kibana plugin, in that plugin i wanted to get infromation of user which has login with inbuilt API “GET \_opendistro/\_security/api/account”

I searched for [API Reference | JavaScript](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html)  
In elastic they have below function call to do so.

#### client.security.authenticate()

what will be the opendistro version of this?

#### client.opendistro.security.api.account()

Can anybody has solution for how can I call above API from kibana custom plugin using server.route with relative url.

---

<div class="post-metadata">

**Author:** ![searchymcsearchface](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/searchymcsearchface/32/868_2.png) [@searchymcsearchface](https://forum.opensearch.org/u/searchymcsearchface)\
**Post date:** [September 10, 2021, 1:50pm UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/2 "2021-09-10T13:50:46Z")

</div>

Hey @disha27! I’m moving this to the security category - you’ll get a better answer in that category.

---

<div class="post-metadata">

**Author:** ![Anthony](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/anthony/32/9939_2.png) [@Anthony](https://forum.opensearch.org/u/Anthony)\
**Post date:** [September 10, 2021, 4:58pm UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/3 "2021-09-10T16:58:01Z")

</div>

@disha27  
As you are using node.js client provided by elastic, this intentionally will not have support for opendistro.

Currently there are efforts to add new open source clients for connecting applications to any OpenSearch or Elasticsearch version 7 cluster, see further details [here](https://opensearch.org/blog/community/2021/08/community-clients/)

But as of now, I don’t think there is anything else to offer the functionality you are looking for.

---

<div class="post-metadata">

**Author:** ![disha27](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@disha27](https://forum.opensearch.org/u/disha27)\
**Post date:** [September 13, 2021, 7:13am UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/4 "2021-09-13T07:13:41Z")

</div>

okay, my requirement is to disable custom plugin access for non-admin user. either by hiding it from left panel as like security plugin or disable text fields of all forms available inside plugin.  
Is there any other way to check currently login user is admin or not and disable plugin access based on it?

---

<div class="post-metadata">

**Author:** ![Anthony](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/anthony/32/9939_2.png) [@Anthony](https://forum.opensearch.org/u/Anthony)\
**Post date:** [September 13, 2021, 8:23am UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/5 "2021-09-13T08:23:39Z")

</div>

@disha27  
You should be able to call rest api \_opendistro/\_security/api/account from within your plugin using something like [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback), it might be awkward but should work.

---

<div class="post-metadata">

**Author:** ![disha27](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@disha27](https://forum.opensearch.org/u/disha27)\
**Post date:** [September 13, 2021, 8:32am UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/6 "2021-09-13T08:32:28Z")

</div>

I thought of using it this way as the last option. If there is no other way I may use axios to call this API.  
but there is issue with this approach.  
as elasticsearch API needs username/password, this API will print ouput for the user I have used to access API and not for the user logged in from kibana.

---

<div class="post-metadata">

**Author:** ![disha27](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@disha27](https://forum.opensearch.org/u/disha27)\
**Post date:** [September 14, 2021, 2:21pm UTC](https://forum.opensearch.org/t/call-elasticsearch-api-from-custom-kibana-plugin-with-relative-url/6980/7 "2021-09-14T14:21:16Z")

</div>

How security plugin is checking for the user is admin or not? Can I use the same part of code here in my plugin?
