Management

Rename Report

Similar to the “Move a report” example, this example shows how to update a report title using the API. You can use this code to bulk update report titles. For example, you may need to do this when you clone a report used for a White-Label Embed and make some edits or updates to the cloned version. In this case, you can change the report title and move it back to a production Space using the API.

Endpoints used

.../{organization}/reports/{report_token}
Supported methods:

  • GET: returns a report
  • POST: creates a new report run
  • PATCH: changes report’s Space, description, title, or layout

How this example works

In this example, the update_report_title method first makes a GET request to app.mode.com/api/{organization}/reports/{report_token}. This request returns information about a report (title, description, layout, etc.), which are used in the payload of a PATCH request to the same endpoint later in the method. You can use this same method to update other report elements, such as its description or layout.

To try it yourself

  • Download the example code to a .py file
  • Input the API token, API secret, organization name, and other custom information as needed. An API token and secret can be generated here
  • Save the .py file in your desired directory
  • Open the terminal and navigate to that directory
  • Run the command python3 {file_name}.py
  • All of our Python recipes require Python 3
import json
import requests

from requests.auth import HTTPBasicAuth


host = 'https://modeanalytics.com'
org = 'org_name'
un = 'api_token'
pw = 'api_secret'


def update_report_title(report_token, report_name):
  url = '%s/api/%s/reports/%s' % (host, org, report_token)
  headers = {'Content-Type': 'application/json'}
  r = requests.get(url, auth=HTTPBasicAuth(un, pw))
  result = r.json()
  layout = result['layout']
  account_id = result['account_id']
  desc = result['description']
  published = result['_forms']['edit']['input']['report']['published']['value']
  payload = {'report':{'name':report_name,'layout':layout,'description':desc,'account_id':account_id,'published':published}}
  result = requests.patch(url, auth=HTTPBasicAuth(un, pw), json=payload, headers=headers)
  return result

update_report_title('report_token', 'new_report_title')
const request = require('request-promise');

const host = 'https://modeanalytics.com';
const org = 'orgName';
const username = 'apiToken';
const password = 'apiSecret';

const updateReportTitle = async (reportToken, reportName) => {
  const url = `${host}/api/${org}/reports/${reportToken}`;
  const report = await request({
      url,
      auth: { username, password },
      json: true,
    });

  const {
    layout,
    account_id,
    description,
    _forms,
  } = report;

  const published = _forms.edit.input.report.published.value;
  const payload = {
    report: {
      name: reportName,
      layout,
      description,
      account_id,
      published,
    },
  };

  return await request({
    url,
    method: 'PATCH',
    auth: { username, password },
    json: true,
    body: payload,
  });
};

updateReportTitle('reportToken', 'reportName');