Forum Discussion
What kind of account do I need to access the REST API?
I'm having issues in accessing the API, I think. I got Error 401 whenever I use my credentials that I believe has admin privileges already. Is there a way to access the API without using the "admin" account?
Edit: How do I check if my account has admin privileges?
Below is my code:
import requests
requests.packages.urllib3.disable_warnings()
uname = 'myaccount'
pw = 'mypassword'
req = requests.session()
req.auth = (uname, pw)
req.verify = False
req.headers.update({'Content-Type': 'application/json'})
uri = 'https://[host]/mgmt/tm/ltm'
response = req.get(uri)
print(response.text)
Result: {"code":401,"message":"Authorization failed: user= resource=/mgmt/tm/ltm verb=GET......."}
Admin privilege would definitely work. I guess [host] is replaced by F5 management IP in your case. Also, script has "import requests, json"
- Mel_339767Nimbostratus
@Only1masterblaster: Thanks for the response. I intentionally do the "[host]" thing to hide the real ip. I'm not yet importing json module as I'm not parsing any json data yet since the error message is clear. How would I check if my account has admin privileges to access the REST API.
- Leonardo_SouzaCirrocumulus
If you login to the F5 via HTTPS (GUI), it will tell at the top your user and the type of your account.
I remember a friend saying that REST initially required admin role account when released in 11.5.0, but in 11.6.0 (I think) other users could access. I tried to confirm that looking the release notes, but I could not find anything in relation to that.
Anyway, just try to login to REST via HTTPS, using a browser.
https:///mgmt/toc
That will tell you if your account will work with REST or not.
- Cory_BlankenshiAltostratus
After your credentials are adjusted so that you can access the API, I would take a look at either the f5-sdk or iCR APIs. Both have the REST API under the hood, but making requests to the f5 and getting back data is pretty easy.
Here's some sample code using the iCR API:
!/usr/bin/env python from iCR import iCR import json f5 = iCR.iCR('my.f5.com', 'userID', 'password') result = f5.get('your/endpoint') print json.dumps(result, indent=4, sort_keys=True) pretty print the json output
- Mel_339767Nimbostratus
@Tom, I've downloaded the package already (iCR). Just waiting for my credentials to be adjusted. BTW, is this compatible with 11.5.4 and 12.1.2? Currently, I'm dealing with two versions.
- Cory_BlankenshiAltostratus
I'm not sure about 11.5.4, but it's definitely compatible with 12.1.2 (that's the version we use). Unless there were massive API changes between the two versions though, I would think that code would be good for both. I would be surprised if the API would work for 12+ and not 11.5+.
- Mel_339767Nimbostratus
@Tom, what value should I put in replacement to ''? Is it 'https://[myip].com?
- Cory_BlankenshiAltostratus
@Mel, I use the URL for my F5 (without https://)
- AkanshaNimbostratus
what is a typical bug resolution ETA , running into a bunch of errors with the F5 API and support is not able to help.
- Cory_BlankenshiAltostratus
I think it depends on the severity of the bug. What are the errors you are running into? Can you post a sample of the API endpoint you're trying to hit and the error(s) you get back?
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com