This library is supported for both npm and bower. For browser-side, we recommend bower. For server-side, we recommend npm.
bower install ordercloud-js-sdk --save npm install ordercloud-js-sdk --save
After you succesfully install the SDK, you will need to include the library in your index.html file. We have created two files, one minified and one standard.
We recommend that you use either gulp or grunt to create a build that puts all of your third-party app dependencies in one location. This will make it much easier to inject each of the bower or npm main scripts into your index.html file.
After you have successfully injected the ordercloud-js-sdk, it will be available in the global namespace of your application
OrderCloud. Ensure that any reference you make to OrderCloud come after your inject the script (from above). An
example will look like this,
Instead of using a callback function as you may have used previously with asynchronous functions, q has a
that you call on the same asynchronous method you wish to handle. Inside of the
.then method, you provide it with two
functions, the first being the function that handles a success, and the second being the function that handles an exception.
Additionally, you can chain the
.then methods together, making it quite easy to handle a flow of function handlers.
This is just a basic introduction to how the q promise library works. If you would like to learn more about how you can use q, head over to the documentation here
Beyond the standard OrderCloud API resources and methods available to you in this SDK, there are also a few configuration settings and helper functions that are meant to help you develop without any need to configure how the SDK is being used yourself. Below is a list of these configurations that you will use time and time again,
Has two methods to handle logging in and logging out.
Method Params Action Get credentials Authenticates user and returns an access-token (and refresh-token if applicable) Delete Removes access-token from cookies
Note that the Get method does not save the access-token for you. You must handle the response appropriately using OrderCloud.Auth.SetToken method (down below)
Provides all necessary methods to work with authentication in OrderCloud (excluding authenticating itself, as shown above using OrderCloud.Credentials)
Utilizes cookies to store tokens in the browser upon user-reentry into the application
Method Params Action GetToken Gets the stored access-token in cookies SetToken token Sets access token, typically used after with OrderCloud.Credentials.Get