Urgent , Please how can i add Authorisation header to HTTPP request on node - red for API

Hi Guys !

i often received this message Authentication credentials were not provided.

please i have been wondering how to add an authorisation API for GET request for HTTP request. on node -red.
i have tried it on Post Man and it works very fine here is the result

[
    {
        "timestamp": "2021-11-22T22:40:00",
        "load_state": "ON",
        "load_w": 148.946,
        "output_wh_total": 4003.0,
        "output_wh_delta": 49.0,
        "solar_w": 0.0,
        "solar_v": 3.832,
        "input_wh_total": 0.0,
        "bat_v": 25.258,
        "state_of_charge": 100,
        "full_charges_count": 1,
        "deep_discharges_count": 0,
        "bat_chg_total_wh": 0,
        "bat_dis_total_wh": 4003,
        "bat_usable_ah": 0.0,
        "bat_temp": 36.148,
        "restart_detected": false,
        "signal_strength": -59,
        "error_flag": 0
    }
]

the API is  `https://cloud-solar.com/api/v1/devices/xokM5P/reports?start=1637620800&end=1637620811`

and the header is ` Authorisation: Token 6d423a90252863e3f4cc068546617b452031d167`

just like this 
`
![image|690x450](upload://bBv4RQiOGDLVyFzwx4GBnlmMvkM.png)
`
![image|690x450](upload://bBv4RQiOGDLVyFzwx4GBnlmMvkM.png)

thanks

It depends on what the header needs to contain, but have you tried the 'Use authentication' option in the node?

wow !

thanks for your reactivity.

yes but i don't know the username and the password.
i am only having the unique API KEY

Authorisation: Token 6d423a90252863e3f4cc068546617b452031d167

thanks

Okay - so that isn't a standard format for the Authorisation header, so the node won't be able to set the header for you.

Instead, add a Function node before the HTTP Request node with:

msg.headers = {
   "Authorisation": "Token 1234...."
}
return msg
1 Like

thanks let me do it now,

thanks again !

@knolleary
that is exactly what i did

msg.headers = {
   "Authorisation": "Token 6d423a90252863e3f4cc068546617b452031d167"
}
return msg

but i get this Authentication credentials were not provided.

whereas it works well on post man

what do you thing might the issues?

hi @knolleary

:sunglasses::sunglasses:

thanks it is working now

{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

Authorisation should probably be Authorization (UK vs US English...)

:blush: yeah you are right that is what i corrected.

thanks too

@hardillb @knolleary

i am not so good in NodeJs,
please how can i filter the the messages so that i will only debug few of the messages
the messages are {"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

i want to display these values

1."load_state"
2."bat_v"
3."load_w"
3. "bat_temp"

thanks fro your help !