Share this post on:

Introduction

API of netbox allows to add new devices, prefixes, sites etc. programmatically. We can use a simple API POST to create one or multiple objects

Code

curl -s -X POST -H "Authorization: Token 6588713b7a7bsd3a24c9e445e9e9f0e491e75932" -H "Content-Type: application/json" https://netbox.kuligowski.co.uk/api/ipam/prefixes/ \
--data '[
{"prefix": "192.168.1.0/24", "site": 1},
{"prefix": "192.168.2.0/24", "site": 1},
{"prefix": "192.168.3.0/24", "site": 1},
{"prefix": "192.168.4.0/24", "site": 1}
]'| jq '.'

Result

As expected, all prefixes have been added to our configuration

[
{
"id": 2,
"url": "https://netbox.kuligowski.co.uk/api/ipam/prefixes/2/",
"display": "192.168.1.0/24",
"family": {
"value": 4,
"label": "IPv4"
},
"prefix": "192.168.1.0/24",
"site": {
"id": 1,
"url": "https://netbox.kuligowski.co.uk/api/dcim/sites/1/",
"display": "kuligowski",
"name": "kuligowski",
"slug": "kuligowski"
},
"vrf": null,
"tenant": null,
"vlan": null,
"status": {
"value": "active",
"label": "Active"
},
"role": null,
"is_pool": false,
"description": "",
"tags": [],
"custom_fields": {},
"created": "2021-08-13",
"last_updated": "2021-08-13T10:22:03.711742Z",
"children": 0,
"_depth": 0
},
{
"id": 3,
"url": "https://netbox.kuligowski.co.uk/api/ipam/prefixes/3/",
"display": "192.168.2.0/24",
"family": {
"value": 4,
"label": "IPv4"
},
"prefix": "192.168.2.0/24",
"site": {
"id": 1,
"url": "https://netbox.kuligowski.co.uk/api/dcim/sites/1/",
"display": "kuligowski",
"name": "kuligowski",
"slug": "kuligowski"
},
"vrf": null,
"tenant": null,
"vlan": null,
"status": {
"value": "active",
"label": "Active"
},
"role": null,
"is_pool": false,
"description": "",
"tags": [],
"custom_fields": {},
"created": "2021-08-13",
"last_updated": "2021-08-13T10:22:03.739491Z",
"children": 0,
"_depth": 0
},
{
"id": 4,
"url": "https://netbox.kuligowski.co.uk/api/ipam/prefixes/4/",
"display": "192.168.3.0/24",
"family": {
"value": 4,
"label": "IPv4"
},
"prefix": "192.168.3.0/24",
"site": {
"id": 1,
"url": "https://netbox.kuligowski.co.uk/api/dcim/sites/1/",
"display": "kuligowski",
"name": "kuligowski",
"slug": "kuligowski"
},
"vrf": null,
"tenant": null,
"vlan": null,
"status": {
"value": "active",
"label": "Active"
},
"role": null,
"is_pool": false,
"description": "",
"tags": [],
"custom_fields": {},
"created": "2021-08-13",
"last_updated": "2021-08-13T10:22:03.762467Z",
"children": 0,
"_depth": 0
},
{
"id": 5,
"url": "https://netbox.kuligowski.co.uk/api/ipam/prefixes/5/",
"display": "192.168.4.0/24",
"family": {
"value": 4,
"label": "IPv4"
},
"prefix": "192.168.4.0/24",
"site": {
"id": 1,
"url": "https://netbox.kuligowski.co.uk/api/dcim/sites/1/",
"display": "kuligowski",
"name": "kuligowski",
"slug": "kuligowski"
},
"vrf": null,
"tenant": null,
"vlan": null,
"status": {
"value": "active",
"label": "Active"
},
"role": null,
"is_pool": false,
"description": "",
"tags": [],
"custom_fields": {},
"created": "2021-08-13",
"last_updated": "2021-08-13T10:22:03.786891Z",
"children": 0,
"_depth": 0
}
]

Leave a Comment

Your email address will not be published. Required fields are marked *