How can we create post/topic in Discourse using API

javascript

(UserXtreamz) #1

Hi,

I need to create discourse topic using API . Anyone please provide the details to create discourse topic using API. Any javascript API available for this? . Using any url is it possible to post the topic to discourse like
discourse.site.com/post?content=“post content”&category=“category name” ?


Post a new Topic with REST - 403 Forbidden
(Gautham N S) #2

Yes it is possible. You can go through the discourse code to find out all the details.
The url for posting is discourse.site.com/posts?title=“Title”&category=“category”&raw=“Your post content here” by using HTTP post request. You have to provide the api key and username along with it.


(UserXtreamz) #3

Hi just tried with the following URL. But i am getting 500 internal error in desktop browser console

http://discourse.site.com/posts?api_key=apikey99bd&api_username=username?title=“test Title”&category=“Uncategorized”&raw=“Your post content here”

Any problem with my URL?


(Gautham N S) #4

What was the error message you obtained when you tried? Did you do a HTTP POST request? Also, it needs to be a JSON request. So try adding .json to the request like this. discourse.site.com/posts.json?title=“Title”&category=“category”&raw=“Your post content here”


(UserXtreamz) #5

Yes, i am using HTTP request i added posts.json. Now its showing the following Error

{“errors”:[“You are not permitted to view the requested resource.”],“error_type”:“invalid_access”}

Do i need to change any settings in discourse? or anything else?


#6

Read api documentation


(UserXtreamz) #7

According to the API Doc i tried with the following URL

http://discourse.site.com/posts.json?api_key=apikey_esdfgbf&api_username=name?title='test Title’&category=‘Uncategorized’&raw=‘Your post content here’

But ia m getting {“errors”:[“You are not permitted to view the requested resource.”],“error_type”:“invalid_access”} in browser. What is the actual issue?


Post a new Topic with REST - 403 Forbidden
#8

For topic test this

http://discourse.example.com/new-topic?title=topic%20title&body=topic%20body&category=category/subcategory

(UserXtreamz) #9

Yes, But its opening the window for creating topic. How can i create new content using HTTP request?

I need to post the content to discourse through this URL .is it possible?


#10

(UserXtreamz) #12

Any API available to create topic like this:


(Aarskin) #13

@User143: see the linked reply here, where I had the same issue. I found removing the quotes from my query string solved my issue.

Not sure if you automatically get notifications on linked replies, so I’m redundantly posting this here.