• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Get Current and Historic Point Values Through REST API

    User help
    3
    8
    1.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      chio
      last edited by

      I'm trying to use the REST API to bring data from Mango into another system. I can authenticate and get data point information, however, I can't figure out how to get current values or historic values. Seems like I must be missing something simple in the documentation?

      import requests
      from requests.auth import HTTPBasicAuth
      
      userName = 'myusername'
      token = 'mypassword'
      theAuth = HTTPBasicAuth(userName, token)
      
      session = requests.Session()
      response = session.get('https://monitoring.OurDomain.com/rest/v1/users/current', auth=theAuth)
      
      if response.status_code == 200:
          print("Success Logging In")
          payLoad = {'xid': 'internal_mango_uptime_hrs'}
          response = session.get('https://monitoring.OurDomain.com/rest/v1/data-points/', data=payLoad, auth=theAuth)
          print(response.status_code)
          print(response.text)
      else:
          print("Error")
          print(response.status_code)
          print(response.text)
      #  log a auth fault 
      
      1 Reply Last reply Reply Quote 0
      • MattFoxM
        MattFox
        last edited by MattFox

        For the latest (current values) use this and set the limit to 1 for the most up to date value:

        https://monitoring.[domain].com/rest/v2/point-values/{XID}
        

        For historic you'll want:

        //This one is a GET, use params
        https://monitoring.[domain].com/rest/v2/point-values/multiple-arrays/time-period/{xids}
        

        Read in the swagger UI and you'll see the params you need to pass in the URL for both of these calls.

        make sure you have access to the swagger API info by ensuring it's enabled in the env.properties file.

        Fox

        Do not follow where the path may lead; go instead where there is no path.
        And leave a trail - Muriel Strode

        C 1 Reply Last reply Reply Quote 0
        • C
          chio @MattFox
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • C
            chio
            last edited by

            Thanks @MattFox for the quick response. swagger is enabled and mango has been reset but now I'm getting a 403 error. I have confirmed the username and password are accurate. Any ideas?

            payLoad = {'username': userName, 'password': password}
            session = requests.Session()
            response = session.post('https://monitoring.[domain].com/rest/v2/login', json=payLoad)
            
            if response.status_code == 200:
                print("Success Logging In")
                print(response.status_code)
                print(response.text)
            else:
                print("Error")
                print(response.status_code)
            
            1 Reply Last reply Reply Quote 0
            • phildunlapP
              phildunlap
              last edited by

              This thread may have useful insights: https://forum.infiniteautomation.com/topic/2658/any-generic-guide-to-rest-api-python/9

              It could be a header issue, or it could be related to the XSRF token.

              1 Reply Last reply Reply Quote 0
              • C
                chio
                last edited by

                This fixed it and i can now login. thanks @MattFox and @phildunlap

                payLoad = {'username': userName, 'password': password}
                session = requests.Session()
                session.headers.update({'Cookie':'XSRF-TOKEN=dc1d54de-fab1-4405-8ccb-ea677aadf7ca','X-Xsrf-Token':'dc1d54de-fab1-4405-8ccb-ea677aadf7ca','Accept': 'application/json', 'Accept-Encoding': 'gzip,deflate,sdch'})
                # session.headers["Content-Type"] = "application/json"
                response = session.post('https://monitoring.[domain].com/rest/v2/login', json=payLoad)
                
                1 Reply Last reply Reply Quote 0
                • MattFoxM
                  MattFox
                  last edited by

                  Thanks Phil, haven't quite mastered the art of answering forum posts while catching 40 winks!
                  Good to see you're sorted Chio.

                  Fox

                  Do not follow where the path may lead; go instead where there is no path.
                  And leave a trail - Muriel Strode

                  1 Reply Last reply Reply Quote 0
                  • phildunlapP
                    phildunlap
                    last edited by

                    I'm largely a librarian of previously answered questions at this point :D

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post