Add query parameters to pre-fill script fields via URL #11731

Closed
opened 2025-12-29 21:49:13 +01:00 by adam · 4 comments
Owner

Originally created by @maxblome on GitHub (Oct 15, 2025).

NetBox version

v4.4.3

Feature type

New functionality

Proposed functionality

It would be nice if parameters could be pre-filled directly via the URL

Example:

Script:

class MyScript(Script):
    ...
    device = ObjectVar(
        model=Device,
    )
    ...

https://<netbox>/extras/scripts/1/?device=1
or

https://<netbox>/extras/scripts/1/?vars={"device": "1"}
encoded:
https://<netbox>/extras/scripts/1/?vars={%22device%22:%20%221%22}

Use case

e.g. if you want to create custom links and want to pass a device directly there so that the user does not have to fill everything in again themselves

Example Link:

/extras/scripts/1/?device={{ object.id }}
or
/extras/scripts/1/?vars={"device": "{{ object.id }}"}

Database changes

not required

External dependencies

No response

Originally created by @maxblome on GitHub (Oct 15, 2025). ### NetBox version v4.4.3 ### Feature type New functionality ### Proposed functionality It would be nice if parameters could be pre-filled directly via the URL Example: Script: ```python class MyScript(Script): ... device = ObjectVar( model=Device, ) ... ``` `https://<netbox>/extras/scripts/1/?device=1` or `https://<netbox>/extras/scripts/1/?vars={"device": "1"}` encoded: `https://<netbox>/extras/scripts/1/?vars={%22device%22:%20%221%22}` ### Use case e.g. if you want to create custom links and want to pass a device directly there so that the user does not have to fill everything in again themselves Example Link: `/extras/scripts/1/?device={{ object.id }}` or `/extras/scripts/1/?vars={"device": "{{ object.id }}"}` ### Database changes not required ### External dependencies _No response_
adam added the type: feature label 2025-12-29 21:49:13 +01:00
adam closed this issue 2025-12-29 21:49:13 +01:00
Author
Owner

@pheus commented on GitHub (Oct 15, 2025):

Thanks for the feature request — and for the idea!

Good news: this is already supported for script variables via query parameters. I verified it with a minimal example below.

from extras.scripts import Script, ObjectVar
from dcim.models import Device

class QueryDevice(Script):
    class Meta:
        name = "Query Device"
        description = "Query for a Device"

    device = ObjectVar(
        label="Device",
        model=Device,
    )

    def run(self, data, commit):
        device = data["device"]
        self.log_success(f"Found device: {device} (ID: {device.pk})")

With this script in place, visiting a URL like the following will pre-fill the Device field (assuming a Device with primary key 1 exists and you have permission to view it):

https://<netbox>/extras/scripts/1/?device=1

A couple of tips:

  • The query parameter name must match the variable name defined on the script (device in the example).
  • For ObjectVar, pass the object’s primary key as the value.
  • If the provided ID doesn’t exist or you don’t have access, the field won’t pre-populate.

If this covers your use case, I think we can mark the FR as already supported. If you were aiming for something a bit different, let us know. Thanks again for taking the time to file the request!

@pheus commented on GitHub (Oct 15, 2025): Thanks for the feature request — and for the idea! Good news: this is already supported for script variables via query parameters. I verified it with a minimal example below. ```python from extras.scripts import Script, ObjectVar from dcim.models import Device class QueryDevice(Script): class Meta: name = "Query Device" description = "Query for a Device" device = ObjectVar( label="Device", model=Device, ) def run(self, data, commit): device = data["device"] self.log_success(f"Found device: {device} (ID: {device.pk})") ``` With this script in place, visiting a URL like the following will pre-fill the **Device** field (assuming a `Device` with primary key `1` exists and you have permission to view it): ``` https://<netbox>/extras/scripts/1/?device=1 ``` A couple of tips: - The query parameter name must match the variable name defined on the script (`device` in the example). - For `ObjectVar`, pass the object’s primary key as the value. - If the provided ID doesn’t exist or you don’t have access, the field won’t pre-populate. If this covers your use case, I think we can mark the FR as already supported. If you were aiming for something a bit different, let us know. Thanks again for taking the time to file the request!
Author
Owner

@maxblome commented on GitHub (Oct 16, 2025):

Thanks, that's exactly what I was looking for. Then I must have done something wrong when testing it. Unfortunately, I couldn't find it in the documentation, or did I miss something?

@maxblome commented on GitHub (Oct 16, 2025): Thanks, that's exactly what I was looking for. Then I must have done something wrong when testing it. Unfortunately, I couldn't find it in the documentation, or did I miss something?
Author
Owner

@pheus commented on GitHub (Oct 16, 2025):

Thanks for circling back - glad that solved it!

This behavior (prefilling script variables via URL query parameters) works today, but it isn’t called out in the documentation yet. Per contribution process, documentation updates are tracked with a documentation issue before a PR is opened. I’ll open a docs issue to capture this addition and link it here for visibility.

Thanks again for flagging the docs gap. We’ll get it tracked and improved!

@pheus commented on GitHub (Oct 16, 2025): Thanks for circling back - glad that solved it! This behavior (prefilling script variables via URL query parameters) works today, but it isn’t called out in the documentation yet. Per contribution process, documentation updates are tracked with a **documentation issue** before a PR is opened. I’ll open a docs issue to capture this addition and link it here for visibility. Thanks again for flagging the docs gap. We’ll get it tracked and improved!
Author
Owner

@jnovinger commented on GitHub (Oct 18, 2025):

Thanks for creating the new docs issue, @pheus. Closing this one now.

@jnovinger commented on GitHub (Oct 18, 2025): Thanks for creating the new docs issue, @pheus. Closing this one now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11731