Get data usage by IMEI through the REST API + Python

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):


Within the data section, take the value of id which corresponds to deviceid and add it to the below call:


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.


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 = '' + 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 = '' + str(data) + '&orgid=' + orgid + '&timestart=' + 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')
print('File: ' + file_name + ' saved successfully!')
Was this article helpful?
0 out of 0 found this helpful