# Unable to connect to Enterprise App Search via Node.js

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-enterprise-app-search-via-node-js/270611>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 19, 2021, 5:34pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-enterprise-app-search-via-node-js/270611 "2021-04-19T17:34:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shoto\_Todoroki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shoto_todoroki/32/86988_2.png) [@Shoto\_Todoroki](https://discuss.elastic.co/u/Shoto_Todoroki)\
**Post date:** [April 19, 2021, 5:34pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-enterprise-app-search-via-node-js/270611/1 "2021-04-19T17:34:02Z")

</div>

Hi, I am trying to connect to Enterprise App Search via node.js. I followed the below github code  
[https://github.com/elastic/app-search-node](https://github.com/elastic/app-search-node)

but this is the error I am getting while connecting to the enterprise engine I have.

```auto
    Error: Unauthorized
    at Request._callback (D:\Web and App stuffs\Node.js\elastic-search\node_modules\@elastic\app-search-node\lib\client.js:95:26)   
    at Request.self.callback (D:\Web and App stuffs\Node.js\elastic-search\node_modules\request\request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.<anonymous> (D:\Web and App stuffs\Node.js\elastic-search\node_modules\request\request.js:1154:10)
    at Request.emit (events.js:315:20)
    at IncomingMessage.<anonymous> (D:\Web and App stuffs\Node.js\elastic-search\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (events.js:421:28)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errorMessages: [
    {
      root_cause: [Array],
      type: 'security_exception',
      reason: 'missing authentication credentials for REST request [/engines/test-engine/documents]',
      header: [Object]
    }
  ]
}

```

Can anyone let me know how do I add my credentials ? This is my code

```auto
const AppSearchClient = require('@elastic/app-search-node');
const apiKey = 'API_KEY'
const baseUrlFn = () => 'Here I am using my Enterprise App Search Endpoint API'

const client = new AppSearchClient(undefined, apiKey, baseUrlFn)

//A dummy data to add
let data = {
    "id": "some123",
    "title": "random",
    "description": "Split into the separate Rincon Mountain and Tucson Mountain districts, this park is evidence that the dry Sonoran Desert is still home to a great variety of life spanning six biotic communities. Beyond the namesake giant saguaro cacti, there are barrel cacti, chollas, and prickly pears, as well as lesser long-nosed bats, spotted owls, and javelinas.",
    "nps_link": "https://www.nps.gov/sagu/index.htm",
    "states": [
        "Arizona"
    ],
    "visitors": 838456,
    "world_heritage_site": false,
    "location": "32.20,-109.5",
    "acres": 9215.72,
    "square_km": 2271.2,
    "date_established": "1997-10-14T05:00:00Z"
}
    client
        .indexDocuments('test-engine', data)
        .then(response => {
            console.log(response)
            return res.status(200).json({
                message: response.body
            })
        }).catch(error => console.log(error))

```

---

<div class="post-metadata">

**Author:** ![Byron\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byron_h/32/82245_2.png) [@Byron\_H](https://discuss.elastic.co/u/Byron_H)\
**Post date:** [April 19, 2021, 7:59pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-enterprise-app-search-via-node-js/270611/2 "2021-04-19T19:59:08Z")

</div>

Hi @Shoto_todoroki, can you please share with me the versions of App Search and Elasticsearch you are running?

---

<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:** [May 17, 2021, 7:59pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-enterprise-app-search-via-node-js/270611/3 "2021-05-17T19:59:55Z")

</div>

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