Report

Reporting endpoints let you create and fetch a raw data export based on a selected period and optional filters such as shared inbox, users, tags, etc. The two endpoints (Export Report & Get Report) and involved due to the asynchronous nature of generating reports: one request to create the report and another to get the data shortly after.

Raw exports can be programmatically created via Export Report API endpoint and fetched via Get Report endpoint

One can use the following Python code snippet to bootstrap coding API access for raw data exports.

# Example Python code that exports the report for the last 7 days

import datetime
import time

import requests
import json

end = datetime.datetime.utcnow()
start = end - datetime.timedelta(days=7)

API_URL = "https://api.intheloop.io/api/v1/report"
token = "Bearer eyJ..."
request = {
    "timezone": "Europe/Ljubljana",
    "start": round(start.timestamp()),
    "end": round(end.timestamp()),
    "resultFormat": "Json",
    "tagIds": [
    ],
    "teamIds": [
    ],
    "teammateIds": [
    ],
    "customerIds": [
    ]
}
headers = {
    "Authorization": token,
    "Content-Type": "application/json",
    "accept": "application/json",
    "User-Agent": "LocalLoopBot",
}


response = requests.post(f"{API_URL}/export", headers=headers, json=request)

response_id = json.loads(response.content.decode()).get("id")

response_data = {}
while True:
    get_response = requests.get(f"{API_URL}/exports/{response_id}", headers=headers)
    status_response = json.loads(get_response.content.decode())
    if status_response.get("status") in ["Completed", "Failed"]:
        if status_response.get("status") == "Failed":
            print("Export failed!")
            exit(1)
        
        data_url = response_data.get("url")
        break
    time.sleep(10) # wait 10 seconds

export_data = json.loads(
    requests.get(data_url).content.decode()
)

print(export_data[:10])
print("Done")

Last updated