CSV Lists of New Reports - API and Python

  • 19 April 2024
  • 0 replies

Userlevel 6
Badge +2

We are a few years into using Docebo and we have experienced many changes to our organization in the last year. As a result, our New Reports has many reports that are no longer needed, are scheduled to be sent to users that are no longer with the company, or just outdated.

It is very time consuming to go into each report and get these details to determine if the report can be deleted.

I am not a developer. I have minimum skills with Python but I have learned that ChatGPT is VERY good at helping with Python. I used it to generate the script below.

I start with the endpoint Get / analytics/v1/reports which provides an output of all of the New Reports as JSON text that I copy and save as new.reports.json. The Pythong script takes that JSON file and creates a CSV (new.reports.csv) with the Name and Type of the reports in the first 2 columns and then the rest of the data in the following columns. 

import pandas as pd
import json

# Read the json data from the input file
with open('new.reports.json', 'r') as file:
data = json.load(file)

# Convert the json data to a pandas DataFrame
df = pd.json_normalize(data['data'])

# Reorder the columns, putting the 'name' column in the first position and the 'type' column in the second position
columns = list(df.columns)
columns = ['name', 'type'] + columns
df = df[columns]

# Write the DataFrame to a csv file
df.to_csv('new.reports.csv', index=False)

The result has been a big help in my clean up. It contains who created the report, when it was created, visibility, the recipient email addresses and more.

Hopefully this helps someone else close the gap on their administrative reporting needs.

0 replies

Be the first to reply!