Connection issues using apikey

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 APIs 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 :thinking:?

Many thanks in advance!

The confusion here is that the Elastic Cloud API is different to the Elasticsearch one.
RESTful API | Elasticsearch Service Documentation | Elastic 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 for accessing Elasticsearch directly :slight_smile:

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

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

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"

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