Sending an API Key as a Header (Calling REST)

Hello,

I've read this Calling REST api
and know that to query an API requires an inject, change, http request, and debug node.

I'm trying to send a GET request to this API, but to receive a 2xx response I need to include an API key, so I'm trying to do that with a msg.header in the change node, but am uncertain if I should do that with string format. I'm trying to use JSON.

Guidance on how to structure the msg.header object so the API accepts the key would be appreciated.

Headers need to be an array of objects where the object key is the header name and the object value is the header value.

Something like (untested):

msg.headers = [
    "Ocp-Apim-Subscription-Key": "069525d4f10146dea45c8d6bb3d81905",
]

That is actually pretty close to what I tried with a function node, I just used brackets {} to contain the JSON. No such luck. The change node I worked with was somewhat less clear.

My bad, of course I forgot the inner {}

[{"id":"55e06a3a.782524","type":"change","z":"63281c77.40a064","name":"","rules":[{"t":"set","p":"headers","pt":"msg","to":"[{\"Ocp-Apim-Subscription-Key\":\"069525d4f10146dea45c8d6bb3d81905\"}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1660,"wires":[[]]}]
msg.headers = [
    {
        "Ocp-Apim-Subscription-Key": "069525d4f10146dea45c8d6bb3d81905"
    }
]

Hm. Surprisingly, there seems to be an error symbol no matter which brackets I use.

I figured out it didn't need JSON, and successfully queried the API.
{"events":,"hasErrors":false,"message":"Success"}

Used:

"msg.headers = {};
msg.headers['']="";

return msg;"

In my function node.

Should just be { } ... no needed.

msg.headers =  {
        "Ocp-Apim-Subscription-Key": "069525d4f10146dea45c8d6bb3d81905"
    }