Overview
This example shows you how to implement a REST API endpoint on your Adaptiva server to collect and view client information. You will import the workflow that implements the GET method for the API and then test the ability to retrieve client information via REST invocation.
Requirements
This solution runs on all versions of Adaptiva.
Download Workflow
This solution uses a custom workflow and PowerShell scripts which you will need to download to your server.
The included PowerShell scripts are only needed if you are using a self-signed certificate.
Import Workflow
Follow the instructions in the Import a Workflow article to import the workflow and resolve any issues.
By default, it will import into a folder named: My Rest API Workflows.
Review the workflow
Open the Adaptiva Admin Portal and log in as a Super Admin.
In the left-hand navigation, expand Platform Features and click Workflows > Designer.
In the Workflow Designer navigation tree, click My Rest API Workflows and then in the details pane select GetAdaptivaClientInfo.
The workflow is running a simple query:
select
Device_ID as ClientID,
Device_Name as ClientName,
IP_address as IPAddress,
[Last_Check-in] as LastCheckIn
from a_AdaptivaClientDetails order by Device_NameThere is also an option to specify a specific computer name, which will modify the query to:
from a_AdaptivaClientDetails where Device_Name like '%" + Params.Output + "%' order by Device_ID"
The key to the workflow is the following:
- The results are returned in JSON format and added to the End1.ResultText field
- End1.ResultWholeNumber returns 200
- End1.ResultArrayOfText returns a single-entry array with the value [Content-Type: application/json]
Create a Certificate (PEM format) to be used for accessing the REST API Endpoint
Option 1: Issue a certificate from your CA
If you want to use a CA-based certificate, request a Client Authentication certificate.
The certificate will usually be provided as a .pfx file, which you will need to convert to a .pem file. You can use the directions in the CA Requirements | Adaptiva Docs documentation to use openssl to convert your .pfx file.
Option 2: Use a self-signed certificate in a lab environment
In a lab environment, you can use the provided PowerShell scripts to create a self-signed certificate and JWT authentication token to secure the REST API communication.
- Extract the JWT_TestingScripts.zip file to a working directory.
- Use the following PowerShell script to create a self-signed certificate as well as the needed JWT.
Before running the PowerShell script, ensure you set the execution policy to allow you to run the script.
.\CreateJWTcert_v1.ps1 -Subject "CN=JwtSigningCertScriptTest" -Password "ThisShouldbeAFancyLongPassword" -ExportLocation .\CertFiles -Length 730Navigate to the CertFiles folder in the local directory to find the jwt-public.pem and jwt-signing.pfx files generated.
The certificate will expire in 2 years based on the example. Set a reminder to refresh prior to expiration.
Create the authorization token that will be used with the GET request
- You can generate an authorization token from the .pfx file using the CreateJWTfromCert_v1.ps1 (for PowerShell v5) or CreateJWTfromCert_PSv7_v1.ps1 (for PowerShell v7).
- Run the following command to generate a new authorization token:
.\CreateJWTfromCert_v1.ps1 -PFXLocation $(Resolve-Path .\CertFiles\jwt-signing.pfx) -Pass "ThisShouldbeAFancyLongPassword" -Expire 10- Copy the token to notepad and make sure it is all a single line
- Save the token for use later
This token will expire in 10 days using the example above. Set appropriately.
Configure the Server to support REST API requests
- Log in to the Adaptiva Admin Portal as a Super Admin.
- Click the gear in the top right and click Settings > REST API Endpoints > Configuration.
- Toggle REST Server Enabled ON.
- Check the box for Allow RSA-256.
- Copy the contents of the certificate (jwt-public.pem) to the Certificate box.
- Click Save.
Create the REST API Endpoint
- In the left-hand navigation, click Endpoints under REST API Endpoints.
- Click New.
- Enter the following information:
- Name: Client Info
- Description: REST API endpoint for client information
- REST API Endpoint Path: clientinfo
- Authentication Type: JWT
- Use Global JWT Settings: Toggled ON
- In the HTTP Methods section, next to GET, click Browse.
- In the left-hand navigation, click My Rest API Workflows, select GetAdaptivaClientInfo, click OK.
- Click Save.
Test the request using Postman
- Open Postman on a client machine with network access to the Adaptiva server.
- Create a New Request.
- Select GET and enter the URL: https://<yourAdaptivaServerFQDN:[port]>/restapifoundry/clientinfo
- Click Authorization.
- Select the Auth Type as Bearer Token.
- Copy and paste the token into the field (be sure it is a single line).
- Click Send.
- In the returned Body be sure to change the output type to JSON.
- The information returned will look like:
{
"columnNames": [
"ClientID",
"ClientName",
"IPAddress",
"LastCheckIn"
],
"rows": [
[
44,
"pc1-2",
"172.99.15.11",
1776873608607
],
[
74,
"pc1",
"172.99.14.21",
1776873626480
]
]
}The time returned is in Epoch time (milliseconds). You can convert that in the query if you would prefer.
- You can also supply a parameter to the GET request if you want to return info about a single device or devices that match a name:
clientinfo?client=<devicename>- For example:
https://adaptiva.kaibab.forest.lab:9678/restapifoundry/clientinfo?client=pc1If there are multiple devices that start with pc1, then all will be returned. If the name entered does not match any name in Adaptiva then the following is returned:
{
"columnNames": [
"ClientID",
"ClientName",
"IPAddress",
"LastCheckIn"
],
"rows": [
"pc9",
"No Records Found Matching this Device Name",
0,
null
]
}