Anybody was successful to connect to Netbox from Excel using API?

162 views
Skip to first unread message

Philippe Langlois

unread,
Nov 10, 2021, 11:26:24 AM11/10/21
to NetBox
Hello,

I'm struggling at trying to be able to access Netbox data from Excel using Netbox as the Data Source. I always end up getting "Access to the resource is forbidden" from excel, and don't know how to properly set it up.

Anybody achieved that?

Thanks


Phil

noma...@gmail.com

unread,
Dec 8, 2021, 6:14:17 AM12/8/21
to NetBox
I have no experience with Excel in such a manor, but have you specified a valid API token that has the required permissions for what you want to do?
I mean it just a HTTP(s) request from Excel to Netbox-server, so communications has to be in place first.

Feng Xia

unread,
Dec 8, 2021, 7:57:52 AM12/8/21
to NetBox
Hi Phil,

As Noma said, the API is a RESTful API, and it requires a user token per each HTTP call.


To setup a token:

1. First create a Django superuser: `python manage.py createsuperuser`, then follow the prompt. The `email` question is optional, you can leave that blank.
2. Now, you go to the `admin` site. If you run the Netbox by `python manage.py runserver`, then go to `http://localhost:8000/admin`. You should see the Admin login.
3. Use the username, pwd created in step 1 to login.
4. Scroll towards the bottom of the page, says "USERS", under that section you will see the "Tokens". Click "Add" to add a new token.
5. On the form, select the superuser you created in step 1, and click SAVE, it will generate a token string.
6. Now you can use that string in HTTP calls.

I don't know how Excel issues HTTP call. But these should give you good clue to figure it out in Excel. Hope this helps.

Best,
feng

rsepul...@gmail.com

unread,
Dec 9, 2021, 11:23:11 AM12/9/21
to NetBox
Hi,

Once you have an API token, you should add a web data source, through Power Query, using the advanced option. You should be using the following parameters:
* An URL that you can get from http://localhost:8000/api/docs (as in the example above) or clicking on the "REST API documentation" icon on the footer. Anyone marked as GET.
* Declare your API token as header, writing "Authorization" at left and "Token your_token" at right, without quotes and replacing your_token with the string you already obtained.

You should see it in advanced editor like this:

let
    Origin = Json.Document(Web.Contents("http://localhost:8000/api/virtualization/virtual-machines/?limit=0", [Headers=[Authorization="Token your_token"]])),
    results = Origin[results],
(...)

In this part you'll have to obtain data from the list. To achieve that, you should watch this video: https://www.youtube.com/watch?v=zUCBYDvRUYM .
Reply all
Reply to author
Forward
0 new messages