# API-Key (header x-api-key) in http request

**URL:** <https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169>\
**Category:** Developing Nodes\
**Created:** [4 May 2021 13:42 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169 "2021-05-04T13:42:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bigberg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigberg/32/36995_2.png) [@Bigberg](https://discourse.nodered.org/u/Bigberg)\
**Post date:** [4 May 2021 13:42 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/1 "2021-05-04T13:42:08Z")

</div>

I want to create a simple query on a cloud-based software.  
I get the message "ENETUNREACH" in all tried versions  
I know that I have to set the header x-api-key with the key.  
I do this GET query in Postman = Y\> works  
I do the query in Node.js =\> works  
But I just don't get the part in the node red.  
Here is the information I need to create the GET query:

Url: [https://api.airkey.evva.com:443/cloud/v1/customer](https://api.airkey.evva.com:443/cloud/v1/customer)  
x-api-key: xxxx  
Content-Type: application / json

Currently it seems to me that I am not that far away from it:  
`[{"id":"340899c6.d3b816","type":"tab","label":"Airkey API Test","disabled":false,"info":""},{"id":"49a54f77.b8319","type":"function","z":"340899c6.d3b816","name":"set payload and headers","func":"msg.headers = {};\nmsg.headers['x-api-key'] = 'xxx';\nmsg.headers['Content-Type'] = 'application/json';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":220,"wires":[["dec76f59.1b076"]]},{"id":"32f4730e.9bad8c","type":"inject","z":"340899c6.d3b816","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":180,"y":220,"wires":[["49a54f77.b8319"]]},{"id":"404fc276.fd378c","type":"debug","z":"340899c6.d3b816","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":220,"wires":[]},{"id":"dec76f59.1b076","type":"http request","z":"340899c6.d3b816","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.airkey.evva.com:443/cloud/v1/customer","tls":"","persist":false,"proxy":"","authType":"","x":610,"y":220,"wires":[["404fc276.fd378c"]]}]`

I hope someone can help me and tell me what I'm doing wrong.  
Many thanks for the support.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 May 2021 13:47 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/2 "2021-05-04T13:47:54Z")

</div>

your flow is completely corrupted.

can you paste it again?

In order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [4 May 2021 13:56 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/4 "2021-05-04T13:56:11Z")

</div>

Hi @Bigberg

At the end of your function you need to `return msg`.

---

<div class="post-metadata">

**Author:** ![Bigberg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigberg/32/36995_2.png) [@Bigberg](https://discourse.nodered.org/u/Bigberg)\
**Post date:** [4 May 2021 14:37 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/5 "2021-05-04T14:37:38Z")

</div>

I adjusted it (the corrupt flow)

in the functions node I have the "return msg;" inside

---

<div class="post-metadata">

**Author:** ![Bigberg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigberg/32/36995_2.png) [@Bigberg](https://discourse.nodered.org/u/Bigberg)\
**Post date:** [4 May 2021 14:40 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/6 "2021-05-04T14:40:59Z")

</div>

here is the function node:  
msg.headers = {};  
msg.headers ['x-api-key'] = 'xxx';  
msg.headers ['Content-Type'] = 'application / json';  
return msg;

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 May 2021 20:29 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/7 "2021-05-04T20:29:08Z")

</div>

> [@Bigberg](#):
>
> I get the message "ENETUNREACH"

On the machine running node-red are you able to `ping api.airkey.evva.com`. Are you running node-red in a container such as Docker? If so does the ping work from within the container?

---

<div class="post-metadata">

**Author:** ![Bigberg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigberg/32/36995_2.png) [@Bigberg](https://discourse.nodered.org/u/Bigberg)\
**Post date:** [5 May 2021 07:47 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/8 "2021-05-05T07:47:14Z")

</div>

Thanks for the input.  
Yes, the goal is achievable. I am also shown the IP with the ENETUNREACH report.  
Node-red runs on a Raspberry and not in a Docker.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 July 2021 07:48 UTC](https://discourse.nodered.org/t/api-key-header-x-api-key-in-http-request/45169/9 "2021-07-04T07:48:02Z")

</div>

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