Skip to content

id parameter of get.dcim.devices action #48

Open

Description

@rgrueebler

Hi everyone,

I played around with the netbox.get.dcim.devices action. When I execute it without any parameters, it returns all the devices, which is expected. There is also the 'id' parameter. I assumed that I can get the data from a specific device with it. I realized that I need to enter a list. So I executed the action with an 'id' of '[1]'.

The return value of the action is this:

{
  "raw": {},
  "status": 404
}

In the nginx access logs from Netbox there is the following entry:

25/Feb/2024:08:15:33 -0500] "GET /api/dcim/devices/%5B1%5D/?save_in_key_store=False&save_in_key_store_ttl=60 HTTP/1.1" 404 23 "-" "python-requests/2.31.0"

My understanding is that '%5B1%5D/' represents '[1]'. So the action tries to access '/api/dcim/device/[1]...'.
Am I using the id parameter in the wrong way?

Thank you
Remo

Activity

  1. aopdal commented on Feb 26, 2024

    @aopdal

    I think you are right, when I test creating a workflow using the action like this:

    version: 1.0
    tasks:
      task1:
        action: netbox.get.dcim.devices
        input:
          id:
            - 1
    

    I get:
    st2.actions.python.NetboxHTTPAction: DEBUG endpoint_uri transformed to /dcim/devices/[1]/ because id was passed

    When I try in NetBox API /api/dcim/devices/{id}/ I get:

    /api/dcim/devices/1/

    And If I tries

    version: 1.0
    tasks:
      # [261, 196]
      task1:
        action: netbox.get.dcim.devices
        input:
          id:
            - 1
            - 2
    

    I get

    endpoint_uri transformed to /dcim/devices/[1, 2]/ because id was passed

    But I want something like:
    api/dcim/devices/?id=1&id=2

    So I think it looks like the action get.dcim.devices is a combination of two API endpoints:

    /api/dcim/devices/
    /api/dcim/devices/{id}/

  2. aopdal commented on Feb 26, 2024

    @aopdal

    Looks like its her in the run.py:

            if http_verb == 'get':
                if kwargs.get('id', False) and get_detail_route_eligible:
                    # modify the `endpoint_uri` to use the detail route
                    endpoint_uri = '{}{}/'.format(endpoint_uri, str(kwargs.pop('id')))
                    self.logger.debug(
                        'endpoint_uri transformed to {} because id was passed'.format(endpoint_uri)
                    )
    

    For this to work it must be only one ID used in the get, and the [] must be stripped. And it may be hitting all the get actions when ID is used.

  3. rgrueebler commented on Feb 28, 2024

    @rgrueebler
    Author

    Do you mean something like tihs:
    endpoint_uri = '{}{}/'.format(endpoint_uri, str(kwargs.pop('id')[0]))

  4. self-assigned this
    on Feb 28, 2024
  5. aopdal commented on Feb 28, 2024

    @aopdal

    Do you mean something like tihs: endpoint_uri = '{}{}/'.format(endpoint_uri, str(kwargs.pop('id')[0]))

    No, I just pointed out the api request is changed when ID is used. If other fields is used it works with more than one. When the api is the way it is it support just one.

    I don't use the ID in my workflows, so I have not been hit by this.

  6. johanek commented on Mar 3, 2026

    @johanek
    Contributor

    We’re seeing this too on v3.4.4 after upgrading from 3.0.5. In 3.0.5 the id parameter for get.dcim.devices was a string, so st2 run netbox.get.dcim.devices id=105587 correctly hit /api/dcim/devices/105587/. In 3.4.4 the action schema now declares id as type: array, so StackStorm passes id as a list (e.g. [105587] or [105587, 1234]).

    Because actions/run.py still does endpoint_uri = "{}{}/".format(endpoint_uri, str(kwargs.pop("id"))), the detail-route URL becomes /dcim/devices/[105587]/ for a single id, or /dcim/devices/[105587, 1234]/ for an array of ids, which NetBox rightly 404s.

    I have a fixed version which I will raise a PR for shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions