Created
February 17, 2020 21:40
-
-
Save smarr/fa0ba54c0b33bca2285be35f1e5f6805 to your computer and use it in GitHub Desktop.
Delete All Tasks from Microsoft To Do app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@microsoft/microsoft-graph-client/lib/graph-js-sdk.js"></script> | |
<script type="text/javascript" src="https://alcdn.msauth.net/lib/1.2.0/js/msal.js"></script> | |
<script | |
src="https://code.jquery.com/jquery-3.4.1.min.js" | |
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" | |
crossorigin="anonymous"></script> | |
<script> | |
// Configuration options for MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL.js-1.0.0-api-release#configuration-options | |
const msalConfig = { | |
auth: { | |
clientId: "5110aa60-211e-41ff-836a-5592f931865d", // Client Id of the registered application | |
redirectUri: "https://stefan-marr.de/downloads/todotaskmng.html", | |
}, | |
}; | |
// const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes | |
const graphScopes = ["user.read", "tasks.read", "tasks.readwrite"]; | |
// Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal | |
// Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication | |
const msalApplication = new Msal.UserAgentApplication(msalConfig); | |
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions(graphScopes); | |
const authProvider = new MicrosoftGraph.ImplicitMSALAuthenticationProvider(msalApplication, options); | |
const Client = MicrosoftGraph.Client; | |
const client = Client.initWithMiddleware({ | |
authProvider | |
}); | |
let $tasks = null; | |
$(document).ready(() => { | |
$tasks = $("#tasks"); | |
main(); | |
}); | |
async function main() { | |
try { | |
let userDetails = await client.api("/me").get(); | |
let folders = await client.api('/me/outlook/taskFolders') | |
.version('beta') | |
.get(); | |
let mainFolderId = folders.value[0].id; | |
let done = false; | |
while (!done) { | |
let tasks = await client.api(`/me/outlook/taskFolders/${mainFolderId}/tasks`) | |
.version('beta') | |
.get(); | |
for (const t of tasks.value) { | |
$tasks.append(`<p>${t.subject}</p>`); | |
const p = await client.api(`/me/outlook/tasks/${t.id}`) | |
.version('beta') | |
.delete() | |
// debugger; | |
console.log(p); | |
} | |
} | |
} catch (error) { | |
throw error; | |
} | |
debugger; | |
} | |
</script> | |
</head> | |
<body> | |
<h1>ToDoTaskMng</h1> | |
<div id="tasks"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment