Http API call using "http request" node receives "access denied" response

I'd like to know if anyone else has seen similar problems and has a solution. I have no problem with most API's using the Node-RED HTTP Request Node. But when call APIs at https://api.weather.gov, I receive an "access denied" (403 error, I assume) response to all my GET requests.

Simplest call would be to: https://api.weather.gov/

Using CURL and my Chrome browser the response is:
{
"status": "OK"
}

However when using Node-RED HTTP Request Node the response (debug node output) is:

Access Denied

Access Denied

You don't have permission to access "http://api.weather.gov/" on this server.


Reference #18.66c32f17.1587072906.2247fc

Some APIs require the request to include a User-Agent http header - something the HTTP Request node doesn't set by default.

You could trying adding the header to see if that works.

This recipe shows how to set headers for the Request node: https://cookbook.nodered.org/http/set-request-header

1 Like

Thank you, adding the header works:
msg.url = "https://api.weather.gov";
msg.headers = {};
msg.headers['USER-AGENT'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36';

return msg;

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