Highlighted
Micro Focus Expert
Micro Focus Expert
125 views

ALM Octane nodejs API SDK installation example

 

How to install the ALM Octane Nodejs SDK on Linux

I recently tried to setup the nodejs SDK. It makes it rather easy to implement some data exchange with ALM Octane. You can download the SDK from the marketplace:

https://marketplace.microfocus.com/appdelivery/content/nodejs-sdk-for-alm-octane-rest-api

It took me a while to figure out the exact Linux commands. Therefore I would like to share with you my installation protocol. Maybe you find this useful. 


1) Install nodejs

First of all you have to install nodejs, if it is not already installed on your machine. So these are the commands that worked for me: 

sudo yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash -
sudo yum install nodejs

 

2) Install Octane NodesJS REST SDK

Then install the ALM Octane NodeJS API: 

npm i @MicroFocus/hpe-alm-octane-js-rest-s

The API reflects your ALM Octane version. So you always need to do this API update step. 

 

3) Update API

The update API step will generate the node library based on your ALM Octane version. You will have to repeat this step each time you upgrade ALM Octane. 

$ mkdir myscripts
$ cat > octane.json << EOH
{
"config": {
"protocol": "http",
"host": <HOST>,
"port": <PORT>,
"shared_space_id": <SHARED_SPACE_ID>,
"workspace_id": <WORKSPACE_ID>,
"tech_preview_API": <boolean for whether tech preview api should be enabled>
},
"options": {
"username": "<USERNAME>",
"password": "<PASSWORD>"
}
}
EOH

In this file I replaced the host with my ALM Octane hostname such as myhost.mydomain.com, entered my ALM Octane port namber, shared space and workspace ID. For the tech_preview_API I used true. This gives you a preview on the new methods that are about to come.  Here the file with some sample values:  

$ mkdir myscripts
$ cat > octane.json << EOH
{
"config": {
"protocol": "http",
"host": octane.mydomain.com,
"port": 8080,
"shared_space_id": 1001,
"workspace_id": 1002,
"tech_preview_API": true

},
"options": {
"username": "sa@nga",
"password": "secret_password123"
}
}
EOH

Then I used these commands to generate / update the SDK: 

$ cd node_modules/@microfocus/hpe-alm-octane-js-rest-sdk/
$ node scripts/generate_default_routes.js ~/myscripts/octane.json

 

4) Create updated API documentation

You can also generate an updated version of the API documentation based on your currently installed ALM Octane version. These commands worked for me: 


$ cd node_modules/@microfocus/hpe-alm-octane-js-rest-sdk/
$ node scripts/generate_api_annotations.js

$ npm install apidoc
$ node_modules/.bin/apidoc -f doc/apidoc.js -o apidoc/


5) Read the API documentation

Now that the API documentation was created based on your ALM Octane version you can open it on a browser. But which URL to use? This worked for me: 

Open in browser:
file:///home/demo/node_modules/@microfocus/hpe-alm-octane-js-rest-sdk/apidoc/index.html

 

5) Try an example nodeJS SDK script

As a simple first example I am using a nodeJS SDK script that is going to display all your defects in your ALM Octane workspace. I did create a playground workspace for that with a reasonable small amount of defects like 3 or 4 for this. 

This is the sample script. You need to adjust your Octane host, port, shared space ID, workspace ID, client ID and secret.  


GET ALL DEFECTS EXAMPLE

var Octane = require('@microfocus/hpe-alm-octane-js-rest-sdk')

var octane = new Octane({
protocol: "http",
host: "myoctane.mydomain.com",
port: "8080",
shared_space_id: "2001",
workspace_id: "1002",
//routesConfig: <ROUTES_CONFIG_FILE_PATH> | <ROUTES_CONFIG_JSON_OBJECT>
})

octane.authenticate({
client_id: "myoctane_client_id",
client_secret: "1234567890_put_your_secret_here"
}, function (err) {
if (err) {
console.log('Error - %s', err.message)
return
}

// get all defects
octane.defects.getAll({}, function (err, defects) {
if (err) {
console.log('Error - %s', err.message)
return
}

console.log(defects.meta.total_count)
defects.forEach(function (defect) {
console.log(defect)
})
})


6) Run the example:

To run the example simple use: 

node example.js

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.