# Why I can't make simple search request to my Elastic App Search?

**URL:** <https://discuss.elastic.co/t/why-i-cant-make-simple-search-request-to-my-elastic-app-search/250147>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [September 28, 2020, 8:22am UTC](https://discuss.elastic.co/t/why-i-cant-make-simple-search-request-to-my-elastic-app-search/250147 "2020-09-28T08:22:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah\_182](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@sarah\_182](https://discuss.elastic.co/u/sarah_182)\
**Post date:** [September 28, 2020, 8:22am UTC](https://discuss.elastic.co/t/why-i-cant-make-simple-search-request-to-my-elastic-app-search/250147/1 "2020-09-28T08:22:54Z")

</div>

so I want to make search request to my elastic enterprise search app using guide from the [documentation in here](https://www.elastic.co/guide/en/app-search/current/search.html) , I don't want to use elastic node JS client, but I want to make http request using axios.

here is the code I use

```
        const url = "https://XXXXXXX38ce49e5aff1aa238e6f9195.ent-search.asia-southeast1.gcp.elastic-cloud.com/api/as/v1/engines/events/search"
        const headers = {"Authorization": "Bearer search-qpz4bu5o7ubb8j31r15juyrh"}
        const jsonData = {
            query: "hello there"
        }
    
    
        try {
    
            const {data} = await axios.post(url,jsonData,headers)
            response.status(200).send(data)
    
        } catch (error) {
            console.log(error)
            response.status(500).send(error)
    
        }

```

but I always get 401 error like this:

```
 {
        "message": "Request failed with status code 401",
        "name": "Error",
        "stack": "Error: Request failed with status code 401\n at createError (/Users/xxx/Documents/elastic_jxxx/firebase_emulator/functions/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/Users/xxxx/Documents/elastic_jakarta_kumpul_muslim/firebase_emulator/functions/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/Users/xxxxx/Documents/elastic_xxxxx/firebase_emulator/functions/node_modules/axios/lib/adapters/http.js:244:11)\n at IncomingMessage.emit (events.js:203:15)\n at endReadableNT (_stream_readable.js:1145:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)",
        "config": {
            "url": "https://XXXXXXXa638ce49e5aff1aa238e6f9195.ent-search.asia-southeast1.gcp.elastic-cloud.com/api/as/v1/engines/events/search",
            "method": "post",
            "data": "{\"query\":\"hello there\"}",
            "headers": {
                "Accept": "application/json, text/plain, */*",
                "Content-Type": "application/json;charset=utf-8",
                "User-Agent": "axios/0.20.0",
                "Content-Length": 28
            },
            "transformRequest": [
                null
            ],
            "transformResponse": [
                null
            ],
            "timeout": 0,
            "xsrfCookieName": "XSRF-TOKEN",
            "xsrfHeaderName": "X-XSRF-TOKEN",
            "maxContentLength": -1,
            "maxBodyLength": -1,
            "Authorization": "Bearer search-qpz4bu5o7ubb8j31r15juyrh"
        }
    }

```

I believe I have put the correct search key, I can get the sucessful response using the same baseURL and search key in postman like this

could you please me ?

 ![Screen Shot 2020-09-28 at 14.44.39](https://us1.discourse-cdn.com/elastic/original/3X/2/6/26f3b6b2ac5bdafc2d37431a3977ca93cfe6fcd2.png)

---

<div class="post-metadata">

**Author:** ![constancecchen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/constancecchen/32/71762_2.png) [@constancecchen](https://discuss.elastic.co/u/constancecchen)\
**Post date:** [September 29, 2020, 5:26pm UTC](https://discuss.elastic.co/t/why-i-cant-make-simple-search-request-to-my-elastic-app-search/250147/2 "2020-09-29T17:26:54Z")

</div>

Based on axios' documentation, I think it's your headers config that needs fixing. Try this:

```auto
const { data } = await axios.post(url, jsonData, { headers });

```

The issue is that your Authorization header needs to be nested under the `headers` key - the 3rd param/arg is for general configuration, not just headers specifically. Hope that makes sense 🙂

---

<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:** [October 27, 2020, 5:26pm UTC](https://discuss.elastic.co/t/why-i-cant-make-simple-search-request-to-my-elastic-app-search/250147/3 "2020-10-27T17:26:56Z")

</div>

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