The Flexera One API and Flexera One IT Asset Management API provide a way for scripts and other automation technologies to programmatically access data held in Flexera One.
In this post I give a some quick start examples using shell (bash) and curl commands to illustrate basic use of these APIs.
Before calling any API endpoints, you must generate a long-lived refresh token associated with your user account. This is a once-off operation.
To do this:
See the following page for more details about this process: Generating a Refresh Token.
NOTE 1: Don't forget to save your refresh token securely! Once the token has been generated and displayed, you cannot retrieve it again; you can only generate a new token.
NOTE 2: This quick start post illustrates the use of user authentication for calling API endpoints. Service account authentication can also be used. See the following page for details about this: Authentication.
Example commands in the following sections of this page use a couple of shell variables that contain details about your Flexera One environment. These variables can be initialized as follows:
fOneEndpoint=flexera.com # or flexera.eu or flexera.au
orgId=12345 # Your Flexera One org ID
Some of the examples also use the jq command-line tool to process JSON data returned by APIs. Package repositories for most modern operating systems contain a package to easily install jq.
Once you have a refresh token, it can be used to generate a short-lived access token that can subsequently be used to authenticate when calling API endpoints.
The following commands illustrate how to generate an access token by POSTing to the /oidc/token endpoint:
# Securely prompt for the refresh token
refreshToken=$(read -sp "Refresh token: " && echo $REPLY)
accessToken=`curl -s -X POST https://login.$fOneEndpoint/oidc/token -d "grant_type=refresh_token&refresh_token=$refreshToken" | jq -r .access_token`
NOTE: Access tokens expire after 1 hour. The /oidc/token endpoint can be called again to generate a new access token as needed.
See the following page for more information: Generating an Access Token From Refresh Token.
With an access token in hand, you are now ready to call API endpoints. The following examples illustrate calling some endpoints.
NOTE: The actual API endpoints you can call and the data returned will be governed by what Flexera One products & capabilities are covered by your organization's Flexera One subscription, and what rights are assigned to your Flexera One user account.
Sample JSON output shown below is formatted for readability. The actual output returned when calling API endpoints generally does omits unnecessary whitespace.
The reportsIndex API endpoint can be used to retrieve details about custom reports that have been configured in Flexera One ITAM. This is useful for looking up the numeric ID of a report by name.
For example, to retrieves the ID of a report with the name "Inventory device details":
reportId=$(
curl https://api.$fOneEndpoint/fnms/v1/orgs/$orgId/reports -H "Authorization: Bearer $accessToken" |
jq -r '.[] | select(.title=="Inventory device details") | .id'
)
The retrieved ID of the report can be used with the reportsExecute API endpoint to run the report and return data:
curl https://api.$fOneEndpoint/fnms/v1/orgs/$orgId/reports/$reportId/execute -H "Authorization: Bearer $accessToken"
Sample output:
{
"values": [
{
"ComputerID": 12,
"ComputerName": "vm40949",
"ComputerType": "Virtual Machine",
"OperatingSystem": "HP-UX 11.31",
"SerialNo": "384b572c-4e0a-12de-f5ce-67f6739d6c23"
},
{
"ComputerID": 13,
"ComputerName": "esx9523",
"ComputerType": "VM Host",
"OperatingSystem": null,
"SerialNo": "784b572d-72da-93de-c5fe-89f63b9d6723"
},
[...]
],
"nextPage": "/fnms/v1/orgs/12345/reports/207/execute?skipToken=CAEaBTEwMDAd83JduriRjZjAwZTY0OC00MzJjLTQ1ZjAtOTdmMC0xNWFkM2ZiODFiZjc%3D"
}
Report data is returned in pages. Use the nextPage value in the returned result to retrieve the next page of data.
For further exploration about how to retrieve Flexera One ITAM custom report data, see the following article that provides a sample PowerShell script that uses these API endpoints: The New Generic ITAM REST API for querying any web report is available! A PowerShell example.
Technopedia data can be queried through a GraphQL API.
Here is an example:
echo '
{
"query": "
query softwareProduct($name: [String]) {
SoftwareProduct(name: $name) {
name
id
manufacturer { name }
softwareReleases { id softwareLifecycle { endOfLifeDate } softwareVersion { name } }
}
}
",
"variables": {"name": ["Maximo", "SQL Server"]}
}
' |
tr '\n' ' ' |
curl https://api.$fOneEndpoint/content/v2/orgs/$orgId/graphql -H "Authorization: Bearer $accessToken" --data @-
The sample GraphQL query shown here includes line breaks for ease of reading. The tr command is used to remove these line breaks, as line breaks are not allowed in the query text.
Sample output:
{
"data": {
"SoftwareProduct": [
{
"id": "12e307a6-b43f-4eec-a1df-f6a42134b3c9",
"manufacturer": {
"name": "IBM"
},
"name": "Maximo",
"softwareReleases": [
{
"id": "08bdb8ce-1d80-4c9b-8c2b-488e2637398b",
"softwareLifecycle": {
"endOfLifeDate": "2999-12-31T00:00:00Z"
},
"softwareVersion": {
"name": "SaaS (7.6)"
}
},
{
"id": "4069046f-0f87-4e9c-a533-587dcd0cae00",
"softwareLifecycle": {
"endOfLifeDate": "2022-12-30T00:00:00Z"
},
"softwareVersion": {
"name": "8.0"
}
},
[...]
]
},
[...]
]
}
}
See the following page for details about the various datasets that can be queried from Technopedia: Datasets.
The above examples illustrate basic API usage. Some aspects to consider for more comprehensive usage are:
We would love to hear what you are doing with the Flexera One APIs! Please add comments on this post to share and inspire us.
However if you have a question about this post or using the Flexera One APIs in general, it will be helpful to avoid comment-confusion if you can please create a new thread in the Flexera One forum and refer back to this post rather than adding a comment here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.