# How to pass user credential to REST api?

**URL:** https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562
**Category:** Elasticsearch
**Created:** [June 10, 2021, 12:04pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562 "2021-06-10T12:04:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ashwin\_Srivastav](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@Ashwin\_Srivastav](https://discuss.elastic.co/u/Ashwin_Srivastav)
#### Post date: [June 10, 2021, 12:04pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/1 "2021-06-10T12:04:03Z")

</div>

I have coded a REST api which basically inserts, gets and updates the data from Elasticsearch. After implementing the basic security when I pass a curl command to the api providing credentials along with it (using -u), I get the following error:

```auto
[type=security_exception, reason=unable to authenticate user [a] for REST request]

```

Any idea how to pass the credentials to the REST api so that the same can pass it to Elasticsearch?  
I am using version 6.8.16.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 10, 2021, 12:32pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/2 "2021-06-10T12:32:26Z")

</div>

I don't understand what you did and how. Could you share some code?

---

<div class="post-metadata">

### Author: ![Ashwin\_Srivastav](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@Ashwin\_Srivastav](https://discuss.elastic.co/u/Ashwin_Srivastav)
#### Post date: [June 10, 2021, 12:55pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/3 "2021-06-10T12:55:34Z")

</div>

@dadoonet The code is there in many files and is very long. So I don't think it will be feasible to share the code.  
Basically the api builds the query from the curl command which is passed to it in some manner. After building the query it calls Elasticsearch with the built query.  
I hope it helps in some way.

---

<div class="post-metadata">

### Author: ![theDor](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@theDor](https://discuss.elastic.co/u/theDor)
#### Post date: [June 10, 2021, 6:40pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/4 "2021-06-10T18:40:20Z")

</div>

What code language u are using? it should come as additonal optional parameters when you pass the request

---

<div class="post-metadata">

### Author: ![Ashwin\_Srivastav](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@Ashwin\_Srivastav](https://discuss.elastic.co/u/Ashwin_Srivastav)
#### Post date: [June 11, 2021, 7:33am UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/5 "2021-06-11T07:33:29Z")

</div>

@theDor I am using JAVA. Should I pass it as a header? Will it work?

---

<div class="post-metadata">

### Author: ![theDor](https://avatars.discourse-cdn.com/v4/letter/t/b4bc9f/32.png) [@theDor](https://discuss.elastic.co/u/theDor)
#### Post date: [June 11, 2021, 4:44pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/6 "2021-06-11T16:44:56Z")

</div>

Are u using elasticsearch client or http generic client?

---

<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: [July 9, 2021, 4:45pm UTC](https://discuss.elastic.co/t/how-to-pass-user-credential-to-rest-api/275562/7 "2021-07-09T16:45:12Z")

</div>

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