Authenticating against the FMC REST API
In this recipe, we'll learn how to obtain an authentication token for our FMC console. In contrast to other REST APIs, such as the Cisco Meraki API we explored in a previous chapter, FMC's REST API does not use a static authentication token that can be generated for a user and is valid indefinitely. Instead, we must use our username/password combination to obtain a token that can then be used for all further requests to authenticate the request. In addition to the token itself, the response also contains a list of available domains that our account has access to.
Since we must do this authentication for every request, we'll write a function that takes our username/password combination as well as the base URL of our console and returns an authenticated requests session
object, as well as a list of domains. We will then reuse this function in the coming chapters to create an authenticated session.
Getting ready
Open your...