Analytics: Query Data

All of the analytics endpoints are GET functions and return data.

/v2/analytics/last_n_values/“login_id”

This endpoint returns a dictionary containing the most recent n values of the specified tag for the specified user. Note: If you do not specify the user, it will redirect you to the "last_value" endpoint listed below.

Role permissions

This operation is permitted for business users or the user with the given login id.

GET
Headers
Content-Type: application/json

 

URL Encoded Parameters
  • The following keys are required:
    • field : The clean name of the tag you want the data for. It must have the stream name before the tag, for example: raw.tag
  • The following keys are optional:
    • limit : limit of how many fields returned, default to 1
    • since : ISO8601 format with tzoffset
    • until : ISO8601 format with tzoffset
  • Returns a list of dictionaries, one dictionary for each of the last N values, with N as the limit field.

 

HTTP Response

200 OK

  • Successfully received data

400 BAD REQUEST

  • The request had a syntax or type error cause before sending it to the server

401 UNAUTHORIZED

  • No authorized user is currently logged in.

403 FORBIDDEN

  • Not authorized to post data for the given user.

415 NOT FOUND

  • Unsupported Media Type; likely missing the header

404 NOT FOUND

  • No user matching login_id can be found.

500 SERVER ERROR

  • Could not complete the request due to an internal server error.

503 SERVICE UNAVAILABLE

  • Temporarily unable to complete the request. Please try again.



Examples

Curl

#Login as a business user
curl -c cookies.txt -X POST -k -H 'Content-Type:application/json' -H 'Accept: application/json' -i 'https://api.mediumone.com/v2/login' -d '{"login_id":"john_doe_business", "password":"12345", "api_key":"ABCDEFGHIJKLMNOPabcdefghijklmnop1234567890"}'

#Request up to 10 recent values of the tag test in stream raw, for user john_doe
curl -b cookies.txt -X GET -k -H 'Content-Type: application/json' -i 'https://api.mediumone.com/v2/analytics/last_n_values/john_doe?field=raw.test&limit=10'

Python

import certifi
import requests
import json
import urllib

login_headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
analytics_headers = {'Content-Type': 'application/json'} 
data = {'login_id': 'john.doe@mediumone.com', 'password': '12345', 'api_key': 'ABCDEFGHIJKLmnopabcdefghijklmnop1234567890'}

session = requests.session()
response = session.post('https://api.mediumone.com/v2/login', data=json.dumps(data), headers=headers, verify=certifi.where())

data = {"field":"raw.test", "limit": "10"}

url = 'https://api.mediumone.com/v2/analytics/last_n_values?' + urllib.urlencode(data)

response = session.get(url=url, headers=analytics_headers, verify=certifi.where())

 

/v2/analytics/last_value/“login_id”

This endpoint returns the last value of one or more tags for the specified user.

Role permissions

This operation is permitted for both business users and regular users, but a regular user can only access its own data.

 

GET
Headers
Content-Type: application/json

 

Body
  • Required URL Encoded parameters:
    • field : The clean tag names for each field you want the data for. They must have the stream name before the tag, for example: raw.tag or processed.tag. This parameter can repeat multiple times in the url, once for each field you want.
  • Returns: a dictionary with each field and its respective most recent value.

 

HTTP Response

200 OK

  • Successfully received data

400 BAD REQUEST

  • The request had a syntax or type error cause before sending it to the server

401 UNAUTHORIZED

  • No authorized user is currently logged in

403 FORBIDDEN

  • Not authorized to post data for the given user

415 NOT FOUND

  • Unsupported Media Type; likely missing the header

500 SERVER ERROR

  • Could not complete the request due to an internal server error

503 SERVICE UNAVAILABLE

  • Temporarily unable to complete the request. Please try again

 

Examples

Curl

#Login as correct user
curl -c cookies.txt -X POST -k -H 'Content-Type:application/json' -H 'Accept: application/json' -i 'https://api.mediumone.com/v2/login' -d '{"login_id":"john_doe", "password":"abcde", "api_key":"ABCDEFGHIJKLMNOPabcdefghijklmnop1234567890"}'

curl -b cookies.txt -X GET -k -H 'Content-Type: application/json' -i 'https://api.mediumone.com/v2/analytics/last_value/john_doe?field=raw.test&field=processed.test2'

Python

import certifi
import requests
import json

login_headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
analytics_headers = {'Content-Type': 'application/json'} 
data = {'login_id': 'john.doe@mediumone.com', 'password': '12345', 'api_key': 'ABCDEFGHIJKLmnopabcdefghijklmnop1234567890'}

session = requests.session()
response = session.post('https://api.mediumone.com/v2/login', data=json.dumps(data), headers=headers, verify=certifi.where())

url = 'https://api.mediumone.com/v2/analytics/last_value/john_doe?field=raw.test'

response = session.get(url=url, headers=analytics_headers, verify=certifi.where())

 

/v2/analytics/last_value/

This endpoint returns the last value of each tag for all users.

 

Role permissions

This operation is permitted only by business users.

 

GET
Headers
Content-Type: application/json

 

Body
  • Optional URL Encoded parameters:
    • order : The optional field for the tags to be sorted by, default is event timestamp (optional)
    • direction : the direction to be sorted, ASC or DESC, default is DESC (optional)
    • limit : the number of returned records, default to 1000
  • Returns: a list of lists where the first element of the list is the userID, second is a dictionary containing all the last values. For example, [["user", {last_values}]]

 

HTTP Response

200 OK

  • Successfully received data

400 BAD REQUEST

  • The request had a syntax or type error cause before sending it to the server

401 UNAUTHORIZED

  • No authorized user is currently logged in

403 FORBIDDEN

  • Not authorized to post data for the given user

415 NOT FOUND

  • Unsupported Media Type; likely missing the header

500 SERVER ERROR

  • Could not complete the request due to an internal server error

503 SERVICE UNAVAILABLE

  • Temporarily unable to complete the request. Please try again

 

Examples

Curl

#Login as business user
curl -c cookies.txt -X POST -k -H 'Content-Type:application/json' -H 'Accept: application/json' -i 'https://api.mediumone.com/v2/login' -d '{"login_id":"john_doe", "password":"abcde", "api_key":"ABCDEFGHIJKLMNOPabcdefghijklmnop1234567890"}'

curl -b cookies.txt -X GET -k -H 'Content-Type: application/json' -i 'https://api.mediumone.com/v2/analytics/last_value?limit=4'

Python

import certifi
import requests
import json

login_headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
analytics_headers = {'Content-Type': 'application/json'}
data = {'login_id': 'john.doe@mediumone.com', 'password': '12345', 'api_key': 'ABCDEFGHIJKLmnopabcdefghijklmnop1234567890'}

session = requests.session()
response = session.post('https://api.mediumone.com/v2/login', data=json.dumps(data), headers=headers, verify=certifi.where())

url = 'https://api.mediumone.com/v2/analytics/last_value/?limit=4'

response = session.get(url=url, headers=analytics_headers, verify=certifi.where())

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.