cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ljwalker
Level 8
Report Inappropriate Content
Message 1 of 4

Must provide a device type?

Jump to solution

Hello All,

Just starting my ESM experience and have a question about the API.

When I run my python code i get the following response.

Must provide a device type

Bellow is the code and full response.(minus ip and auth info) I also bolded the line that is causing the issue.

#!/usr/bin/env python

import base64

import requests

from requests import Request, Session

import re

import json

# Developing URL strings with session login
auth_string = user + ':' + password  # preps login
credentials = base64.b64encode(auth_string)  # base 64 is the preferred format for http communication
url_base = 'https://' + esm + '/rs/esm'  # this is the url to send commands to
login_url = url_base + '/login'  # logging in to system

# header for session persistence
login_headers = {'Authorization': 'Basic ' + credentials, 'Content-Type': 'application/json'}

login_response = requests.post(login_url, headers=login_headers, verify=False)

session = login_response.headers['location']

session_header = {'Authorization': 'Session ' + session, 'Content-Type': 'application/json'}

# commands to get reports
version = requests.get(url_base + '/getVersion', headers=session_header, verify=False)

dataReturned = requests.post(url_base + '/devGetDeviceList?filterByRights=false',
   data='{"config": '
  '{"type": "RECEIVER"}}',
   headers=session_header, verify=False)

# TODO How to get data into body of http post/get for mor specific results?
# data.body = {"config": {"type": "RECEIVER"}}

# print results
print(version.content)

print(version.url)

print(dataReturned.url)

print(dataReturned.content)

# terminate session
requests.delete(url_base + '/logout', headers=session_header, verify=False)

Response (minus insecure request warning)

{"return": {

    "apiMajorVersion": 3,

    "apiMinorVersion": 0,

    "esmMajorVersion": 9,

    "esmMinorVersion": 5,

    "esmPatch": "",

    "esmRevision": 2,

    "esmVersionString": "9.5.2 20160128"

}}

https://IP/rs/esm/getVersion

https://IP/rs/esm/devGetDeviceList?filterByRights=false

Must provide a device type

Process finished with exit code 0

Thanks in advance for any help!

1 Solution

Accepted Solutions
ljwalker
Level 8
Report Inappropriate Content
Message 4 of 4

Re: Must provide a device type?

Jump to solution

I found what I was looking for. Turned out to be a small error.

the line

data='{"config": {"type": "RECEIVER"}}',

created the error

Must provide a device type

The line should be as follows

data='{"types": "RECEIVER"}}',

Notice two points.

No need for the config, but more important is that type needed to be types.

While the error says type the example in the documentation shows types.

View solution in original post

3 Replies
rgarrett
Level 9
Report Inappropriate Content
Message 2 of 4

Re: Must provide a device type?

Jump to solution

data sources are tied to a receiver, and the API needs to know the ID of the reciever.  To get that , use the devGetDeviceList service

From the docuentation:

Something like

List<EsmDevice> devices =

api.devGetDeviceList(Collections.singletonList(EsmDeviceType.ELMREC), false);

for(EsmDevice rec : devices)

     { if(rec.getName().equals("Receiver01"))

     { mReceiver = rec; }

     }

}

ljwalker
Level 8
Report Inappropriate Content
Message 3 of 4

Re: Must provide a device type?

Jump to solution

I must completely misunderstand what the command does.

I thought it would return a list of all receivers connected to the ESM.

something like;

if device = receiver

     return device details.

else skip

ljwalker
Level 8
Report Inappropriate Content
Message 4 of 4

Re: Must provide a device type?

Jump to solution

I found what I was looking for. Turned out to be a small error.

the line

data='{"config": {"type": "RECEIVER"}}',

created the error

Must provide a device type

The line should be as follows

data='{"types": "RECEIVER"}}',

Notice two points.

No need for the config, but more important is that type needed to be types.

While the error says type the example in the documentation shows types.

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