cronofy / cronofy-node

Node wrapper for the Cronofy API
https://docs.cronofy.com/developers
MIT License
49 stars 23 forks source link

A simple wrapper for the Cronofy API.

Basic Usage

The APIs should be one to one with the all of the current methods in Cronofy's documentation. The general pattern is that each method takes an options object and an optional callback. If a callback is not passed in as the second argument the function will act as a promise.

Usage Example

var Cronofy = require('cronofy');

var cronofyClient = new Cronofy({
  client_id: 'armzr1h5NPQST93XTFL9iIULXxfdDlmV',
  client_secret: 'aPPwd-ASDFAsdfasdfasdfsadfasdfASDFSADF_asdfasdfasdf',
  access_token: 'aLUj9bRInSj1n08pHPAo5ru0OOppDaCO',
  refresh_token: '5hdSBZHgjA4xcQAelyAYWDfezZv0-9yP',
  data_center: 'de'
});

var options = {
  code: 'asdkfj213sdf',
  redirect_uri: 'https://www.yoursite.com/calendar_redirect_page'
};

cronofyClient.requestAccessToken(options)
  .then(function(response){
    console.log(response);
  });

// Alternatively as a callback
cronofyClient.requestAccessToken(options, function(err, response){
  if(err) throw err;
  console.log(response);
})

Parameters Note

The cronofy client object can be initialized with client and token details. These details will be automatically added to each call that they are needed for, but these values can be replaced by any specified in the method's options object.

data_center is the two-letter designation for the data center you want to operate against - for example de for Germany, or au for Australia. When omitted, this defaults to the US data center. You can find this value on your app's dashboard under SDK identifier.

Functions available

requestAccessToken(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an object containing an access and refresh token for you to use with future requests.

refreshAccessToken(options, callback)

Takes an optional callback, either returning a promise for, or calling the provided callback with the new refresh and access token information.

Options Object

revokeAuthorization(callback)

Takes an optional callback, either returning a promise for, or calling the provided callback with an empty object in the success case.

elevatedPermissions(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an object containing a permissions URL with a token

Options Object

authorizeWithServiceAccount(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an empty object in the success case.

Options Object

Account functions

accountInformation(callback)

Takes an optional callback, either returning a promise for, or calling the provided callback with an object containing the account information.

Response Example

{
  "account": {
    "account_id": "acc_567236000909002",
    "email": "janed@company.com",
    "name": "Jane Doe",
    "default_tzid": "Europe/London"
  }
}

profileInformation(callback)

Takes an optional callback, either returning a promise for, or calling the provided callback with an array of the user's calendar profiles.

Events functions

createEvent(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an empty object in the success case.

Options Object

readEvents(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an array of the user's events accross all calendars.

Options Object

deleteEvent(options, callback)

Returns an empty string/promise for an empty string on success.

Options Object

bulkDeleteEvents(options, callback)

Returns an empty string/promise for an empty string on success.

Options Object

freeBusy(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with a list of free/busy information across all calendars.

Options Object

updateExternalEvent(options, callback)

Allows the editing of external events on accounts which have granted Extended Permissions

See full details in the Update External Event documentation.

deleteExternalEvent(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an empty object in the success case.

Options Object

Calendar functions

listCalendars(callback)

Takes an optional callback, either returning a promise for, or calling the provided callback with a list of calendars for the user.

Push Notification functions

createNotificationChannel(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an object with the new channel details.

Options Object

deleteNotificationChannel(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an empty object in the success case.

Options Object

listNotificationChannels(callback)

Takes an optional callback, either returning a promise for, or calling the provided callback with a list of notification channels.

Managed Availability functions

listAvailabilityRules(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full response details in the List Availability Rules documentation

upsertAvailabilityRule(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See the full options in the Upsert Availability Rule documentation

Options Object

readAvailabilityRule(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full response details in the List Availability Rules documentation

Options Object

deleteAvailabilityRule(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full details in the Delete Availability Rule documentation

Options Object

upsertAvailablePeriod(options, callback)

Creates or updates an Available Period for the authenticated account. Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full details in the Create or Update Available Periods documentation

listAvailablePeriods(options, callback)

Lists Available Periods for the authenticated account. Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full details in the Read Available Periods documentation

deleteAvailablePeriods(options, callback)

Deletes a single Available Period for the authenticated account, or deletes all Available Periods for the authenticated account.

Options Object

Provide either:

, or:

Real-Time Scheduling functions

realTimeScheduling(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full details in the Real-Time Scheduling documentation

Options Object

addToCalendar(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with a URL to redirect the user towards

Options Object

Batch Request functions

batch(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

See full details in the Batch documentation.

Options Object

Bookable Event functions

createBookableEvent(options, callback)

Takes options object and an optional callback, either returning a promise or calling the provided callback with the body of the response (or error, if applicable).

Options Object

See full details in the Create Bookable Event documentation.

readBookableEvent(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an object representing the bookable event.

Options Object

See full details in the Read Bookable Event documentation.

upsertRegistrationBookableEvent(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an object representing the bookable event.

Options Object

See full details in the Create or Update Registration documentation.

deleteRegistrationBookableEvent(options, callback)

Takes options object and an optional callback, either returning a promise for, or calling the provided callback with an object representing the bookable event.

Options Object

See full details in the Delete Registration documentation.

A feature I want is not in the SDK, how do I get it?

We add features to this SDK as they are requested, to focus on developing the Cronofy API.

If you're comfortable contributing support for an endpoint or attribute, then we love to receive pull requests! Please create a PR mentioning the feature/API endpoint you’ve added and we’ll review it as soon as we can.

If you would like to request a feature is added by our team then please let us know by getting in touch via support@cronofy.com.