Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / CreateListItemInAnotherSite.js
Created May 30, 2019 13:15
Create a ListItem in another site using the REST API
(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 {
POST https://platinumdogsconsulting.sharepoint.com/sites/hubsitetest/_api/site/GetCopyJobProgress
HEADERS
{
Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose
X-RequestDigest: <<site form digest>>
}
BODY
{
"copyJobInfo": {
References:
- https://gist.github.com/zplume/9f4c1a658517802701deff3473f23a60
- https://gist.github.com/zplume/21248c3a8a5f840a366722442cf9ee97
- https://blog.velingeorgiev.com/createcopyjobs-api-copy-move-SharePoint-files-folders
- See also: https://gist.github.com/zplume/9f4c1a658517802701deff3473f23a60
"NameConflictBehavior":0 = Fail
"NameConflictBehavior":1 = Replace
"NameConflictBehavior":2 = Rename at destination (Keep Both)
Based on similar bejaviour at: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0
(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 March 19, 2019 00:46
Creates an Azure AD Application Registration with Client Secret using the Azure CLI
param (
[string]$tenantId,
[string]$userName,
[string]$userPassword,
[string]$subscriptionId,
[switch]$production,
[switch]$quiet
)
## Connecting to site
Clear-Host
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/
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:authorization_code
code:{authorisation code}
redirect_uri:{redirect_uri}
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:refresh_token
refresh_token:{refresh_token_value}
resource:https://graph.microsoft.com/
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:password
resource:https://graph.microsoft.com/
username:{user upn}
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:the client id
client_secret:the client secret
grant_type:client_credentials
resource:https://graph.microsoft.com/