$ npm i discourse-jsimport Discourse from "discourse-js"; const apiKey = "<api-key-from-discourse>"; const baseUrl = "<your-discourse-url>" || "http://localhost:3000"; const discourse = new Discourse(apiKey, baseUrl); discourse.posts .create({ api_username: "karl", topic_id: 11, // optional (required for creating a new post on a topic.) raw: "Hello World", imageUri: imageUri // optional to create a post/topic with an image. }) .then(res => console.log(res)) .catch(err => console.log(err));Todo
discourse.groups .getMembers({ group_name: "group-name" }) .then(res => console.log(res)) .catch(err => console.log(err));Todo
Todo
discourse.posts .create({ api_username: "karl", topic_id: 11, // optional (required for creating a new post on a topic.) raw: "Hello World", imageUri: imageUri // optional to create a post/topic with an image. }) .then(res => console.log(res)) .catch(err => console.log(err));discourse.posts .like({ id: 72 }) .then(res => console.log(res)) .catch(err => console.log(err));discourse.posts .unlike({ id: 72 }) .then(res => console.log(res)) .catch(err => console.log(err));Note: You can only unlike a post within 5 - 10 minutes after you have liked it. Think of unlike more so like an undo.
See this post here and here for information around the undocumented time limit on unliking a liked post.
discourse.topics .getTopic({ id }) .then(res => console.log(response)} .catch(err => console.log(err))Todo
This is if you are developing the discourse-js API locally on your machine.
# Clone the repo $ git clone git@gitlab.com:theworkshop/discourse-js.git $ cd discourse-js $ pwd|pbcopy # Copies the current working directory /path/to/discourse-js/ # cd into the directory you want to test locally. $ npm install /path/to/discourse-js/Why not just use npm link?:
For speed and productivity. Symlinks do not work with React Native π©π².
- facebook/react-native#637 ππ³
- facebook/metro#1 ππ³
Read more about npm link and why we do this here.
You will also need a Discourse server running. This can be local or running in the cloud.
MIT