Skip to content

Instantly share code, notes, and snippets.

@misbach
Last active January 29, 2021 02:00
Show Gist options
  • Save misbach/585cbef74117737fad307e4238ed2cb2 to your computer and use it in GitHub Desktop.
Save misbach/585cbef74117737fad307e4238ed2cb2 to your computer and use it in GitHub Desktop.
Export Office 365 Org Chart
/*
Description:
Exports all people in an organization starting from a specified person.
To run:
1. Go to the People landing page in Office 365 and view a specific person
2. Change the starting person email, and UUID.
3. Paste the code below into the javascript console
Misc. Info
Get Managers
https://nam.delve.office.com/mt/v3/people/[email%40address]/core/managers
Direct Reports
https://nam.delve.office.com/mt/v3/people/[email%40address]/core/directs
Profile Page
https://nam.delve.office.com/?u=[UUID]&v=work
Related People
https://nam.delve.office.com/mt/v3/people/me/relatedpeople?top=50&flights=%27PulseWebExternalContent,PulseWebStoryCards,PulseWebVideoCards,DelveOnOLS,PulseWebFallbackCards,PulseWebContentTypesWave1,PulseWebContentTypeFilter%27&overrides=olsmodified,olsrelatedpeople,olsinfeed
Working With
https://nam.delve.office.com/mt/v3/people/[UUID]/workingwith?top=50&flights=%27PulseWebExternalContent,PulseWebStoryCards,PulseWebVideoCards,DelveOnOLS,PulseWebFallbackCards,PulseWebContentTypesWave1,PulseWebContentTypeFilter%27&overrides=olsmodified,olsrelatedpeople,olsinfeed
Example Person Record:
{
"FullName":"Bob Jones",
"Email":null,
"UserName":"Bob@Jones.org",
"JobTitle":"CTO",
"ProfileImageAddress":"/mt/v3/people/profileimage?userId=Bob%40Jones.org&size=L",
"AadObjectId":"5e723e15-ecdc-4a6f-6353-379a8c613663",
"ItemSource":"UserProfile"
}
*/
// Starting Person
getPerson("Bob@Jones.org", "5e723e15-ecdc-4a6f-6353-379a8c613663");
document.body.innerHTML = "";
function getPerson(email, id) {
let url = 'https://nam.delve.office.com/mt/v3/people/'+encodeURIComponent(email)+'/core/directs';
// Get person's direct reports
fetch(url, {credentials: 'same-origin'}).then(function(rsp) {
return rsp.json();
}).then(function(json){
json.d.forEach(function (person) {
if (person.JobTitle == "") return; // Interns, and duplicates
let info = person.FullName+"|"+person.UserName+"|"+person.JobTitle+"|https://nam.delve.office.com"+person.ProfileImageAddress+"|"+person.AadObjectId+"|"+id;
let node = document.createElement("li");
node.innerHTML=info;
document.getElementsByTagName("body")[0].appendChild(node);
getPerson(person.UserName, person.AadObjectId);
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment