# Post API to Zulip server

**URL:** <https://discourse.nodered.org/t/post-api-to-zulip-server/71831>\
**Category:** General\
**Created:** [7 December 2022 19:00 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831 "2022-12-07T19:00:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lesmar96](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lesmar96](https://discourse.nodered.org/u/lesmar96)\
**Post date:** [7 December 2022 19:00 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/1 "2022-12-07T19:00:55Z")

</div>

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.](https://zulip.com/api/send-message) 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

 ![677B97F9-0D73-4CB7-BCA0-C3C29B8DA7D6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76f81f4d346e59afa5c150805bb49d43ab4c7980.jpeg)

---

<div class="post-metadata">

**Author:** ![lesmar96](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lesmar96](https://discourse.nodered.org/u/lesmar96)\
**Post date:** [8 December 2022 10:46 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/2 "2022-12-08T10:46:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 December 2022 17:27 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/3 "2022-12-08T17:27:56Z")

</div>

Does the curl version work ? as per their examples:

```auto
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.

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

```

---

<div class="post-metadata">

**Author:** ![lesmar96](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lesmar96](https://discourse.nodered.org/u/lesmar96)\
**Post date:** [8 December 2022 17:52 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/4 "2022-12-08T17:52:27Z")

</div>

Thanks @bakman2 for taking time to look at this!

> [@bakman2](#):
>
> Does the curl version work ?

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

> [@bakman2](#):
>
> If yes, you can convert those `--data-urlencode....` things into a payload object and you should be able to perform a POST request, eg.

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 December 2022 18:38 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/5 "2022-12-08T18:38:29Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![lesmar96](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lesmar96](https://discourse.nodered.org/u/lesmar96)\
**Post date:** [8 December 2022 23:26 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/6 "2022-12-08T23:26:43Z")

</div>

> [@bakman2](#):
>
> first make this work before jumping in node-red.

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.

 ![18A22C16-BB7A-4089-AF87-44321FED6832](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/edf03238153f3e10d7ddc773b4d5f5c982cd706f.jpeg)

---

<div class="post-metadata">

**Author:** ![lesmar96](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lesmar96](https://discourse.nodered.org/u/lesmar96)\
**Post date:** [9 December 2022 18:16 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/7 "2022-12-09T18:16:01Z")

</div>

I got this working at least in part.

I added this to configure the headers.

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

```

Then it started accepting my inputs.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 February 2023 18:16 UTC](https://discourse.nodered.org/t/post-api-to-zulip-server/71831/8 "2023-02-07T18:16:21Z")

</div>

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