Cannot get endpoint configured in Node-red

Hi ,
I am new to HA .I created an endpoint in node-red but cannot access it . I get the following error when I hit the URL:

Cannot GET /hello

Please let me know if I am missing any configs from HA side? Thanks !

If you’re using the Node-RED add-on.

Note : In order to use the http_node you will need to expose Node-RED using a network port in addition to ingress. The HTTP nodes will also be presented under /endpoint/ as shown in the UI. If using the node-red-dashboard module this will also be hosted under this path and will use any credentials set here.

From GitHub - hassio-addons/addon-node-red: Node-RED - Home Assistant Community Add-ons

@mbonani Thanks for the response.I am able to access node red fine on HA . I couldn’t get to an endpoint that I created in a flow in node-red.

A little more information would be helpful.

How did you create the endpoint? What do its properties look like? How are you trying to get to it?

I followed the exact same procedure @ https://cookbook.nodered.org/http/create-an-http-endpoint

When I test the endpoint form a browser , I get this error .

Does /endpoint/hello work?

Ok the above mentioned endpoint worked . But my practical use case is unable to get the endpoint .

I have a flow in node red where I wanted to play a mp3 file from my local server (where home assistant and node red both are running) to a chromecast device . When I deploy this flow in node red and try to get to this endpoint @ 192.168.XX.XX:1880/endpoint/alavp ,I get this error:

The file exists in the /tmp directory and permissions are changed to 777 . Are there any steps where I need to grant acced to node-red user. If so, what would be the user that’s running node red

I don’t think the Node-RED add-on has access to /tmp.

From what I’ve seen, add-ons seem to share specific folders with each other. /share in particular seems to be a common and shared folder among them. I would recommend putting a file you want both to see in there.

That being said, if you already use this file in service calls in HA, why not just make a service call from Node RED? For instance if you already have the ability to cast this music from HA you could just use the same service call from Node RED in the same way.

Thanks for the response. After placing the file in /share , I was able to play the file from browser @ http://192.168.XX.XX:1880/endpoint/alavp. However the cast node is unable to play . Still getting this error

"Not able to load media:Load failed Not able to load the media."

Ok I think I understand what you’re trying to do. I don’t use the cast node at all so I’m not familiar with it but looking at its documentation it seems to want a URL to the a media file rather then the actual file. Are you trying to give it the endpoint /endpoint/alavp as the URL to the media file? If so couple questions:

  • In your Node RED addon configuration, have you specified credentials in http_node? If so the cast node is likely getting a 401 unauthenticated error since that endpoint is protected by authentication
  • Is Node RED accessible from outside your network? It looks like this node is going to pass the url along to google home. I’m not sure google home will accept a LAN URL. If the file is not externally accessible then perhaps google home is the problem here.
  • Are you setting the correct HTTP headers in your response at that endpoint or just returning the media file? This is just a guess but many services expect HTTP headers to tell them what type of response they are getting and how to handle it. I don’t think Node RED can or will do this automatically for you. You may need to do some digging to find out if it is looking for headers and what those are so you can set them.
  • Is google home or this node expecting the entire media file in the payload or is it expecting to be able to buffer/stream it from the URL? It looks like there’s some mention of this in the ‘Advanced’ part in the documentation of this node. You’ll need to make sure you are serving up the file in the way it expects.

Also is all this an exercise just to see if you can do this? Because it seems like it would be so much easier to just put this file in your /config/www folder of home assistant. Then you can access it directly via /local/ without trying to pull it in then serve it up in a Node RED flow.

Or alternatively if you already have the Google integration in HA just use the media_player.play_media service. It’s a lot easier to use from the looks of it.

HI Mike,

Thanks for the response .

Yes I am trying to give the endpoint /endpoint/alavp as the URL to the media file
Yes I have http_node credentials configured
No ,my node red is not accessible externally

Could you pls explain more on the other option that you mentioned for playing using /config/www ?
My end goal is to use this as a continuation for a flow in node red where my Projector starts ,it has to play a custom video file via chromecast . I can have the custom video file on youtube / local . For the local option, I tried creating an endpoint and trying to get it to chromecast but its failing with above mentioned error .

Take a look at the below URL . Search for “Play local files” . I tried to play my local files using the procedure mentioned here but it fails

Thanks!

Gotcha ok so looks like what you’re trying to should work. Except

If you have credentials configured then that means the endpoint /endpoint/alavp requires basic authentication. Since the cast node does not ask you to provide authentication details for the URL you gave it I have to assume that it only allows URLS which do not require authentication. So I think you would need to remove authentication from your node RED config by setting the http_node option as follows:

http_node:
  username: ''
  password: ''

The alternative I was suggesting is that HA comes with a special folder in the config directory that it auto-exposes. Like I said above, any file you put in /config/www can be accessed via <HA Base URL>/local/<file name>. So its effectively a shortcut to the HTTP In node thing, just by putting a file in the www folder gives you a URL directly to that file.

2 Likes

Thank you , Yes , the authentication was the problem,It works when I remove the credentials .

1 Like

Solution

  1. go to your Node-RED within the Home Assistant UI.
  2. Right Click INSIDE Node-RED > Inspect Element
  3. Go up in the tree and search for <iframe title="Node-RED" src="/api/hassio_ingress/sometingsomething/"> </iframe>
  4. Copy what’s written between the double quotes after src=
  5. Add this to the home assistant hostname + port (if not 443 or 80)
    This would be e.g.: http://homeassistant.local:8123/api/hassio_ingress/<some-id>/endpoint/test for the [get] on /test.
    Add a debug and go to that page. This should give you some output