# Connection issues using apikey

**URL:** <https://discuss.elastic.co/t/connection-issues-using-apikey/261452>\
**Category:** Elasticsearch\
**Created:** [January 18, 2021, 4:51pm UTC](https://discuss.elastic.co/t/connection-issues-using-apikey/261452 "2021-01-18T16:51:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LarryLeisure](https://avatars.discourse-cdn.com/v4/letter/l/3bc359/32.png) [@LarryLeisure](https://discuss.elastic.co/u/LarryLeisure)\
**Post date:** [January 18, 2021, 4:51pm UTC](https://discuss.elastic.co/t/connection-issues-using-apikey/261452/1 "2021-01-18T16:51:47Z")

</div>

Dear all,

I have just recently started working with ElasticSearch and Rest APIs and would like to ask for your help concerning the following issue:

I am using a trial version of ElasticSearch Cloud Service, set up a deployment (Version 7.10.2 ) hosted on AWS and imported the "kibana\_sample\_data\_flights" data set.

The overall goal of my use case is to retrieve cloud-stored data using Rest APIs. As a first step in my "learning journey", I copied the Elasticsearch endpoint from the webpage and was able to perform a basic health check with:  
`curl -X GET "https://<copyPastedEndpoint>:9243/_health"`  
returning  
`{"ok": true, "status": 200}`

Next, I wanted to get a list of all indices, so I generated an API key according to the [Getting Started Manual on REST API](https://www.elastic.co/guide/en/cloud/current/ec-api-authentication.html)s and built following request:  
`curl -v -H "Authorization: ApiKey <copyPastedApiKey>" -X GET "https://<copyPastedEndpoint>:9243/_cat/indices"`

Unfortunately, since then I got stuck with this error message:  
`{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/_cat/indices]","header":{"WWW-Authenticate":["Basic realm=\"security\" charset=\"UTF-8\"","Bearer realm=\"security\"","ApiKey"]}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/_cat/indices]","header":{"WWW-Authenticate":["Basic realm=\"security\" charset=\"UTF-8\"","Bearer realm=\"security\"","ApiKey"]}},"status":401}`

Since searching the forum and the web did not really help, I would be very happy if anybody could give me a hint what I have done wrong...

Can I make REST requests using the trial version at all?  
Is it correct to simply paste the complete API-key-string in the request after the keyword "ApiKey"? I understand that `$EC_API_KEY` (as mentioned in the manual) is just a variable containing the key, right?  
By the way: Shouldn't it be $ES\_API\_KEY 🤔?

Many thanks in advance!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 19, 2021, 11:11pm UTC](https://discuss.elastic.co/t/connection-issues-using-apikey/261452/2 "2021-01-19T23:11:44Z")

</div>

The confusion here is that the Elastic Cloud API is different to the Elasticsearch one.  
[RESTful API | Elasticsearch Service Documentation | Elastic](https://www.elastic.co/guide/en/cloud/current/ec-restful-api.html) is for managing your account and associated clusters.

The `_cat/` APIs are for direct cluster interaction. And you will want to look at [Securing your deployment | Elasticsearch Service Documentation | Elastic](https://www.elastic.co/guide/en/cloud/current/ec-security.html) for accessing Elasticsearch directly 🙂

> [@LarryLeisure](#):
>
> By the way: Shouldn't it be $ES\_API\_KEY

EC = Elastic Cloud  
ES = Elasticsearch  
Technically, you're talking to Elasticsearch through the Elastic Cloud API layer. But you have a point 🙂

---

<div class="post-metadata">

**Author:** ![LarryLeisure](https://avatars.discourse-cdn.com/v4/letter/l/3bc359/32.png) [@LarryLeisure](https://discuss.elastic.co/u/LarryLeisure)\
**Post date:** [January 21, 2021, 4:10pm UTC](https://discuss.elastic.co/t/connection-issues-using-apikey/261452/3 "2021-01-21T16:10:17Z")

</div>

Thank you for showing me the difference between the two APIs. Reading the docs (again), their purpose is now absolutely clear to me 🙄

However, I managed to get what I wanted with this line of code:  
`curl -u elastic:myElasticPassword -X GET "https://<copyPastedEndpoint>:9243/kibana_sample_data_flights/_search?pretty"`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 18, 2021, 4:10pm UTC](https://discuss.elastic.co/t/connection-issues-using-apikey/261452/4 "2021-02-18T16:10:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
