SDK for Interacting with the Knowledge Anywhere LMS API.
contact support@knowledgeanywhere.com if you would like more information.
npm i knowledgeanywhere --save
to get the package.LMS_AUDIENCE
, LMS_SECRET
to be present as process variables. The easiest way to accomplish this is to use an .env file that is loaded via Foreman or dotenv. If you are directed to use a different API url, use the LMS_API_URL
environment variable.LMS_AUDIENCE
, LMS_SECRET
keys. Fill in LMS_AUDIENCE
and LMS_SECRET
from the values that are attained in the admin section of your LMS under the Site Menu. Set environment to stage
.npm install
npm tests
To update documentation, run npm run-script generate-docs
The recommended editor for working on the SDK is Visual Studio code, which is has a debug configuration already setup.
In the specs folder, modify the file manual-tests.js
to run through the code you desire to debug. When you're ready, select the "debug" icon in the pane and click "launch program" and it will hit any breakpoints you set.
See also: Visual Studio Code - Debugger Documentation
Most fields are optional. Only required fields are externalId, email, lastName, FirstName.
Type: User
(string)
: The unique identifier from the system calling the API for this user
(string)
: The email for the user.
(string)
: The last name for the user
(string)
: The first name for the user
(string)
: Plain text password (optional). There is a minimum length requirement of 6 characters.
(string)
: Unique identifier utilized by the Single Sign-on system integrated with the LMS used to uniquely identify this user for sign-on. If Provisioning and SSO are handled by the same system this could be the same data passed for externalId.
(boolean)
: Make user active/inactive in the LMS
(string)
: The name of the microsite.
(boolean)
: Send the user an email with a link to the LMS. Defaults to false
(boolean)
: Make the user change thier passowrd on next login. Defaults to false
(string)
: The 4 letter language code. If the code is not active in the LMS the user will be defaulted to the default LMS value. In most cases this is EN-US. Defaults to EN-US. If a invalid locale is passed in, the operation will continue, but will return a warning.
(string)
: If your LMS uses registration codes for users to self register use this field to assign that code to the user. The value passed in must match a value in the LMS, if no match is found the request will result in a 400 bad request.
(string)
: The phone number for this user
(string)
: The company name for this user
(string)
: The street address, P.O. Box for this user
(string)
: The apartment, suite, unit building, floor, etc for this user
(string)
: The city for the user
(string)
: The 2 or 3 letter state/province abbrevation for the user.
(string)
: The zip or postal code for the user
(string)
: The 2 or 3 letter ISO country code country for the user. See
https://www.iso.org/iso-3166-country-codes.html
for the list of valid country codes. Defaults to the country specified in your LMS configuration. If a invalid country is specified, the operation will continue, but a warning will be thrown.
(Array<CustomField>)
Model representing a Token
Type: Token
(object)
Response from auth server to serialize into a Token.
(string)
: Access Token, used to make requests.
(date)
: Issue date
(date)
: Expiry date
(number)
: Seconds till expiration. Epcoch Unix Timestamp
(string)
: Type of token. (Bearer)
(boolean)
: Checks to see if the token is "fresh" or expired
Model representing a Custom Field
Type: CustomField
(any)
(object)
Object containing the Custom Field Definition
(string)
: String containing the name of the custom field. If the property is not matched to an existing value in the system, it will be created.
(string)
: String containing the value of the custom field. The value can be a single value or a comma seperated string. If the property is not matched to an existing value, it will be created.
This module is available for use and is used by all other modules to call the API in a consistent way and handles authentication. Use the methods to manually make a request to the API using an endpoint.
`lms.api.post('v1/users', data)`
The ping module is a utility class used to determine service availability. WARNING: This module may be deprecated or subject to change. It's primary usage at this stage is for testing. Documentation will most certainly be dropped beyond the initial full release.
Extends LMSAPI
Methods for handling authentication. Usage of this module may not be needed. When making calls to the API using other modules in this sdk, authorization is handeled for you. This module is available if you would like to use it to make standard restful calls to the API outside of the SDK.
Creates a new token from the LMS API Authorization server and stores it on disk. Calling the method will return a promise containing the token. Subsequent calls will check the freshness of the token and create a new one if needed.
Promise<Token>
:
Promise resolves to a
Token
lms.auth.token()
.then((token) => {
//use token.authorization in a a Authorization header when making a restful API call.
})
.catch((ex) => console.log(ex));
The users module contains functions related to creating, reading, updating and deactivating users.
Extends LMSAPI
Search for users. If you only want to return 1000 users at a time, use the offset parameter. Otherwise all users will returned.
(Object
= {}
)
Object containing search parameters. See properties.
(string)
: Filter users by the date they were created. Should be a unix timestamp (ms) . Optional. Defaults to 0 (midnight 1970, UTC)
(string)
: Filter users by the date they were created. Should be a unix timestamp (ms) . Optional. Defaults to the current UTC time. (same as calling
new Date().getTime()
)
(Array<string>)
: Comma separated list of emails to return. Commas must be escaped for HTML. Each item will be executed as a fuzzy search, not an exact match. This means searching for
@knowledgeanywhere.com
will return any users with
@knowledgeanywhere.com
in their email.
(boolean)
: When true, inactive users will be included in the results set.
(int)
: num of records to offset. Returns the first 1000 records of the collection by default (
offset: 0
). A offset of 1000 (
offset: 1000
) will return the next 1000 records.
Promise<Array<User>>
:
Resolves to a promise containing an array of users.
Finds a single user by externalId. Resolves to a promise containing the user. If a user is not found with the specified externalId a 404 will be returned in the catch block.
(string)
externalId of the user to be looked up.
Promise<User>
:
Promise resolves to a object containing the user.
fortuna.user.findById()
.then((res) => console.log(user))
.catch((ex) => console.log(ex));
Creates a new user.
Promise<Object>
:
Promise resolves to a object. The warnings array will contain additional info about invalid data.
fortuna.user.create(user)
.then(res => {
// {
// message: "USER_PROVISION_SUCCESS",
// hasWarnings: false,
// warnings: []
// }
})
.catch((ex) => console.log(ex));
Update a user. Partial updates are allowed and only the fields passed in will be updated. Note, updating email
and externalId
is not supported at this time. @see User
Promise<Object>
:
Promise resolves to a object. The warnings array will contain additional info about invalid data.