3 Replies Latest reply on Apr 11, 2016 8:40 AM by ljwalker

    Must provide a device type?

    ljwalker

      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. Re: Must provide a device type?
          rgarrett

          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; }

               }

          }

          • 2. Re: Must provide a device type?
            ljwalker

            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

            • 3. Re: Must provide a device type?
              ljwalker

              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.