07-06-2026 02:01 PM
All,
I am looking for some direction on scripting a RestAPI call to our FMC (7.5). I have been able to figure out how to send the API call via curl and find the Auth Token that I then copy/paste into to GET that then returns my info. However, really cludgy and there must be a better way...
What I am doing is:
curl -i -k -X 'POST' -u "username:passwd" https://ip.addr/api/fmc_platform/v1/auth/generatetoken
which then returns the token as part of the header which shows in the debug...
Then I copy/paste the token into this
curl -k -X 'GET' 'https://ip.addr/api/fmc_config/v1/domain/domain.uuid/object/networkaddresses?limit=1500&expanded=true' -H 'accept: application/json' -H 'X-auth-access-token: token'
which then spits out the first page of a couple pages of objects.
If you cannot tell I am a nub when it comes to using APIs. I am thinking that there must be a easier/better way to script this and am hoping that one of the bright minds has already done it?
Thanks, Jeff
07-06-2026 03:38 PM - edited 07-06-2026 03:38 PM
curl is great for one-off tests or when doing some ad-hoc actions.
If you're going to script some functionality towards the FMC, using a scripting/programming language, like python, is the appropriate approach.
You can find a number of examples over at DevNet and within DevNet's code exchange - https://developer.cisco.com/codeexchange/
That's the easier way to handle both the authentication and pagination etc etc.
And I believe there are some libraries for FMC out there.
07-06-2026 11:57 PM
Hello,
Instead of manually copying tokens, you can script the FMC REST API calls to first request the token, parse it from the response header, and then automatically include it in subsequent GET requests. Most people use a wrapper script in Python or Bash that handles authentication, stores the token, and loops through paginated results. This way, the process is seamless—no copy/paste—and you can automate pulling all pages of objects with a single script.
07-07-2026 01:49 AM
You don't need to manually copy and paste the token each time. A common approach is to automate the process with a small Bash or Python script that first sends the authentication request, extracts the X-auth-access-token from the response headers, and then immediately uses that token for your GET request. That way, every execution obtains a fresh token automatically.
If you're using curl, you can also save the response headers to a file with -D headers.txt and then parse the token from that file before making subsequent API calls. This makes the workflow much cleaner and easier to automate.
On a different note, if you ever need to generate or format text for documentation, comments, or notes while working on projects like this, I've found https://conversorletras.co/ useful for quickly creating different Unicode text styles.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide