Client SDK
Get Started
AirOps provides an easy and secure way to bring your AirOps Apps to end user experiences. To facilitate secure access to our Apps directly from client-side code, we have implemented a Client SDK with an authorization mechanism.
This document will guide you through the process of installing and integrating our Client SDK with your server-side code, enabling your end-users to securely access App endpoints.
Checkout our playground with code examples.
Authorization
To authenticate with our API using the SDK, you'll need three pieces of information: your workspace id, user id (any unique identifier will work), and API key. First, use the API key to hash your user id on your back-end server. This will result in a hashed user id that is unique to your API key and user id combination. Workspace id and API Key can be found in your workspace settings.
Here's a sample implementation of the identity verification process for your server:
require "openssl"
def user_id_hash
api_key = "YOUR_API_KEY" # your workspace token (keep safe!)
user_id = "YOUR_USER_ID"
# Convert your api key to bytes
key = api_key.encode("utf-8")
# Hash the message using HMAC-SHA256 and the key
hash = OpenSSL::HMAC.hexdigest('sha256', key, user_id)
end
import hashlib
def user_id_hash():
api_key = "YOUR_API_KEY" # your workspace token (keep safe!)
user_id = "YOUR_USER_ID"
# Convert your api key to bytes
key = bytes(api_key, 'utf-8')
# Hash the message using HMAC-SHA256 and the key
hash = hashlib.sha256(key + bytes(user_id, 'utf-8')).hexdigest()
return hash
const crypto = require('crypto');
const userIdHash = () => {
const apiKey = "YOUR_API_KEY"; // your workspace token (keep safe!)
const userId = "YOUR_USER_ID";
// Convert your api key to a buffer
const key = Buffer.from(apiKey, 'utf-8');
// Hash the message using HMAC-SHA256 and the key
const hash = crypto.createHmac('sha256', key)
.update(userId)
.digest('hex');
return hash;
}
Running Apps via Client SDK
Install NPM package
npm i @airops/js_sdk
Or use the CDN
<script src=“https://cdn.jsdelivr.net/npm/@airops/js_sdk/dist/index.umd.min.js”></script>
Identify the user
import AirOps from '@airops/js_sdk';
const airops = AirOps.identify({
userId: 'YOUR_USER_ID',
workspaceId: 'YOUR_WORKSPACE_ID',
hashedUserId: 'YOUR_USER_ID_HASH'
})
Use it to execute an app
Once you have successfully initialized the SDK, you can begin using the methods available to interact with our API. Note that the methods will return promises.
await airops.execute({
appId: 4,
payload: {
input: {
name: "XXXXYYYYZZZZ"
},
}
});
Execute an app with streaming
In order to stream the app results you will need to enable stream and pass a callback function to the execute method. Optionally you can pass an extra callback function to get a notification when the app is finished.
airops.apps.execute({
appId: 3,
payload: {
input: {
name: "XXXXYYYYZZZZ",
},
},
stream: true,
streamCallback: (data) => {
// Do something with the data
},
streamCompletedCallback: (data) => {
// Do something with the data
},
});
Execute an app async
// Execute an app async
const jobId = await airops.apps.asyncExecute({
appId: 3,
payload: {
input: {
name: "XXXXYYYYZZZZ"
}
}
});
// Pool results
await airops.apps.getResults({ jobId });
Updated 14 days ago