Bulk Update or Reassign Schedules

Hi all,

One common request we get is how to bulk update or reassign schedules. A common use case for this is when users leave the company. First and foremost, do not delete the user before updating the schedules as the schedules and any information on them will be lost.

Generally, we recommend using the API for mass changes in schedules. I’ve written a template below on how to do a bulk re-assign of schedules using the Looker python SDK, but feel free to adjust it in any way to fit your use case. Please read through the commented notes!

import json

import looker_sdk
from looker_sdk import models

# Note that this is assuming we've downloaded the Looker python sdk and that we've set up the ini file in the same folder as this program
# Please refer to https://github.com/looker-open-source/sdk-codegen/tree/main/python for how to download the sdk and create the ini file
sdk = looker_sdk.init31("looker.ini")

# First create a Look that contains a list of scheduled plans & their cron tab that need to be updated from System Activity
# Replace the look_id in the call below
scheduled_plans = sdk.run_look(look_id=11275, result_format='json')
scheduled_plans = json.loads(scheduled_plans)

# Iterates through all the schedules in the list
# replace user_id here with the new user id
for i in scheduled_plans:
json_query = {
"user_id": 1430,
"crontab": i['scheduled_plan.cron_schedule']
}
body = json.dumps(json_query)
sdk.update_scheduled_plan(i['scheduled_plan.id'], body)

Hope this helps out! Any comments or recommendations on making the code better are always welcome!

Cheers,

Annie

Looker DCL 

0 1 2,082