Skip to content

New Tags resource #44

@agowa

Description

@agowa

We recently updated netbox to v2.9.8 and one of our scripts broke because there apparently the api changed and contains now a new resource specifically for tags:

POST /api/tenancy/tenants/?format=json HTTP/1.1
Host: netbox
Authorization: token myTokenString
User-Agent: PowerShell
Content-Type: application/json
Connection: close

{"slug":"BAR111","tags":["MyTagName"],"custom_fields":{"customer_id":"111"},"group":1,"name":"Bar111"}

Error response:

HTTP/1.1 400 Bad Request
Date: Sat, 05 Dec 2020 04:08:45 GMT
Content-Type: application/json
Connection: close
Server: gunicorn/20.0.4
Vary: Accept, Cookie, Origin
Allow: GET, POST, HEAD, OPTIONS
API-Version: 2.9
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
X-Frame-Options: SAMEORIGIN

{"tags":[["Related objects must be referenced by numeric ID or by dictionary of attributes. Received an unrecognized value: MyTagName"]]}

new:

POST /api/tenancy/tenants/?format=json HTTP/1.1
Host: netbox
Authorization: token myTokenString
User-Agent: PowerShell
Content-Type: application/json
Connection: close

{"slug":"BAR111","tags":[92],"custom_fields":{"customer_id":"111"},"group":1,"name":"Bar111"}

The difference is that tags is now a int array instead of a string array. Where the provided number ("92") is the id of the tag resource. The swagger documentation of netbox is apparently incorrect on that part, as it says it's an array of objects with mandatory name and slug.

To get all tags and there id: Get-nbObject -APIUrl "https://netbox" -Resource "extras/tags" | ft

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions