devnetuser and the password Cisco123! become
ZGV2- bmV0dXNlcjpDaXNjbzEyMyE= when they
are base-64 encoded. The only missing component is the
resource that you need to send the authorization request
to. You verify the documentation and see that the
authorization resource is /system/api/v1/auth/token
and requires the API call to be POST. With this
information, you can build the authorization API
endpoint, which becomes
https://sandboxdnac2.cisco.com/system/api/v1/auth/to
ken.
Next, you will use curl, a command-line tool that is
useful in testing REST APIs and web services. Armed
with the authorization API endpoint, the Authorization
header containing the base-64-encoded username and
password, and the fact that the API call needs to be a
POST call, you can now craft the authorization request in
curl. The authorization API call with curl should look as
follows:
Click here to view code image
curl -X POST \
https://sandboxdnac2.cisco.com/dna/system/api/v1/auth/token
\
-H 'Authorization: Basic
ZGV2bmV0dXNlcjpDaXNjbzEyMyE='
The result should be JSON formatted with the key Token
and a value containing the actual authorization token. It
should look similar to the following:
Click here to view code image
{"Token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Y2U3M-
TJiMDhlZTY2MjAyZmEyZWI4ZjgiLCJhdXRoU291cmNlIjoiaW50ZXJuYWwiL-
CJ0ZW5hbnROYW1lIjoiVE5UMCIsInJvbGVzIjpbIjViNmNmZGZmNDMwOTkwM-