B-iggy
(B Iggy)
July 5, 2020, 9:16am
1
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!
bartv
(Bart )
July 5, 2020, 9:37am
2
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:
Discourse is backed by a complete JSON api. Anything you can do on the site you can also do using the JSON api.
Many of the endpoints are properly documented in the discourse_api gem, however some endpoints lack documentation.
To determine how to do something with the JSON API here are some steps you can follow.
Example: recategorize a topic.
Go to a topic and start editing a category:
[image]
Open Chrome dev tools, switch to the Network tab, select XHR filter:
[image]
Perform the op…
1 Like
B-iggy
(B Iggy)
July 5, 2020, 9:42am
3
Thanks a lot @bartv
Just doing it right now
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
bartv
(Bart )
July 5, 2020, 9:44am
4
I doubt they’re all required. Just try it
1 Like
B-iggy
(B Iggy)
July 5, 2020, 10:16am
5
Just as info it is not failing because of the data fields but because of bad csrf.
See here:
API requests with the Content-Type as “application/json” often receive an unhelpful message like “BAD CSRF”, so we should improve the error messaging so that it provides more details as to why they are receiving this error message.
@blake Does this mean I need to set the api_username and api_key in the Header?
My current progress which fails:
3 Likes
blake
(Blake Erickson)
July 6, 2020, 3:47pm
6
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.
2 Likes
B-iggy
(B Iggy)
July 6, 2020, 4:35pm
7
Awesome, thank you very much @blake !
That was it.
For someone searching for hours via Google and Search as I did, that’s it:
2 Likes
system
(system)
Closed
August 5, 2020, 4:35pm
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.