Management
Remove all schedules from report
You can use the Mode API to remove all schedules from a specific report. If there are reports from former members or the report has been deprecated, this script will assist with removing all scheduled runs.
Endpoints used
.../{workspace}/reports/{report_token}/schedules\
Supported methods:
- GET: returns all schedules attributed to a report
 
.../{workspace}/reports/{report_token}/schedules/{schedule_token}\
Supported methods:
- DELETE: deletes the specific schedule
 
How this example works
In this example, the get_report_schedules method makes a GET request to return a list of all active report schedules for a specific report. Once the list is compiled, it will then delete each schedule using the delete_schedule method to remove the schedule.
To try it yourself
- Input the API token, API secret, Workspace name, and other custom information as needed. Follow these steps to create an API token.
 - Save the file in your desired directory
 - Open the terminal and navigate to that directory
 - Run the command 
python3 {file_name}.pyfor python or Node/Express to run the JS library 
import json
import requests
from requests.auth import HTTPBasicAuth
host = 'https://app.mode.com'
ws = 'workspace_name' # Note: workspace_name value should be all lowercase
un = 'api_token'
pw = 'api_secret'
def get_report_schedules(report_token):
  url = '%s/api/%s/reports/%s/schedules' % (host, ws, report_token)
  headers = {'Content-Type': 'application/json'}
  r = requests.get(url, headers=headers, auth=HTTPBasicAuth(un,pw))
  schedules_object = r.json()['_embedded']['report_schedules']
  report_schedules = []
  for s in schedules_object:
    report_schedules.append(s['token'])
  return report_schedules
def remove_schedule(report_token,schedule_token):
  url = '%s/api/%s/reports/%s/schedules/%s' % (host, ws, report_token,schedule_token)
  headers = {'Content-Type': 'application/json'}
  r = requests.delete(url, headers=headers, auth=HTTPBasicAuth(un,pw))
  print ('Schedule Token:%s has been deleted' % (schedule_token))
def delete_report_schedules(report_token):
  report_schedules = get_report_schedules(report_token)
  for s in report_schedules:
    remove_schedule(report_token,s)
delete_report_schedules('report_token')
const request = require('request-promise');
const host = 'https://app.mode.com';
const ws = 'workspace_name'; // Note: workspace_name value should be all lowercase
const username = 'api_token';
const password = 'api_secret';
const getReportSchedules = async reportToken => {
  let reportSchedules = await request({
   method: 'GET',
   url: `${host}/api/${ws}/reports/${reportToken}/schedules`,
   auth: { username, password },
   json: true  });
  reportSchedules._embedded.report_schedules.forEach((s)=>{
    console.log(s.token,reportToken)
    console.log(deleteSchedule(reportToken,s.token));
  })
};
const deleteSchedule = (reportToken,scheduleToken)=>{
 let status;
 let result = request({
   method: 'DELETE',
   url: `${host}/api/${ws}/reports/${reportToken}/schedules/${scheduleToken}`,
   auth: { username, password },
   json: true,
   resolveWithFullResponse: true
  })
  return result
};
getReportSchedules('reportToken')