npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

purecloud_api_sdk_javascript

v0.88.8

Published

--- title: Javascript SDK --- Javascript wrapper around the PureCloud Platform API

Downloads

120

Readme


title: Javascript SDK

Javascript wrapper around the PureCloud Platform API

GitHub release Bower version npm

Platform API Javascript Client

Install with Bower:

bower install purecloud-api

Install with NPM:

npm install purecloud_api_sdk_javascript

Reference from the CDN:

<!-- Replace `0.51.1` with the version you want to use. -->
<script src="https://sdk-cdn.mypurecloud.com/javascript/0.51.1/purecloud-api.min.js"></script>

View the documentation on the PureCloud Developer Center. View the source code on Github.

Usage

Client-side usage

For convenience, all modules are bundled together.

<!-- Include the full library -->
<script type="text/javascript" src="purecloud-api.js"></script>

NodeJS usage

Start by requireing the purecloud package

var purecloud = require('purecloud_api_sdk_javascript');

When using the sdk in the browser, the classes are all in the purecloud.platform namespace, but when using in Node, everything is just on that new purecloud object that was created from the require. Subsequent calls would look similar to this usage.

let session = purecloud.PureCloudSession({...});
let authApi = purecloud.AuthorizationApi(session);

session.login().then(function(){
    authApi.getRoles()
      .then((roles) => {
        ...
      });
});

Authentication

Every module uses a ~PureCloudSession~ to make authenticated requests to the PureCloud API.

Auth Type Restrictions!

The client-credentials strategy only works when used in node.js. This is restricted intentionally because it is impossible for client credentials to be handled securely in a browser application.

The implicit strategy only works when used in a browser. This is because a node.js application does not have a browser interface to display the PureCloud login window.

// Node.js - Client credentials strategy
var purecloud = require('purecloud_api_sdk_javascript');
var pureCloudSession = purecloud.PureCloudSession({
  strategy: 'client-credentials',
  clientId: yourPurecloudClientId,
  clientSecret: yourPurecloudSecretKey
});

// Browser - Implicit strategy
var pureCloudSession = purecloud.platform.PureCloudSession({
  strategy: 'implicit',
  clientId: yourClientId,
  redirectUrl: yourCallbackUrl
});

// Browser - Token strategy
var pureCloudSession = purecloud.platform.PureCloudSession({
  strategy: 'token',
  token: yourToken
});

After creating the session object, invoke the login method to authenticate with PureCloud.

pureCloudSession.login()
  .then(function() {
    // Do authenticated things
  });

Environments

If connecting to a PureCloud environment other than mypurecloud.com (e.g. mypurecloud.ie), set the ~environment~ in ~PureCloudSession~.

var session = purecloud.platform.PureCloudSession({
  // ... your other settings
  environment: 'mypurecloud.ie'
});

Local Storage

To persist a token across web pages when navigating between them, set the ~storageKey~ in ~PureCloudSession~. ~storageKey~ will be used to store the token in LocalStorage if supported so make it unique if multiple sessions may exist in the same page.

var session = purecloud.platform.PureCloudSession({
  // ... your other settings
  storageKey: 'myAuthToken'
});

Making Requests

All API requests return a Promise which resolves to the response body, otherwise it rejects with an error.

var session = purecloud.platform.PureCloudSession({ /* your settings */ });
pureCloudSession.login()
  .then(function(){
    var users = new purecloud.platform.UsersApi(session);
    users.getMe()
      .then(function(user) {
        // successfully got the user object, do something with it here
      })
      .catch(function(error) {
        // an error occurred getting the user object
      })
      .finally(function() {
        // this will be called for successes and failures
      });
});

Error Responses

Error responses will contain an object with the HTTP status code, response headers, and the body of the error response. e.g.

{
  "statusCode": 400,
  "headers": {
    "date": "Fri, 24 Feb 2017 16:36:21 GMT",
    "content-type": "application/json",
    "content-length": "135",
    "connection": "close",
    "inin-correlation-id": "391a2855-53ae-4f2b-bc9d-728ef989fd08",
    "inin-ratelimit-count": "1",
    "inin-ratelimit-allowed": "300",
    "inin-ratelimit-reset": "60",
    "cache-control": "no-cache, no-store, must-revalidate",
    "pragma": "no-cache",
    "expires": "0"
  },
  "body": {
    "status": 400,
    "code": "invalid.value",
    "message": "Value [] is not valid for field type [QueryFilterType]. Allowable values are: and, or"
  }
}

Debug Logging

There are hooks to trace requests and responses. To enable tracing, override the .debugLog method on the session object.

pureCloudSession.debugLog = console.log;

Proxy Support

If behind a corporate proxy, provide an options.proxy property when creating a session:

var session = purecloud.PureCloudSession({proxy: 'http://my-corporate-proxy:1080'})