Skip to content

Instantly share code, notes, and snippets.

Phil Harding phillipharding

Block or report user

Report or block phillipharding

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@phillipharding
phillipharding / Get O365 Groups using AdalJS and Graph on Classic SP Page.js
Last active Oct 10, 2019
Get Office 365 Groups and Current User Profile using the Graph API and AdalJS to acquire access tokens
View Get O365 Groups using AdalJS and Graph on Classic SP Page.js
console.clear();
/* Logging levels
0: Error
1: Warning
2: Info
3: Verbose
*/
(function() {
/* LOAD ADAL.JS onto the page
@phillipharding
phillipharding / Get Compliance Tags Available for a Site Collection
Created Jul 17, 2019
Returns the Office 365 Compliance Tags which have been published to a site collection
View Get Compliance Tags Available for a Site Collection
POST https://tenant.sharepoint.com/sites/siteurl/_vti_bin/client.svc/ProcessQuery HTTP/1.1
X-RequestDigest: {digest}
Content-Type: text/xml
<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
<Actions>
<StaticMethod TypeId="{9efa17eb-0d34-4f69-a085-5cc3f802439e}" Name="GetAvailableTagsForSite" Id="22">
<Parameters>
<Parameter Type="String">https://tenant.sharepoint.com/sites/siteurl</Parameter>
</Parameters>
@phillipharding
phillipharding / Get Term By Id from Group and Termset by Name
Created Jun 10, 2019
Get a Term by its ID with LocalCustomProperties from a Termgroup and Termstore by Name
View Get Term By Id from Group and Termset by Name
POST https://platinumdogsconsulting.sharepoint.com/teams/PKC_EDMS_Discovery/_vti_bin/client.svc/ProcessQuery
Content-Type: text/xml
X-RequestDigest:
User-Agent:
Host:
<Request AddExpandoFieldTypeSuffix="true" ApplicationName=".NET Library" LibraryVersion="16.0.0.0" SchemaVersion="15.0.0.0" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
<Actions>
<ObjectPath Id="48" ObjectPathId="47"/>
<ObjectIdentityQuery Id="49" ObjectPathId="47"/>
@phillipharding
phillipharding / CreateListItemInAnotherSite.js
Created May 30, 2019
Create a ListItem in another site using the REST API
View CreateListItemInAnotherSite.js
(async function() {
function getFailedResponseData(response) {
return new Promise( async (resolve) => {
const ct = response.headers.get("Content-Type") || "";
let data = {};
if (ct.match("application/json")) {
data = await response.json();
} else {
View GetCopyJobProgress - Polling Response Finishes when "JobState" = 0
POST https://platinumdogsconsulting.sharepoint.com/sites/hubsitetest/_api/site/GetCopyJobProgress
HEADERS
{
accept: application/json;odata=verbose
content-type: application/json; odata=verbose
}
BODY
{
"copyJobInfo": {
"EncryptionKey": "6YIOwbP9/TSLiw6D0H+mvsiRbgjSvJLs5L28Pfx/0BQ=",
View CreateCopyJobs - Move Folder using SharePoint REST API
References:
- https://gist.github.com/zplume/9f4c1a658517802701deff3473f23a60
- https://gist.github.com/zplume/21248c3a8a5f840a366722442cf9ee97
"NameConflictBehavior":0 = think means fail
"NameConflictBehavior":1 = think means replace
"NameConflictBehavior":2 = Rename at destination
Based on similar bejaviour at: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0
"IsMoveMode":true|false = if true the source folder is removed, otherwise it remains (copy)
View Get O365 Groups using Graph on Classic SP Page.js
(async function() {
function getAccessToken(resource) {
return new Promise( async (resolve, reject) => {
var body = {
"resource": resource || "https://graph.microsoft.com"
};
const url = `${_spPageContextInfo.webAbsoluteUrl}/_api/SP.OAuth.Token/Acquire`;
const response = await fetch(url, {
@phillipharding
phillipharding / Create Azure AD App Registration.ps1
Created Mar 19, 2019
Creates an Azure AD Application Registration with Client Secret using the Azure CLI
View Create Azure AD App Registration.ps1
param (
[string]$tenantId,
[string]$userName,
[string]$userPassword,
[string]$subscriptionId,
[switch]$production,
[switch]$quiet
)
## Connecting to site
Clear-Host
View AzureAD v1.0 On-Behalf-Of Grant
POST /{tenant id}/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
client_id:{client id}
client_secret:{client secret}
grant_type:urn:ietf:params:oauth:grant-type:jwt-bearer
assertion:{access_token_value}
resource:https://graph.microsoft.com/
You can’t perform that action at this time.