UNPKG

3.81 kBMarkdownView Raw
1# clickup.js
2
3A Node.js wrapper for the [Clickup API](https://clickup.com/api).
4
5[![Downloads](https://img.shields.io/npm/dm/clickup.js.svg?style=for-the-badge)](https://www.npmjs.com/package/clickup.js)
6[![Install size](https://img.shields.io/bundlephobia/min/clickup.js?style=for-the-badge)](https://packagephobia.now.sh/result?p=clickup.js)
7![Package version](https://img.shields.io/github/package-json/v/ComfortablyCoding/clickup.js?style=for-the-badge)
8
9## Install
10
11```sh
12npm install clickup.js
13```
14
15or
16
17```sh
18yarn add clickup.js
19```
20
21## Usage
22
23Before you can use this library you will need to first authenticate with the Clickup API and obtain an `Access Token`. You can read how to do so at the [Clickup API docs](https://clickup.com/api).
24
25In your project, initialize an instance of clickup.js:
26
27```js
28const { Clickup } = require('clickup.js');
29const token = '...'; // API access token
30const clickup = new Clickup(token);
31```
32
33Once you've created an instance, you can use it to access all the features provided by the wrapper, the following example fetches a task by id and displays the response to the console:
34
35```js
36(async () => {
37 try {
38 // get a specific task
39 const { body } = await clickup.tasks.get('9hz');
40 console.log(body);
41 } catch (error) {
42 if (error.response) {
43 // The request was made and the server responded with a status code
44 // that falls out of the range of 2xx
45 console.log(error.response.body);
46 console.log(error.response.statusCode);
47 console.log(error.response.headers);
48 } else if (error.request) {
49 // The request was made but no response was received
50 console.log(error.request);
51 } else {
52 // Something happened in setting up the request that triggered an Error
53 console.log('Error', error.message);
54 }
55 console.log(error.options);
56 }
57})();
58```
59
60**Note:** Due to the HTTP request library being used each error contains an `options` property which are the options Got used to create a request - just to make debugging easier. Additionally, the errors may have `request` and `response` properties depending on which phase of the request failed. Read more about HTTP request library [Got](https://github.com/sindresorhus/got).
61
62## Important Note
63
64The library is structured to match classes with their respective routes, **NOT** how they are sectioned in the Clickup API docs. For example adding a guest to a task is under the `Tasks` class instead of the `Guests` class as its route is via `task` and not `guest`. Due to this a request to add a guest to a task will look like so:
65
66```js
67(async () => {
68 try {
69 // guest data
70 const guestData = {
71 permission_level: 'read',
72 };
73 // add guest to task
74 const { body } = await clickup.tasks.addGuest('c04', 403, guestData);
75 console.log(body);
76 } catch (error) {
77 if (error.response) {
78 // The request was made and the server responded with a status code
79 // that falls out of the range of 2xx
80 console.log(error.response.body);
81 console.log(error.response.statusCode);
82 console.log(error.response.headers);
83 } else if (error.request) {
84 // The request was made but no response was received
85 console.log(error.request);
86 } else {
87 // Something happened in setting up the request that triggered an Error
88 console.log('Error', error.message);
89 }
90 console.log(error.options);
91 }
92})();
93```
94
95## Documentation
96
97You can read the library documentation at the [clickup.js docs](https://clickup-js.netlify.app)
98
99## Features
100
101The available features are:
102
103- `Authorization`
104- `Checklists`
105- `Comments`
106- `Folders`
107- `Goals`
108- `KeyResults`
109- `Lists`
110- `Spaces`
111- `Tasks`
112- `Teams`
113- `Views`
114- `Webhooks`
115
116## Disclaimer
117
118The [clickup.js](https://github.com/ComfortablyCoding/clickup.js) package is **unofficial** and therefor not endorsed or affiliated with ClickUp or it's subsidiaries.