> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.itential.com/itential-gateway/4/manage-inventory-via-api/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server. # Manage inventory via API ## Getting started with the API For a complete API reference, use the API Documentation link in the Itential Gateway UI. The interface allows you to browse and interact with the Itential Gateway API. ### Add a device If an existing Ansible Inventory is not already configured, you can add a new device to Gateway using the API. The following is an example `curl` script to add a device. ```bash 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"} ``` ```bash curl -X POST --header 'Authorization: ' --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. ```bash 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"} ``` ```bash curl -X GET --header 'Authorization: ' --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. ```bash 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"} ``` ```bash curl -X POST --header 'Authorization: ' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "hosts": [ "ios01" ] }' 'https://localhost:8083/api/v2.0/roles/itential_get_config/execute' ``` > **Note** > > For Itential Gateway 2022.1, use the following endpoint instead: > > ```bash > curl -X POST --header 'Authorization: ' --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. ```bash 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"} ``` ```bash curl -X POST --header 'Authorization: ' --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' ``` > **Note** > > For Itential Gateway 2022.1, use the following endpoint instead: > > ```bash > curl -X POST --header 'Authorization: ' --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' > ```