|
| 1 | +# clickup.js |
| 2 | + |
| 3 | +A Node.js wrapper for the [Clickup API](https://clickup.com/api). |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```sh |
| 8 | +npm install clickup.js |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Before 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). |
| 14 | + |
| 15 | +In your project, initialize an instance of clickup.js: |
| 16 | + |
| 17 | +```js |
| 18 | +const Clickup = require('clickup.js'); |
| 19 | +const token = '...'; // API access token |
| 20 | +const clickup = new Clickup(token); |
| 21 | +``` |
| 22 | + |
| 23 | +Once 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: |
| 24 | + |
| 25 | +```js |
| 26 | +(async () => { |
| 27 | + try { |
| 28 | + // get a specific task |
| 29 | + const { body } = await clickup.tasks.get('9hz'); |
| 30 | + console.log(body); |
| 31 | + } catch (error) { |
| 32 | + if (error.response) { |
| 33 | + // The request was made and the server responded with a status code |
| 34 | + // that falls out of the range of 2xx |
| 35 | + console.log(error.response.body); |
| 36 | + console.log(error.response.statusCode); |
| 37 | + console.log(error.response.headers); |
| 38 | + } else if (error.request) { |
| 39 | + // The request was made but no response was received |
| 40 | + console.log(error.request); |
| 41 | + } else { |
| 42 | + // Something happened in setting up the request that triggered an Error |
| 43 | + console.log('Error', error.message); |
| 44 | + } |
| 45 | + console.log(error.options); |
| 46 | + } |
| 47 | +})(); |
| 48 | +``` |
| 49 | + |
| 50 | +**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. Additionaly, the errors may have `request` (Got Stream) and `response` (Got Response) properties depending on which phase of the request failed. Read more about HTTP request library Got [here](https://github.com/sindresorhus/got). |
| 51 | + |
| 52 | +## Important Note |
| 53 | + |
| 54 | +The 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: |
| 55 | + |
| 56 | +```js |
| 57 | +(async () => { |
| 58 | + try { |
| 59 | + // guest data |
| 60 | + const guestData = { |
| 61 | + permission_level: 'read', |
| 62 | + }; |
| 63 | + // add guest to task |
| 64 | + const { body } = await clickup.tasks.addGuest('c04', 403, guestData); |
| 65 | + console.log(body); |
| 66 | + } catch (error) { |
| 67 | + if (error.response) { |
| 68 | + // The request was made and the server responded with a status code |
| 69 | + // that falls out of the range of 2xx |
| 70 | + console.log(error.response.body); |
| 71 | + console.log(error.response.statusCode); |
| 72 | + console.log(error.response.headers); |
| 73 | + } else if (error.request) { |
| 74 | + // The request was made but no response was received |
| 75 | + console.log(error.request); |
| 76 | + } else { |
| 77 | + // Something happened in setting up the request that triggered an Error |
| 78 | + console.log('Error', error.message); |
| 79 | + } |
| 80 | + console.log(error.options); |
| 81 | + } |
| 82 | +})(); |
| 83 | +``` |
| 84 | + |
| 85 | +## Documentation |
| 86 | + |
| 87 | +You can read the library documentation at the [clickup.js docs](https://comfortablycoding.github.io/clickup.js) |
| 88 | + |
| 89 | +## Features |
| 90 | + |
| 91 | +The available features are: |
| 92 | + |
| 93 | +- `Authorization` |
| 94 | +- `Checklists` |
| 95 | +- `Comments` |
| 96 | +- `Folders` |
| 97 | +- `Goals` |
| 98 | +- `KeyResults` |
| 99 | +- `Lists` |
| 100 | +- `Spaces` |
| 101 | +- `Tasks` |
| 102 | +- `Teams` |
| 103 | +- `Views` |
| 104 | +- `Webhooks` |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +MIT License |
| 109 | + |
| 110 | +Copyright (c) 2020 jj |
| 111 | + |
| 112 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 113 | +of this software and associated documentation files (the "Software"), to deal |
| 114 | +in the Software without restriction, including without limitation the rights |
| 115 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 116 | +copies of the Software, and to permit persons to whom the Software is |
| 117 | +furnished to do so, subject to the following conditions: |
| 118 | + |
| 119 | +The above copyright notice and this permission notice shall be included in all |
| 120 | +copies or substantial portions of the Software. |
| 121 | + |
| 122 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 123 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 124 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 125 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 126 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 127 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 128 | +SOFTWARE. |
0 commit comments