Manage inventory via API

Getting started with the API

For a complete API reference, use the API Documentation link in the Itential Automation Gateway UI. The interface allows you to browse and interact with the Itential Automation Gateway API.

Add a device

If an existing Ansible Inventory is not already configured, you can add a new device to IAG using the API. The following is an example curl script to add a device.

$curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "password": "admin", "username": "admin@itential" }' 'http://localhost:8083/api/v2.0/login'
${"token": "NTAuMjczOTA4MTYwNDM5OTY2"}
$curl -X POST --header 'Authorization: <COPY TOKEN VALUE FROM PREVIOUS CMD HERE>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
> "name": "ios02",
> "variables": {
> "ansible_host": "192.168.32.79",
> "ansible_port": 22,
> "ansible_user": "ios-user",
> "ansible_ssh_private_key_file": "/path/to/key",
> "ansible_network_os": "ios",
> "ansible_connection": "network_cli"
> }
> }' 'https://localhost:8083/api/v2.0/devices'

Get a device list

Use the following command to get a list of managed devices.

$curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "password": "admin", "username": "admin@itential" }' 'http://localhost:8083/api/v2.0/login'
${"token": "NTAuMjczOTA4MTYwNDM5OTY2"}
$curl -X GET --header 'Authorization: <COPY TOKEN VALUE FROM PREVIOUS CMD HERE>' --header 'Accept: application/json' 'http://localhost:8083/api/v2.0/devices'

Get configuration for a device

Use the following command to retrieve the configuration for a managed device.

$curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "password": "admin", "username": "admin@itential" }' 'http://localhost:8083/api/v2.0/login'
${"token": "NTAuMjczOTA4MTYwNDM5OTY2"}
$curl -X POST --header 'Authorization: <COPY TOKEN VALUE FROM PREVIOUS CMD HERE>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
> "hosts": [ "ios01" ]
> }' 'https://localhost:8083/api/v2.0/roles/itential_get_config/execute'

For Itential Automation Gateway 2022.1, use the following endpoint instead:

$curl -X POST --header 'Authorization: <COPY TOKEN VALUE FROM PREVIOUS CMD HERE>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
> "hosts": [ "ios01" ],
> "template": "ios_config"
> }' 'https://localhost:8083/api/v2.0/getConfig'

Run a command on a device

Use the following to run a command on a managed device.

$curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "password": "admin", "username": "admin@itential" }' 'http://localhost:8083/api/v2.0/login'
${"token": "NTAuMjczOTA4MTYwNDM5OTY2"}
$curl -X POST --header 'Authorization: <COPY TOKEN VALUE FROM PREVIOUS CMD HERE>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
> "command": [ "show version" ],
> "hosts": [ "ios01" ]
> }' 'https://localhost:8083/api/v2.0/roles/itential_cli/execute'

For Itential Automation Gateway 2022.1, use the following endpoint instead:

$curl -X POST --header 'Authorization: <COPY TOKEN VALUE FROM PREVIOUS CMD HERE>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
> "command": [ "show version" ],
> "hosts": [ "ios01" ],
> "template": "ios_command"
> }' 'https://localhost:8083/api/v2.0/runCommand'