GET /app/devices/{device_id}/data

URL requires a header and body with the following format (Items in bold are required):

Body:

No request body is required as this is a GET request

Response:

JSON object containing all the last posted data entry

Code Example

Python example to post Device Data:

#!/usr/bin/python3

# Get_Last_Data
#
# Retrieve last instance of data posted to a specific device
# This example is built on top of the API Login Example
# This example is built on top of the API Get Device ID example
# This example is built on top of the API Get Device Info example
#
# Copyright (c) 2021 Engineering Design Group, LLC. All Rights Reserved.
#
# <variable_name> represents value specific to user

import requests
import json
from pprint import pprint

#Need an access token to access this API endpoint
import Get_app_token
import Get_Device_ID
import Get_Device_info

#getData returns the most recent data structure posted to the specified device.
def getData(accessToken = "", deviceUuid = ""):

    #retrieve access token if user does not provide one
    if accessToken == "":
        accessToken = Get_app_token.getToken(<user_username>, <user_password>, <client_ID>)

    #if the user did not provide a device UDID, fetch all Device UDID's and let the user choose
    if deviceUuid == "":

        #pull a list of each Device ID
        deviceIdList = Get_Device_ID.getDeviceId(accessToken)
        print("displaying all device IDs and UDIDs...\\n")

        i = 0
        for deviceId in deviceIdList:

            #get the device info for each unique device, extract board name and device UDID
            deviceInfo = Get_Device_info.getDeviceInfo(accessToken, deviceId)
            deviceName = deviceInfo['boardName']
            deviceUdid = deviceInfo["pcbSn"]

            #display each board with a number so user can choose which board to use
            print("Device #%d" %i, deviceName)
            print("DeviceID:", deviceId, end = ": ")
            print("UDID:", deviceUdid, "\\n")

            i += 1

        deviceIdIndex = int(input("Which device number would you like to retrieve data for? "))
        deviceId = deviceIdList[deviceIdIndex]

    #generate URL for GET request
    baseUrl = "<https://edglabsb.azurewebsites.net>"
    endpointAddress = "/app/devices/" + deviceId + "/data"
    dataUrl = baseUrl + endpointAddress

    #create header and body to send to API
    authHeader={
        "Authorization": "Bearer " + accessToken,
        "Content-Type": "application/json"
    }

    #retrieve most recent Data using GET request
    response = requests.get(dataUrl,
                           headers = authHeader,
                           verify = True)
    #display API response code
    print("Device Data: ", response)

    deviceData = response.json()

    return deviceData

def main():
    print("Retrieving most recent data for device...")
    device_data = getData()
    #display list of device ID's accessible by user
    print("DeviceData: ")
    pprint(device_data)

if __name__ == "__main__":
    main()