API support for power connections #1470

Closed
opened 2025-12-29 16:32:20 +01:00 by adam · 3 comments
Owner

Originally created by @einstux on GitHub (Dec 20, 2017).

Issue type

[X ] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • NetBox version: 2.2.6

Description

We noticed that the API in 2.2 is missing write functions for power connections,
is this on purpose?

Is somebody already working on this, or is a merge request at a later point appreciated?

Thanks,
Tom

Originally created by @einstux on GitHub (Dec 20, 2017). ### Issue type [X ] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * NetBox version: 2.2.6 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description We noticed that the API in 2.2 is missing write functions for power connections, is this on purpose? Is somebody already working on this, or is a merge request at a later point appreciated? Thanks, Tom
adam closed this issue 2025-12-29 16:32:20 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 20, 2017):

@sirtux What are you trying to do? What is the request being made to the API?

@jeremystretch commented on GitHub (Dec 20, 2017): @sirtux What are you trying to do? What is the request being made to the API?
Author
Owner

@einstux commented on GitHub (Dec 21, 2017):

I want to connect a power port to a power outlet via API,
and I don't see a /api/dcim/power-connections POST support, only GET. If I try a post I get afair a 405 error.

I'd like to see the same featureset as a post on /api/dcim/interface-connections.

@einstux commented on GitHub (Dec 21, 2017): I want to connect a power port to a power outlet via API, and I don't see a /api/dcim/power-connections POST support, only GET. If I try a post I get afair a 405 error. I'd like to see the same featureset as a post on /api/dcim/interface-connections.
Author
Owner

@jeremystretch commented on GitHub (Dec 21, 2017):

Ah. Interface connections are modeled differently than console and power connections due to their bidirectional nature: There's a discreteInterfaceConnection model which represents a connection between two interfaces. Console and power connections, however, use the ConsolePort and PowerPort models to define connections.

What you want is the /api/dcim/power-ports/<id>/ endpoint. A PATCH request to this endpoint lets you define a connected power_outlet:

$ curl -X PATCH -H "Authorization: Token <token>" -H "Content-Type:application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/dcim/power-ports/2891/ --data '{"power_outlet": 44569}'
{
    "id": 2891,
    "device": 1599,
    "name": "PSU0",
    "power_outlet": 44569,
    "connection_status": true
}
@jeremystretch commented on GitHub (Dec 21, 2017): Ah. Interface connections are modeled differently than console and power connections due to their bidirectional nature: There's a discrete`InterfaceConnection` model which represents a connection between two interfaces. Console and power connections, however, use the `ConsolePort` and `PowerPort` models to define connections. What you want is the `/api/dcim/power-ports/<id>/` endpoint. A PATCH request to this endpoint lets you define a connected `power_outlet`: ``` $ curl -X PATCH -H "Authorization: Token <token>" -H "Content-Type:application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/dcim/power-ports/2891/ --data '{"power_outlet": 44569}' { "id": 2891, "device": 1599, "name": "PSU0", "power_outlet": 44569, "connection_status": true } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1470