Blog

Uncategorized

Connect to NetBox API with Postman

Netbox is the de facto source of truth in the network automation space. It comes packed with some powerful APIs(Application Programming Interface). This ability makes it easy to integrate with your NetDevOps pipeline. When working with APIs in general it’s nice to have a tool where you can query and see how the results are structured. In every DevOps Engineers toolbox, Postman should be near the top.

What is a REST API

In NetBox the API is a “REST” ( REpresentational State Transfer) API. As a result this is a stateless API meaning that each request from the client to the server must contain all the information to interpret the request. Another component of REST is uniform interfaces, there are architectural constraints to make them uniform. They are the identification of resource; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of the application state. REST APIs are also layered, in that you access a specific layer in the hierarchy and that component can not see beyond the immediate layer.

REST APIs provide us a programmatic way to access data where we receive consistently formatted data. Our applications then can process this data in a uniform manner. This allows us to make decisions with the received data. It also allows us to retrieve, update, and create/remove data. Not only can you build applications to interact with API’s you can with Ansible. This is a great way to work with APIs without having to have programming knowledge. We’ll discuss that in further dept in future articles.

Connect to NetBox API

To connect to APIs you typically need to authenticate ( not always, but is recommended if available ). The NetBox REST API employs token-based authentication. Tokens are uniquely mapped to each user. A user may have one or more tokens. To create a token navigate to the API token page in your user profile and click “Add A token”.

Now we move on to Postman. Postman allows us to connect to interact with APIs in a GUI. To make our connection to the NetBox API we need to first create a new request. Click the plus sign to open a new request tab. In the request URL enter "{netbox_url}/api/dcim/devices/". Now to setup authentication click the “Authorization” tab. For the type drop-down select “API Key”. in the Key filed put “Authorization”. The value should be "Token {NETBOX_TOKEN}", the add to dropdown should be “Header”. What all this does is it adds your token to the request header Postman sends to the NetBox API. Click “Send” and you will see some results appear below!

That’s it, now you can start exploring the NetBox API. Every installation of the API has swagger setup to view all the different calls and requirements. Simply navigate to “{NETBOX_URL}/api/docs”. If you’d like to learn more about the full NetDevOps pipeline and how it can benefit your company feel free to contact us for a free consultation.

Leave your thought here