# Make an external http request from discourse

**URL:** https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054
**Category:** Development
**Created:** [August 17, 2019, 10:56am UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054 "2019-08-17T10:56:20Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Thecave3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thecave3/32/153330_2.png) [@Thecave3](https://meta.discourse.org/u/Thecave3)
#### Post date: [August 17, 2019, 10:56am UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/1 "2019-08-17T10:56:20Z")

</div>

Hi,  
I’m thinking of replacing an existing website with discourse. The problem is the backend of that site contains a shared logic even for a mobile app and specific actions for the site.  
So, having to keep an active server with that particular logic, I wonder if it is possible to send http requests from discourse to an external server. The ideal would be that at the occurrence of certain discourse events make a http request to my server.

Is this actually possible? If yes there is somewhere a guide?

Also is it possible to create a topic with specific fields and pass them into the http request?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [August 17, 2019, 11:17am UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/2 "2019-08-17T11:17:52Z")

</div>

It’s perfectly possible, [write a plugin](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515).

Here’s [an example of a plugin which makes an external call whilst processing oneboxes](https://meta.discourse.org/t/onebox-assistant-a-plugin-to-help-onebox-do-its-job/107405).

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 17, 2019, 11:23am UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/3 "2019-08-17T11:23:29Z")

</div>

I think what you’re trying to do is closer to the concept of webhooks. You need to write some webhooks which hit the given urls when an event occurs. If thats the case, you can have a look at this.

> [@Add new webhooks and customize webhook payload](https://meta.discourse.org/t/how-to-add-new-webhooks-and-customize-webhook-payload/59609):
>
> Ever wonder how to add new webhook types? Or how to reduce the payload? Here is the tutorial for the plugin authors. It demos how to add the session and user notification event types as well as customization to the payload. You can also check [the plugin on GitHub](https://github.com/fantasticfears/discourse-webhooks-example) while reading. If you’d like to have a new webhook type supported by the team, bring up a feature request instead. Before started, make sure you already understand [webhook guide](https://meta.discourse.org/t/setting-up-webhooks/49045). New webhook event type A new webhook event type is def…

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [August 17, 2019, 11:31am UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/4 "2019-08-17T11:31:10Z")

</div>

Yep, if the communication is one way, @fzngagan’s proposal is better.

If you want to retrieve and process a response in some complex fashion, then a REST call in a plugin might be better.

---

<div class="post-metadata">

### Author: ![Thecave3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thecave3/32/153330_2.png) [@Thecave3](https://meta.discourse.org/u/Thecave3)
#### Post date: [August 17, 2019, 12:32pm UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/5 "2019-08-17T12:32:55Z")

</div>

Thank you everyone for the answer. No, I’m looking for a way to create a full API REST client and not a simple webhook.  
What i am trying to replicate is a sort of marketplace when users can post their objects and then they can accept the various offers from others users. The logic of the marketplace should remain on the server but the front end should be discourse and so it should be updated according to the data on server.

I honestly don’t know what’s better to do for this situation, so i am looking for tips and references!

I also link to you [the site](https://thehub76.herokuapp.com/) (it is in italian) just to let you understand better what i am trying to migrate

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 17, 2019, 12:49pm UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/6 "2019-08-17T12:49:21Z")

</div>

I think some clarification is required in terms of what role Discourse would play here.  
How does your use case relate to discussion/conversation. What would be done on discourse and what would be done on your server.

> [@Thecave3](#):
>
> The logic of the marketplace should remain on the server but the front end should be discourse and so it should be updated according to the data on server.

This is a broad statement. Discourse in itself is a whole system. What data would you show on Discourse which comes from or is synced with your other server.

From the information you’ve shared, it could be done via a plugin for sure. There are integrations for WordPress, GitHub, etc which might be doing a similar thing what you’re trying to do. But that’s me trying to read between the lines.

If you want to understand how to build plugins, here’s a great collection of links by @merefield

> [@How can I make my own Discourse plugins?](https://meta.discourse.org/t/how-can-i-make-my-own-discourse-plugins/90032/2):
>
> I’ve only just started but here’s my ‘starter for 10’ to get you going: Read: [these](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515)[this](https://meta.discourse.org/t/how-to-start-building-stuff-for-discourse-if-youre-newbie-like-myself/45954) Try and read the code on the simplest, [but popular plugins](https://meta.discourse.org/c/plugin/l/top/yearly) and see if you can understand what they are doing (this is not always easy, especially with the complexity of dealing with multiple files and the sometimes brutal functional brevity of javasctipt, but persevere) You need to learn: Lots of Javascript (look no further than @mpj’s [Fun Fun Function excellent & fun (!) videos](https://www.youtube.com/channel/UCO1cgjhGzsSYb1rsB4bFe4Q) (thanks man!)) Lots of …

This is also a good one.  
[https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827/19?u=fzngagan](https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827/19)

---

<div class="post-metadata">

### Author: ![Thecave3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thecave3/32/153330_2.png) [@Thecave3](https://meta.discourse.org/u/Thecave3)
#### Post date: [August 17, 2019, 1:03pm UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/7 "2019-08-17T13:03:05Z")

</div>

Ok, let me explain better from the beginning the idea:

I want to create a marketplace where users can sell or trade their items. Ideally every time a user creates a post he should enter specific fields to describe this object. Other users should have the opportunity to discuss the price of this item and bid through specific buttons and fields (which should be added using discourse).

Starting from this idea there are two ways I could take (if discourse allows it):

1. Every time a discourse interaction is made about such offers I would like my server to update or send the data.

Or, in case the above thing is not possible:

1. I would like to transfer all the logic to discourse using its internal database and I would like to create a service API rest on discourse that allows a mobile application to connect and use the service from mobile phone.

What is the better and fast idea to implement using discourse?

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 17, 2019, 1:24pm UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/8 "2019-08-17T13:24:10Z")

</div>

> [@Thecave3](#):
>
> Every time a discourse interaction is made about such offers I would like my server to update or send the data.

This is a preferable way to go. The reason being, Discourse isn’t a marketplace and it wouldn’t make much sense to tweak it to behave like one.

Also, do you wish to write the code yourself or hire someone to do that?

---

<div class="post-metadata">

### Author: ![Thecave3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thecave3/32/153330_2.png) [@Thecave3](https://meta.discourse.org/u/Thecave3)
#### Post date: [August 17, 2019, 1:30pm UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/9 "2019-08-17T13:30:09Z")

</div>

> [@fzngagan](#):
>
> This is a preferable way to go. The reason being, Discourse isn’t a marketplace and it wouldn’t make much sense to tweak it to behave like one.

Perfect, so if is possible to do that in discourse, what is the best way to do that?

> [@fzngagan](#):
>
> Also, do you wish to write the code yourself or hire someone to do that?

Since this is not meant to have any revenue and since I have experience in coding is my idea to write all by myself.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 17, 2019, 1:32pm UTC](https://meta.discourse.org/t/make-an-external-http-request-from-discourse/126054/10 "2019-08-17T13:32:42Z")

</div>

I think you should read the links shared above. Also, this wordpress plugin does a similar job but for wordpress so you can check that too.

> [@Manage group membership in Discourse with WP Discourse SSO](https://meta.discourse.org/t/managing-discourse-group-membership-with-wp-discourse/74724):
>
> [WP Discourse](https://github.com/discourse/wp-discourse) functions The [WP Discourse](https://github.com/discourse/wp-discourse) plugin has a couple of functions that can be used to associate WordPress users with Discourse groups. These functions are only enabled on sites that are using WordPress as the SSO provider for Discourse. add\_user\_to\_discourse\_group( $user\_id, $group\_names ) [View Code](https://github.com/discourse/wp-discourse/blob/main/lib/utilities.php#L278-L301) remove\_user\_from\_discourse\_group( $user\_id, $group\_names ) [View Code](https://github.com/discourse/wp-discourse/blob/main/lib/utilities.php#L303-L326) Each of these functions take the same two parameters: $user\_id: the WordPress user’s id $group\_names: a comma separat…
