Forum Discussion

Mel_339767's avatar
Icon for Nimbostratus rankNimbostratus
Nov 09, 2017

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




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)




Result: {"code":401,"message":"Authorization failed: user= resource=/mgmt/tm/ltm verb=GET......."}


10 Replies

  • Admin privilege would definitely work. I guess [host] is replaced by F5 management IP in your case. Also, script has "import requests, json"


  • @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.


  • 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.


    That will tell you if your account will work with REST or not.

  • 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('', 'userID', 'password')
    result = f5.get('your/endpoint')
    print json.dumps(result, indent=4, sort_keys=True)   pretty print the json output
  • @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.


  • 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+.


  • @Tom, what value should I put in replacement to ''? Is it 'https://[myip].com?


  • 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_Blankenshi's avatar
      Icon for Altostratus rankAltostratus

      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?