@saurabharch/helpcenter-query-client
v0.1.5
Published
Javascript SDK for Rollout HelpCenter query REST APIs
Downloads
147
Maintainers
Readme
Full NodeJS API reference is hosted on Github
Introduction
Follow this guide to use the Rollout Helpcenter JavaScript SDK in your Node.js
application.
Before you can add Rollout Helpcenter npm lib to your Node.js app, you need a Rollout account and a Rollout project. Once you create your project you will have a projectID, a user to play with project APIs. Next you must create your own Helpcenter workspace (in one Rollout project you can create more Workspaces)
Add Helpcenter to your project
Install HelpCenterQuery
library with npm command:
npm install @tiledesk/helpcenter-query-client
Alternatively use package.json to import the library in the "dependencies" property, as in the following example:
{
"name": "Hello Rollout nodeJS",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@tiledesk/helpcenter-query-client": "^0.1.3"
}
}
Then run
npm install
Once installed you can import HelpCenterQuery()
class in your Node.js file using the "require" command:
const { HelpCenterQuery } = require('@saurabharch/helpcenter-query-client');
The HelpCenterQuery class
To interact with Rollout Helpcenter APIs and query your documents you need to create an instance of a HelpCenterQuery() class using his constructor. You MUST supply an APIKEY, an existing Project ID and a valid Workspace ID.
Please refer to the official Rollout Help Center guide to better understand how Help Center works and how to get your Workspace ID.
In the next example we first authenticate using our user credentials, then we create a new RolloutClient instance using a PROJECT_ID
and the token
we got from authentication:
const helpcenter = new HelpCenterQuery({
APIKEY: "__",
projectId: "YOUR_PROJECT_ID",
workspaceId: "YOUR_HELPCENTER_WORKSPACE_ID",
log: false
});
Query your Helpcenter Workspace
Once you created your Helpcenter instance you can query your workspace as in the following example:
const helpcenter = new HelpCenterQuery({
APIKEY: APIKEY,
projectId: PROJECT_ID,
workspaceId: WORKSPACE_ID
});
text_to_search = "military";
maxresults = 3;
helpcenter.search(text_to_search, maxresults, (err, results) => {
console.log("results:", results)
assert(results[0].title)
assert(results[0].score)
assert(results[0].url)
});
Specify the API endpoint in instance methods
If instead you are using instance methods working with an instance of RolloutClient, you must specify the parameter in the constructor config object as config.APIRUL:
const helpcenter = new HelpCenterQuery({
APIKEY: APIKEY,
projectId: PROJECT_ID,
workspaceId: WORKSPACE_ID,
APIURL: API_ENDPOINT,
log: true
});