Using The Apstra API Docs

API Token Creation

To do anything with API you must generate your token. In general terms, an API token is a unique identifier used by an application requesting access to a service. In this context, Apstra generates an API token for a client to use. This token is used to authenticate access.

Through the Swagger UI documentation interface, it’s easy to try out the different API calls available and view the responses.

This is just one way to generate a token, the subsequent API request to generate a token can be done in tools such as Postman, via a Python script, etc.

Getting The API Token

Creating the API token is simple and requires the AAA collection of API endpoints.

Navigate AAA API Endpoints

The AAA API endpoints houses the specific login request we need to generate the token.

  1. Step 1 Click on the aaa drop down to expand this section

  2. Step 2 Then select POST /api/aaa/login which will expand the section and give details on the individual API call.

Doc Nav _1

  1. Step 1 shows the API route we need to interact with to authenticate and get the API token. The POST also tells us that this API endpoint is expecting some data from us.

  2. Step 2 the example model highlighted shows the data that the API is expecting to receive from the user which in this case is a username and password in the format highlighted below.

          {
            "username": "admin",
            "password": "admin"
          }
  1. Step 3 outlines the response expected from the server upon a successful request. This is the token that you then use for future API requests.

  2. Step 4 Now that we understand what the API expects to generate the an API token we can try it ourselves by clicking Try it out.

Doc Nav _1

  1. Step 1 Trying yourself is easy, where highlighted change your username and password to reflect your Apstra login username and password.

This is the username and password you use to login to the web UI.
  1. Step 2 Then click execute

Doc Nav _1

And that’s it! you have generated your API token based on your username and password. Highlighted is the API token returned from the API that is valid for 24 hours and you need to use this token for any other requests via the API.

When generating an API token in Apstra, be sure to only copy the information within the quote marks, not including the quotation marks themselves. For example, if the token displayed in the documentation is shown as "1234567890abcdef", you should only copy 1234567890abcdef when using it in your API calls.

Doc Nav _1

Task

Try it yourself using the steps above!

  1. Navigate to the AAA endpoint in Swagger UI API documentation

  2. Select Try it out and add in your own login details

  3. Then execute to return the token