Skip to content

Use cURL for API requests

API calls to Zenoss Resource Manager and Zenoss Cloud Collection Zones can be made using the Linux curl command.

Authentication

For Resource Manager, specify the username and password in quotes with a colon between them using the -u switch

-u "api-username:api-password"

For Collection Zones, specify your API key in the headers of the request

-H "z-api-key: <your_api_key>"

Request type and other headers

Set the request method to POST with -X.

-X POST

Set content-type to application/json in the headers.

-H "Content-Type: application/json"

JSON body

Send your JSON data with -d.

  • The entire JSON body must be quoted when invoking curl from the shell.
  • JSON syntax requires that all strings are in double quote characters (").
  • The easiest way to meet both requirements is to surround the JSON data in single quote characters as shown in the following example.

    -d '{
      "action": "DeviceRouter",
      "method": "addDevice",
      "data": [
        {
          "deviceName": "device.example.com",
          "deviceClass": "/Server/Linux"
        }
      ],
      "tid": 1
    }'
    

URL endpoint

Specify the URL of the router.

https://example.zenoss.io/cz0/zport/dmd/device_router
https://zenapi.zenoss.example.com/zport/dmd/device_router

Example requests

curl https://example.zenoss.io/cz0/zport/dmd/device_router \
  -H "content-type: application/json" \
  -H "z-api-key: YOUR-API-KEY" \
  -X POST -s -S -d \
  '{
    "action": "DeviceRouter",
    "method": "addDevice",
    "data": [
      {
        "deviceName": "device.example.com",
        "deviceClass": "/Server/Linux"
      }
    ],
    "tid": 1
  }'
curl https://zenoss.example.com/zport/dmd/device_router \
  -H "Content-Type: application/json" \
  -u "api-username:api-password"  \
  -X POST -s -S -d \
  '{
    "action": "DeviceRouter",
    "method": "addDevice",
    "data": [
      {
        "deviceName": "device.example.com",
        "deviceClass": "/Server/Linux"
      }
    ],
    "tid": 1
  }'