Skip to content

Instantly share code, notes, and snippets.

@battis
Last active June 18, 2017 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/6e2c8224b2e59b6e41479b1d197d7a18 to your computer and use it in GitHub Desktop.
Save battis/6e2c8224b2e59b6e41479b1d197d7a18 to your computer and use it in GitHub Desktop.
Reset the favorite courses for all users in a subaccount in Canvas

Install

  1. Download both files (composer.json and reset-favorites-core.php) into the same directory.
  2. Use composer to install dependencies:
cd path/to/that/directory
composer install
  1. Edit the PHP script to contain your actual $API_URL, $API_TOKEN and $ACCOUNT_ID

Use

cd path/to/that/directory
php reset-favorites-core.php
{
"name": "battis/reset-favorites-core",
"description": "Reset the favorite courses for all users in a subaccount in Canvas",
"require": {
"smtech/canvaspest": "^1.0"
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
use smtech\CanvasPest\CanvasPest;
$API_URL = 'https://canvas.instructure.com/api/v1'; // your API url goes here
$API_TOKEN = 'hexaliciousgobbledygook'; // your API access token goes here (should be a super-admin, since you're masquerading)
$ACCOUNT_ID = '1'; // the Canvas ID of your particular account goes here
echo 'Starting';
$api = new CanvasPest($API_URL, $API_TOKEN);
$users = $api->get("accounts/{$ACCOUNT_ID}/users");
foreach ($users as $user) {
$api->delete(
'users/self/favorites/courses',
[
'as_user_id' => $user['id']
]
);
echo '.';
}
echo 'All done!' . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment