node-calendly-sdk
Version:
A wrapper SDK in nodejs for the calendly API
209 lines (166 loc) • 4.43 kB
Markdown
This library provides a thin wrapper SDK for the calend.ly API. For up-to-date information on the calend.ly API please visit their [developer docs](https://developer.calendly.com/docs)
1. Log into [Calend.ly](https://calendly.com/login)
2. Navigate to the Integrations page
3. Copy your API Key
See [Official Docs](https://developer.calendly.com/docs/getting-your-authentication-token) for more details.
Install package in your node project.
```sh
npm install --save node-calendly-sdk
```
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
// Create a webhook
calendly_client.webhooks.create("https://mycallbackurl.com/handler")
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
/**
{
"id": <hook_id>
}
*/
});
```
Below is a description of the functions available for supported resources in the V1 API along with some basic usage examples.
Create a webhook that will receive notifications from Calendly when events are scheduled or cancelled.
***Parameters:***
- URL: Callback URL for webhook
- events: Array of events
***Usage:***
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
// Create a webhook
calendly_client.webhooks.create("https://mycallbackurl.com/handler")
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
});
```
***Console Output:***
```json
{
"id": <hook_id>
}
```
***Errors:***
If there are errors when submitting a request they will be returned in the JSON, result, you will need to check for and handle these manually.
- Unauthorized
```json
{
"type": "authentication_error",
"message": "Invalid token"
}
```
- Forbidden
```json
{
"type": "authorization_error",
"message": "Your current organization should be on premium tier"
}
```
- Conflict
```json
{
"type": "conflict_error",
"message": "Hook with this url already exists"
}
```
- Unprocessable Entity
```json
{
"type": "validation_error",
"message": "Validation failed",
"errors": {
"url": ["can't be empty"],
"events": ["is not included in the list"],
"base": ["some error"],
<field_name>: <error_messages_array>
}
}
```
Fetches a specific webhook by ID.
***Parameters:***
- id: ID of webhook.
***Usage:***
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
// Get the webhook that has the id of 1234
calendly_client.webhooks.get(1234)
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
});
```
***Console Output:***
```json
{
"data":[
{
"type":"hooks",
"id": 1234,
"attributes":{
"url":"https://mycallbackurl.com/handler",
"created_at":"2016-08-23T19:15:24Z",
"state":"active",
"events":[
"invitee.created",
"invitee.canceled"
]
}
}
]
}
```
List all of the webhooks configured for this account.
***Usage:***
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
// Create a webhook
calendly_client.webhooks.list()
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
```
Remove a webhook so that it is no longer active.
***Parameters:***
- id: ID of your webhook.
***Usage:***
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
// Create a webhook
calendly_client.webhooks.remove("your-webhook-id")
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
```
List all of the configured event types for this account.
***Usage:***
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
calendly_client.events.list()
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
```
List information about this account.
***Usage:***
```javascript
var Calendly = require('node-calendly-sdk')
calendly_client = new Calendly("YOUR-API-TOKEN")
calendly_client.users.about_me()
.then(function(result) {
console.log(JSON.stringify(result, "\t", null))
```