Bash client for NetBox API (swagger-codegen), how Authorization works or is it broken.

296 views
Skip to first unread message

Pekka Panula

unread,
Sep 25, 2018, 5:40:44 AM9/25/18
to NetBox
Hi all

I made this Bash client for NetBox API using swagger-codegen using https://editor.swagger.io/.

Problem is that i cant get authorization token to work.

So how you define your token when using this generated client, can anyone help me on this?

help says about authorization:
------------8<----------
Authentication methods

  - Api-key - add 'Authorization:<api-key>' after <operation>
------------8<----------

and usage is:
------------8<----------
  client.sh [-h|--help] [-V|--version] [--about] [<curl-options>]
           [-ac|--accept <mime-type>] [-ct,--content-type <mime-type>]
           [--host <url>] [--dry-run] [-nc|--no-colors] <operation> [-h|--help]
           [<headers>] [<parameters>] [<body-parameters>]
------------8<----------

So when i have tried for example: ./client.sh --host https://mynetbox.url.com ipamVlanGroupsList 'Authorization: Token MYTOKEN'
All i get as result: {"detail":"Authentication credentials were not provided."}

Please help.

Stefan de Kooter

unread,
Oct 8, 2018, 2:49:00 PM10/8/18
to NetBox
Netbox required an Authorization header in the format of: Authorization:Token {{authtoken}}
You're missing the 'Token' part?

Pekka Panula

unread,
Oct 22, 2018, 6:10:00 AM10/22/18
to NetBox
Hi

How do i specify Token from CLI?
I have tested severel different formats but nothing seems to be working.

Brian Candler

unread,
Oct 23, 2018, 12:04:01 AM10/23/18
to NetBox
Since you don't show your shell code, there's nothing we can do.

If your shell script is using curl, then it would be something like this:

MYTOKEN="testing123"
curl -H "Authorization: Token $MYTOKEN" ...rest of line...

The documentation already shows plenty of examples using curl:

Follow those.
Reply all
Reply to author
Forward
0 new messages