Post API to Zulip server

I have the basics of Node-Red, but I am pretty green on APIs to web services. I have done it once or twice in the past and Node-Red made it so easy, such as the OpenWeatherMap node.

But now I am trying a POST Api to our self-hosted Zulip server. I would like to be able to send messages on Zulip from my Node-Red flow.

Here is the Zulip documentation. I have not figured out how to format this properly in the HTTP Request node. I have it with basic authentication I tried it with my bot ID and password entered in the node, as well as entered in the URL.

As stated, I am a bit unfamiliar to this and maybe there is something important I am missing.

At the moment, it returns an HTML document, which doesn't seem right at all. I have a struggle figuring out where my config is wrong with the info it gives me. So I assume I maybe be missing something entirely.

I would appreciate a little advice!! Thanks for your time

I should clarify that I have 2 HTTP Request nodes in the same flow. After reading in the docs a bit, I realized that can be a cause of trouble. I moved the one to another flow in the same node-red instance but it acts the same.

Does the curl version work ? as per their examples:

curl -X POST https://yourZulipDomain.zulipchat.com/api/v1/messages \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    --data-urlencode type=stream \
    --data-urlencode 'to="Denmark"' \
    --data-urlencode topic=Castle \
    --data-urlencode 'content=I come not, friends, to steal away your hearts.'

If yes, you can convert those --data-urlencode.... things into a payload object and you should be able to perform a POST request, eg.

msg.payload = {type:"stream",to:"Denmark".... }

Thanks @bakman2 for taking time to look at this!

I was attempting to use the curl example, but I was running aground on converting that example to something that performed correctly.

This conversion is where I was struggling.
So should the https://yourZulipDomain.zulipchat.com/api/v1/messages be in the URL and the various parameters inserted via msg.payload?

I expect that I should be using the authentication fields in the node? or should this be included in msg.payload or maybe msg.headers??

I anticipate researching the structure of the POST command, but I haven't had the time yet.

I was attempting to use the curl example, but I was running aground on converting that example to something that performed correctly.

first make this work before jumping in node-red.

1 Like

I just ran the curl command from terminal with my specific information and worked successfully

In node-red, I have this code in a function node just prior to the http request node. It certainly is working better than before. But it must not like my formatting or something.

The type is supposed to be a string.

I got this working at least in part.

I added this to configure the headers.

msg.headers = {
 "content-type" : 'application/x-www-form-urlencoded'
 };

Then it started accepting my inputs.