Some users might want to use IMEI to get the data usage for their SIMs. This is not a straightforward approach, but below is an example of how it can be done using the API and automated with Python. Remember that IMEIs will change for a SIM if it moves between devices.
Note: Make sure to replace all the values in-between <>
with your own IDs.
API calls example
You need to first use the IMEI to get the Device ID (make sure to use your Org ID in the call as well):
GET https://dashboard.hologram.io/api/1/devices/?orgid=<org_id>&imei=<imei>
Within the data section, take the value of id which corresponds to deviceid and add it to the below call:
GET https://dashboard.hologram.io/api/1/usage/data?deviceid=<device_id>
This will give you the whole data usage history for that specific IMEI. If you require to filter for a specific date range, you need to convert your start and end date into Unix dates, with an epoch converter.
GET https://dashboard.hologram.io/api/1/usage/data?deviceid=<device_id>×tart=<epoch_start_time>&timeend=<epoch_end_time>
API calls automated with Python example
A basic example on how this can be automate using Python and save the result into a text file:
# Script example - Get SIM data usage from IMEI
import requests
from requests.auth import HTTPBasicAuth
import json
import datetime
# Authentication
usr = 'apikey'
pwd = '<your api key>'
# Vars
orgid = '<your org id>'
imei = '<your imei>'
# Get device info from IMEI
getDevInf = 'https://dashboard.hologram.io/api/1/devices/?orgid=' + orgid + '&imei=' + imei
res = requests.get( getDevInf, auth = HTTPBasicAuth(usr, pwd) )
# Parse output to get DeviceID
resPar = res.json()
data = resPar['data'][0]['id']
# Get SIM data usage from DeviceID
# Date format: year/month/day/hours/minutes/seconds:milliseconds
start = datetime.datetime(2021, 9, 28, 0, 0, 0).strftime('%s')
end = datetime.datetime(2021, 10, 5, 0, 0, 0).strftime('%s')
getDataUsg = 'https://dashboard.hologram.io/api/1/usage/data?deviceid=' + str(data) + '&orgid=' + orgid + '×tart=' + start + '&timeend=' + end
res = requests.get( getDataUsg, auth = HTTPBasicAuth(usr, pwd) )
# Save output into a JSON/TXT file
resPar = json.dumps( res.json(), indent = 4, sort_keys = True )
file_name = 'IMEI_' + imei + '_DataUsage.txt'
file = open(file_name, 'w')
file.write(resPar)
file.close()
print('File: ' + file_name + ' saved successfully!')