Discourse API Documentation


(Bernhard Posselt) #180

Another thing: how do I authenticate when doing POST requests? What error codes can be returned for POST or PUT requests?

(Bernhard Posselt) #181

To answer my own questions after reading the source code:

  • subcategories are created by passing another parameter called parent_category_id whose value is the integer id of the preferred category (can be viewed on /categories.json)
  • Authentication for POST requests is done similar to GET requests: by adding it to the URL (wtf)
  • As for error codes: if a POST request tries to create an already existing category, an http 422 is being returned (why no 409?). Did not get further than this

API docs are pretty sparse, this stuff should really be documented better.

(Kane York) #182

You can also add it to the form body.

(Jay Pfaffman) #183

Thanks for your help in improving that!

The thing is that most of the people who are intimately familiar with the API are busy improving it. :slight_smile:

Discourse is pretty fast moving.

(Erlend Sogge Heggen) #184

Agreed! In fact we are actively working on this together with @oblakeerickson. But like @pfaffman pointed out we’re always on the move, so we’re making sure the new API documentation flow can easily keep up with our development pace.

(SMHassanAlavi) #185

I want to find a user’s received likes by api But likes aren’t in user’s details.where should I find it?

(Blake Erickson) #186

You can get the count of likes:

"user_summary": {
  "likes_given": 485,
  "likes_received": 353,
  "posts_read_count": 18938,



(SMHassanAlavi) #187

thank you.Where did you find this?
Is there a complete documention of API?

(Blake Erickson) #188

just use the developer tools in your browser and watch the XHR filter on the network tab.[quote=“Alavi1412, post:187, topic:22706”]
Is there a complete documention of API?

(SMHassanAlavi) #190

Can we change the topic’s owner with API?HOW?

(Blake Erickson) #191

I don’t think this is possible through the PUT topic api calls. You can modify other values like the title and category_id, but not the username.

(Rafael dos Santos Silva) #192
curl 'http://localhost:3000/t/15/change-owner' --data 'post_ids%5B%5D=1074&username=Mobileboy'

(Blake Erickson) #193

ahh awesome, thanks! I didn’t know change-owner existed. As an admin on a topic click the wrench --> select posts --> (select the posts you want to change) --> change ownership --> type in the new username

(SMHassanAlavi) #194

Is there any method to authenticate a username and password with API?

(Lutz Biermann) #195

How can we set the auto-closing time for one specific topic_id with the API?

Lets say the topic_id 60 should auto-close in 48 hours. All other topics in the this Category are on 24h auto-close.

(Lutz Biermann) #196

Second Question: how can we make a specific topic sticky with the API?

(Felix Freiberger) #197

Perform these actions in your browser while the Network tab of the developer tools is open to find out :slight_smile:

(SMHassanAlavi) #198

I want to reply topics with api and change owner of the reply from admin to an email address(Email address may not be in database so the owner will be a stage user).
and if the email address is one of the user’s email address, change the owner from admin to the user.
Is it possible with api?

(Blake Erickson) #199

Changing a post owner is very similar to changing the topic owner:

A better approach might be to assign each user their own api key and they can just post as themselves. Doing everything as an admin is kind of dangerous.

(SMHassanAlavi) #200

How is it possible?
how can we assign each user an api key?