Clockk SDK for Node.js
Easily build integrations for Clockk
npm install clockk-node --save
var{ Clockk }=require('clockk-node');// Initialize the Clockk object with your OAuth credentialsletclockk=newClockk({// The api_url is an optional parameter for if you have Clockk API development environment (only available to Clockk devs)api_url: process.env.CLOCKK_API,client_id: process.env.CLOCKK_CLIENT_ID,client_secret: process.env.CLOCKK_CLIENT_SECRET,redirect_uri: process.env.CLOCKK_REDIRECT_URI})// In your redirect handler, you will want to exchange a code for a tokenrouter.get('/install/clockk',function(req,res,next){lettoken=awaitclockk.exchangeCodeForToken(req.query.code);// get customer data for authenticated userletcustomer=awaitclockk.getCustomer();
...
// Store this token somewhere for making future requests with this SDK});client_id : Required
client_secret : Required
redirect_uri : Required
token : Optional
required for all functions that attempt to access resources from the API. This is automatically set by exchangeCodeForToken(code)
customer_id : Optional
required for all functions that attempt to access resources from the API.
Note: This is not required for the getCustomer() function, which can be used to get the customer_id for functions which require it.
api_url : Optional
Sets the api url that the SDK will use to communicate with
exchangeCodeForToken(code) initiallizes the token on the clockk object. When you would like to utilize the SDK
with an existing token, you can set that in the constructor, or simply directly update clockk.options.token
// Get the token from whatever persistent storage mechanism you are using.consttoken=getTokenFromStorage();// Initiallize the Clockk object with the tokenletclockk=newClockk({token: token});// Also, you can directly update the clockk token on a Clockk object.clockk.options.token=token;// Now that a token is set on the Clockk object, you can call the refresh fuction.letnewToken=awaitclockk.refreshToken();// And you will probably want to update the persisted token with this new token.