Post commits via webhook inside a topic as reply

AI-generated summary

B-iggy is trying to automate posting a reply inside a Discourse topic via a webhook whenever a commit is pushed on a GitHub repository using Integromat. They have set up the API in Discourse, a webhook in GitHub, and an HTTP POST scenario in Integromat but are missing the final piece to make it work.

Bartv suggests reverse engineering the Discourse API by inspecting the network requests when posting a reply manually. B-iggy follows this advice and discovers that not all fields are mandatory for a reply POST call.

However, B-iggy encounters an issue with bad CSRF, which blake resolves by advising to set the Api-Username and Api-Key in the header and remove the credentials from the body. B-iggy successfully implements this solution and shares the final working setup.

Hey guys,
I searched but couldn’t find the proper direction.

I want to automatically post a reply inside a topic as soon as I pushed a commit on a github repository - automatically via a webhook.

I work with Integromat and already successfully did something similar with topics

I have setup an API in Discourse, a webhook in Github, a HTTP POST scenario in Integromat but I’m missing the final piece to make it work.

My current attempt looks like this which does not work.

I think because Discourse does not know what to do with the POST request.
I mean there is /new-message? and /new-topic? but not /new-reply?

Maybe it’s something trivial, thanks in advance for your help!

You can find out how to construct your request by reverse engineering the Discourse API. Basically you open your network inspector, post a reply to a topic and see what happens under the hood:

Thanks a lot @bartv
Just doing it right now :slight_smile:

Only question would be: are ALL fields mandatory to make a reply POST call? It’s quite a lot and some fields can’t be filled by me dynamically I think or are prone to mistakes!? (the id: for example)

In Zapier for example I made once a successful Topic POST Webhook with only those data fields

I doubt they’re all required. Just try it :slight_smile:

Just as info it is not failing because of the data fields but because of bad csrf.
See here:

@blake Does this mean I need to set the api_username and api_key in the Header?

My current progress which fails:

Yep, you will need to set the Api-Username and Api-Key in the header. Be sure to change the _ to a -. You will also need to remove the credentials from the body.

Awesome, thank you very much @blake!
That was it.

For someone searching for hours via Google and Search as I did, that’s it: