cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted

ESM API 10.2 User Privileges

Jump to solution

Hi,

I followed the guide to use the API v2 (https://kc.mcafee.com/corporate/index?page=content&id=KB90289&actp=null&viewlocale=en_US&showDraft=f...) and I am able to login. However, once I call a function I get this error;

"code" : "70",
"message" : "Not Authorized User",
"errors" : [ ]

Which user has access to do API calls and can specific users be set to use the API.

Thank You.

1 Solution

Accepted Solutions
Highlighted

Re: ESM API 10.2 User Privileges

Jump to solution

Okay..I got it working in python.. Here is the code for anyone interested:

user = "username in base64"
passwd = "password in base64"
base_url = 'https://ip-address/rs/esm/v2/'

params = {"username": user,"password": passwd,"locale": "en_US"}
headers = {'Content-Type': 'application/json'}

"""""""""""""""""""""""""""""""""""""""""""""""""
Log into the ESM
"""""""""""""""""""""""""""""""""""""""""""""""""
method = 'login'
url = base_url+method
data = json.dumps(params)
resp = requests.post(url, data=data,headers=headers, verify=False)

"""""""""""""""""""""""""""""""""""""""""""""""""
Get Cookie and Xref Token
"""""""""""""""""""""""""""""""""""""""""""""""""
headers['Cookie'] = resp.headers.get('Set-Cookie')
headers['X-Xsrf-Token'] = resp.headers.get('Xsrf-Token')

"""""""""""""""""""""""""""""""""""""""""""""""""
Make API calls by changing method
"""""""""""""""""""""""""""""""""""""""""""""""""
method = 'essmgtGetESSTime'
url = base_url+method
resp = requests.post(url, headers=headers,verify=False)
print (resp.text)

 

View solution in original post

3 Replies
Highlighted

Re: ESM API 10.2 User Privileges

Jump to solution

Once you login with your basic-encoded Authorization credentials, ESM API 10.x will return a xsrf-token in the headers. Copy this value and add the token as "X-Xsrf-Token" in your future request headers. Now you should authenticate your session correctly.

So:

  1. POST /rs/esm/login (w/ your json encoded credentials)
  2. retrieve xsrf-token
  3. execute any command, ie GET /rs/esm/qryGetFilterFields
    1. with X-Xsrf-Token = {{your-token}}

 

Highlighted

Re: ESM API 10.2 User Privileges

Jump to solution

I have done that.. This is the command..

curl --cookie 'JTWToken Path=/; Secure; HttpOnly'' -H 'Xsrf-Token: CSRFToken '  -H 'Content-Type: application/json' -X POST https://ip-addrress/rs/esm/v2/essmgtGetESSTime 

and this is the response:

"code" : "70",
"message" : "Not Authorized User",
"errors" : [ ]

Highlighted

Re: ESM API 10.2 User Privileges

Jump to solution

Okay..I got it working in python.. Here is the code for anyone interested:

user = "username in base64"
passwd = "password in base64"
base_url = 'https://ip-address/rs/esm/v2/'

params = {"username": user,"password": passwd,"locale": "en_US"}
headers = {'Content-Type': 'application/json'}

"""""""""""""""""""""""""""""""""""""""""""""""""
Log into the ESM
"""""""""""""""""""""""""""""""""""""""""""""""""
method = 'login'
url = base_url+method
data = json.dumps(params)
resp = requests.post(url, data=data,headers=headers, verify=False)

"""""""""""""""""""""""""""""""""""""""""""""""""
Get Cookie and Xref Token
"""""""""""""""""""""""""""""""""""""""""""""""""
headers['Cookie'] = resp.headers.get('Set-Cookie')
headers['X-Xsrf-Token'] = resp.headers.get('Xsrf-Token')

"""""""""""""""""""""""""""""""""""""""""""""""""
Make API calls by changing method
"""""""""""""""""""""""""""""""""""""""""""""""""
method = 'essmgtGetESSTime'
url = base_url+method
resp = requests.post(url, headers=headers,verify=False)
print (resp.text)

 

View solution in original post

You Deserve an Award
Don't forget, when your helpful posts earn a kudos or get accepted as a solution you can unlock perks and badges. Those aren't the only badges, either. How many can you collect? Click here to learn more.

Community Help Hub

    New to the forums or need help finding your way around the forums? There's a whole hub of community resources to help you.

  • Find Forum FAQs
  • Learn How to Earn Badges
  • Ask for Help
Go to Community Help

Join the Community

    Thousands of customers use the McAfee Community for peer-to-peer and expert product support. Enjoy these benefits with a free membership:

  • Get helpful solutions from McAfee experts.
  • Stay connected to product conversations that matter to you.
  • Participate in product groups led by McAfee employees.
Join the Community
Join the Community