0.0.7 • Published 5 years ago

wcp-node v0.0.7

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

wcp-node

Promise based Workday Cloud Platform helper library for Node.js

Features

  • Makes http requests to Workday Cloud Platform from Node.js
  • Supports the Promise API
  • Automatically retrieves the access token for the first request or if the bearer token is expired
  • Currently supports authentication using the client credentials grant type (integration system users)
  • Uses axios http client
  • Supports Implicit Grant Type (the caller is responsible for handling and refreshing the access token)

Supported versions

This library works with Node.js versions 8 and above or support with async/await

Installing

Using npm:

$ npm install wcp-node

End User Docs

For detailed information about Workday Cloud Platform, head out here:

https://cloud.workday.com/documentation/index.html

Prerequisite

  • Complete the Manage Workday Cloud Platform+TG task
  • Register a Developer Tenant
  • Create an API Client
  • Complete the Create Client Credentials Mapping+TG task

Please refer to the Workday Cloud Platform documentation for more details.

Methods

.get(url, axios_options)
.put(url, data, axios_options)
.post(url, data, axios_options)
.patch(url, data, axios_options)

You may modify how the http request is constructed by passing in additional settings in axios_options.

Example

Acquire and setup the wcp object

const Wcp = require('@workdaylabs/wcp-node');

const tenantAlias = '{tenantAlias}';
const clientId = '{clientId}';
const clientSecret = '{clientSecret}';
const wcp = new Wcp(tenantAlias, clientId, clientSecret);

(For Workday internal development only) If you are using a WCP server other than cloud.workday.com, use the following to create wcp instance instead

const wcpServer = 'workday';
const wcp = new Wcp(tenantAlias, clientId, clientSecret, wcpServer);

Performing a GET request

const getWorkers = async () => {
	const url = '/performanceManagement/v1/workers';
	const result = await wcp.get(url);
	console.log('result', result);
}

getWorkers();

Performing a POST request

const postFeedback = async () => {
  const data = {
    displayFeedbackGiverName: true,
    workerManagerAndMe: false,
    workerAndMe: false,
    comment: 'Great job!',
  };
  const workerId = '0e44c92412d34b01ace61e80a47aaf6d';
  const url = `/performanceManagement/v1/workers/${workerId}/anytimeFeedbackEntries?view=giveFeedbackDetail`;
  try {
    console.log('result', await wcp.post(url, data));
  } catch (e) {
    if (e.response && e.response.data && e.response.data.error) {
      console.log(e.response.data.error);
      console.log(e.response.data.errors);
    } else {
      console.log(e.toString());
    }
  }
}

postFeedback();

PUT and PATCH requests are similar to POST

Implicit Grant Type

You may use this library for implicit grant type as well. In this case, however, the library is not responsible to renew the access token. You may check against the access token timestamp for validity. The access token needs to be renewed and set again if expired (by setting wcp.token).

const Wcp = require('wcp-node');

const wcp = new Wcp();

const authCode = 'eyJraWQiOiIyMDE5LTA2LTI1IiwiYWxnIjoiUlM1MTIifQ.eyJpc3MiOiJDXHUwMDNkVVMsU1RcdTAwM2RDQSxMXHUwMDNkUGxlYXNhbnRvbixPVVx1MDAzZERldmVsb3BtZW50LE9cdTAwM2RXb3JrZGF5LENOXHUwMDNkT0NUT1BBQVMiLCJhdXRoX3RpbWUiOjE1NjE1MDM0OTYsImF1dGhfdHlwZSI6IlBhYVMiLCJzeXNfYWNjdF90eXAiOiJFUyIsInNjb3BlIjp7ImNsaWVudF9pZCI6Ik1ETm1OamhoTURjdFpUZ3lZaTAwWldRekxXSmlNVEl0TVRWaU5HVTBPVGt5TXpobCJ9LCJ0b2tlblR5cGUiOiJJZGVudGl0eSIsInN1YiI6InRvcmNpdW9saSIsImF1ZCI6IndkIiwiZXhwIjoxNTYxNTA3MDk2LCJpYXQiOjE1NjE1MDM0OTYsImp0aSI6IjZkaWsyOGRqMzU0eDFvZW9ocXhpc3Y0N29ldzFkaGp4YjNvZXFuZXU5enZ2d2dwMnhlIiwidGVuYW50IjoibGFiczlfaW50ZXJuYWwxIn0.LSN1C9bzUG9yzg7S8_wOOfYu2T8JdTQHBxkOpGGFTjNvmV7BuTNyCFnqYdKtyTi3sPzvsdvRPdg5axSwPyi81XTbFVCuI6hTmiXDVjTlhU6tEtuTdqmtUUq5OUc6_PYhIfAJuBpHQB-ubeJq8apV-Q16FwPeyX6xATEpJCKm8FeLITJk3mLfH7a7JWYbKRCzgs5-04yy6V0WWISOZDBs1seK70aCx2DQaGTnHPKr6Axa7pKAyZu3htuGbl4yhCK_ptMsCJYpfgNHuEq5JVX3ZzuwuD2SzxtfvSZ1T2-ZEEUXQ4e_oh3KCWN_BROWXk3HxC_9HpgbXMOK_Pd4GuZODQ';
wcp.token = { access_token: authCode };
const getWorkers = async () => {
  const url = '/performanceManagement/v1/workers';
  const result = await wcp.get(url);
  console.log('result', result);
};

getWorkers();

Problems?

Please log issues in the github repository

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago