{"id":22489787,"url":"https://github.com/workshoptech/discourse-js","last_synced_at":"2026-03-16T08:03:54.588Z","repository":{"id":47936272,"uuid":"151271172","full_name":"workshoptech/discourse-js","owner":"workshoptech","description":"JavaScript wrapper around the Discourse API","archived":false,"fork":false,"pushed_at":"2023-01-06T09:22:48.000Z","size":1113,"stargazers_count":19,"open_issues_count":11,"forks_count":5,"subscribers_count":2,"default_branch":"development","last_synced_at":"2025-05-07T11:57:01.449Z","etag":null,"topics":["api-wrapper","discourse","javascript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/workshoptech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-02T14:44:45.000Z","updated_at":"2024-06-04T22:15:11.000Z","dependencies_parsed_at":"2023-02-05T19:00:21.280Z","dependency_job_id":null,"html_url":"https://github.com/workshoptech/discourse-js","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workshoptech%2Fdiscourse-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workshoptech%2Fdiscourse-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workshoptech%2Fdiscourse-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workshoptech%2Fdiscourse-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workshoptech","download_url":"https://codeload.github.com/workshoptech/discourse-js/tar.gz/refs/heads/development","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252873986,"owners_count":21817711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","discourse","javascript"],"created_at":"2024-12-06T17:20:43.720Z","updated_at":"2026-03-16T08:03:54.556Z","avatar_url":"https://github.com/workshoptech.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![NPM Version](https://img.shields.io/npm/v/discourse-js.svg?style=flat-square)](https://www.npmjs.com/package/discourse-js)\n\n## Contents\n\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [API](#api)\n  - [Categories](#categories)\n  - [Groups](#groups)\n  - [Messages](#messages)\n  - [Notifications](#notifications)\n  - [Posts](#posts)\n  - [Topics](#topics)\n  - [Users](#users)\n- [Local Development](#local-development)\n- [License](#license)\n\n## Installation\n\n```bash\n$ npm i discourse-js\n```\n\n## Quick Start\n\n```js\nimport Discourse from 'discourse-js';\n\nconst userApiKey = '\u003cuser-api-key-from-discourse\u003e';\nconst apiUsername = '\u003cuser-username-from-discourse\u003e';\nconst baseUrl = '\u003cyour-discourse-url\u003e' || 'http://localhost:3000';\n\nconst discourse = new Discourse();\ndiscourse.config({ userApiKey, apiUsername, baseUrl })\n\ndiscourse.posts\n  .create({\n    topic_id: 11, // optional (required for creating a new post on a topic.)\n    raw: 'Hello World',\n    imageUri: imageUri, // optional to create a post/topic with an image.\n  })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n## API\n\n### Categories\n\n#### Get Category\n\n```js\ndiscourse.categories\n  .getCategory({ cat_id: 'category-id' })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n#### Get Sub-Category\n\n```js\ndiscourse.getSubcategory\n  .getCategory({ cat_id: 'category-id', subcat_id: 'subcategory-id' })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n---\n\n### Groups\n\n#### Get Group Members\n\n```js\ndiscourse.groups\n  .getMembers({ group_name: 'group-name' })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n---\n\n### Messages\n\nTodo\n\n---\n\n### Notifications\n\nTodo\n\n---\n\n### Posts\n\n#### Create a Post\n\n```js\ndiscourse.posts\n  .create({\n    topic_id: 11, // optional (required for creating a new post on a topic.)\n    raw: 'Hello World',\n    imageUri: imageUri, // optional to create a post/topic with an image.\n  })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n#### Like a Post\n\n```js\ndiscourse.posts\n  .like({ id: 72 })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n#### Unlike a Post\n\n```js\ndiscourse.posts\n  .unlike({ id: 72 })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\nNote: You can only `unlike` a post within 5 - 10 minutes after you have `liked` it. Think of `unlike` more so like an _undo_.\n\nSee this post [here](https://meta.discourse.org/t/53722) and [here](https://meta.discourse.org/t/57141) for information around the undocumented time limit on _unliking_ a _liked_ post.\n\n#### Reply to a Post\n\n```js\ndiscourse.posts\n  .reply({\n    topic_id: 72,\n    raw: 'Hello World',\n    reply_to_post_number: 14,\n  })\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n---\n\n### Topics\n\n#### Get a Topic\n\n```js\ndiscourse.topics\n  .getTopic({ id })\n  .then(res =\u003e console.log(res)}\n  .catch(err =\u003e console.log(err))\n```\n\nTopics have a chunk size of 20, which mean you will only get 20 posts back in one get. This can cause weird problems with nested replies and long threads. You can override this by passing `print: true`. Note this sets the chunk size to 1000. See [API: Getting all posts in a topic](https://meta.discourse.org/t/api-getting-all-posts-in-a-topic/41018/10)\n\n```js\ndiscourse.topics\n  .getTopic({\n    id,\n    print: true\n  })\n  .then(res =\u003e console.log(res)}\n  .catch(err =\u003e console.log(err))\n```\n\n#### Delete a Topic\n\n```js\n  discourse.topics\n    .deleteTopic({ id })\n    .then(res =\u003e console.log(res)} // Note: delete returns nothing.\n    .catch(err =\u003e console.log(err))\n```\n\n---\n\n### Users\n\n#### Get a single User\n\n```js\ndiscourse.users\n  .getUser({ username })\n  .then(res =\u003e console.log(res)}\n  .catch(err =\u003e console.log(err))\n```\n\n## Local Development\n\nThis is if you are developing the `discourse-js` API locally on your machine.\n\n```bash\n# Clone the repo\n$ git clone git@gitlab.com:theworkshop/discourse-js.git\n$ cd discourse-js\n$ pwd|pbcopy # Copies the current working directory /path/to/discourse-js/\n# cd into the directory you want to test locally.\n$ npm install /path/to/discourse-js/\n```\n\n_Why not just use `npm link`?_:\n\nFor speed and productivity. Symlinks do not work with React Native 💩📲.\n\n- https://github.com/facebook/react-native/issues/637 🐇🕳\n- https://github.com/facebook/metro/issues/1 🐇🕳\n\n_Read more about npm link and why we do this [here](https://medium.com/@the1mills/how-to-test-your-npm-module-without-publishing-it-every-5-minutes-1c4cb4b369be)_.\n\nYou will also need a Discourse server running. This can be local or running in the cloud.\n\n## Publishing a new Version\nBump the version of the package:\n\n```\nyarn version --patch/--minor/--major\n```\n\nOur preversion, version, and postversion will run, create a new tag in git and push it to our remote repository. The updated package will then be published on npm.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkshoptech%2Fdiscourse-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkshoptech%2Fdiscourse-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkshoptech%2Fdiscourse-js/lists"}