SlideShare a Scribd company logo
SharePoint Conference 2018 - APIs, APIs everywhere!
APIs, APIs Everywhere!
Sébastien Levert
Hi! I’m Seb!
@sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at
Agenda
Agenda
SharePoint REST APIs
Our Scenario
• Building a SharePoint Framework webpart that connects to a
SharePoint list to play with its data
• Using a single Interface to define our Data Access services to enable
easy on-the-fly switch of data sources
• Mocking Service for swapping and localWorkbench development
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { IHelpDeskItem } from "./../models/IHelpDeskItem";
import { WebPartContext } from "@microsoft/sp-webpart-base";
export default interface IDataService {
getTitle(): string;
isConfigured(): boolean;
getItems(context: WebPartContext): Promise<IHelpDeskItem[]>;
addItem(context: WebPartContext, item: IHelpDeskItem): Promise<void>;
updateItem(context: WebPartContext, item: IHelpDeskItem): Promise<void>;
deleteItem(context: WebPartContext, item: IHelpDeskItem): Promise<void>;
}
export default class SharePointDataService implements IDataService {
//…
}
Data Service Architecture
Using the SharePoint REST APIs?
• Enable almost all your CRUD scenarios in the solutions you are
building on SharePoint Online and SharePoint On-Premises
• When called from a SharePoint context, no authentication required
as it’s all cookie based
• It follows the OData standards, making it easy to query your content
OData URI at a glance
OData URI at a glance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Creating a new SPFx Project
yo @Microsoft/sharepoint --skip-install
# Installing all dependencies
npm install
# Opening the newly created project
code .
Creating a new SPFx Project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Getting all the sessions of the specified list using SharePoint REST APIs
public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> {
return new Promise<IHelpDeskItem[]>((resolve, reject) => {
context.spHttpClient.get(
`${absoluteUrl}/_api/web/lists/GetById('${this._listId}')/items` +
`?$select=*,HelpDeskAssignedTo/Title&$expand=HelpDeskAssignedTo`,
SPHttpClient.configurations.v1)
.then(res => res.json())
.then(res => {
let helpDeskItems:IHelpDeskItem[] = [];
for(let helpDeskListItem of res.value) {
helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem));
}
resolve(helpDeskItems);
}).catch(err => console.log(err));
});
}
Retrieving Data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Creating a new session in the specified list
public addItem(item: IHelpDeskItem): Promise<void> {
return new Promise<void>((resolve, reject) => {
//…
return this._webPartContext.spHttpClient.post(
`${currentWebUrl}/_api/web/lists/GetById('${this._listId}')/items`,
SPHttpClient.configurations.v1, {
headers: { "Accept": "application/json;odata=nometadata",
"Content-type": "application/json;odata=verbose",
"odata-version": "" },
body: body
});
}).then((response: SPHttpClientResponse): Promise<any> => {
return response.json();
}).then((item: any): void => {
resolve();
});
});
}
Creating Data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Deleting a specific item from the specified list
public deleteItem(id: number): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (!window.confirm(`Are you sure?`)) { return; }
return this._webPartContext.spHttpClient.post(
`${currentWebUrl}/_api/web/lists/GetById('${this._listId}')/items(${id})`,
SPHttpClient.configurations.v1, {
headers: { "Accept": "application/json;odata=nometadata",
"Content-type": "application/json;odata=verbose",
"odata-version": "",
"IF-MATCH": "*",
"X-HTTP-Method": "DELETE" }
}).then((response: SPHttpClientResponse): void => {
resolve();
});
});
}
Deleting Data
Using SharePoint Search
• Using search allows you to query content in multiple lists or multiple
sites or site collections
• Uses a totally other query language (KQL or Keyword Query
Language)
• Very performant and optimized for fetching a lot of data, but has a 15
minutes-ish delay in terms of data freshness
• Does not support any data modification
KQL Crash Course
• See Mickael Svenson blog series “SharePoint Search Queries
Explained”
• https://www.techmikael.com/2014/03/sharepoint-search-queries-
explained.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Getting all the sessions of the specified list using SharePoint Search
public getItems(context: IWebPartContext): Promise<IHelpDeskItem[]> {
return new Promise<IHelpDeskItem[]>((resolve, reject) => {
context.spHttpClient.get(`${absoluteUrl}/_api/search/query?` +
`querytext='ContentTypeId:0x0100…* AND ListID:${this._listId}'` +
`&selectproperties='…'` +
`&orderby='ListItemID asc'`, SPHttpClient.configurations.v1, {
headers: { "odata-version": "3.0" }
}).then(res => res.json()).then(res => {
let helpDeskItems:IHelpDeskItem[] = [];
if(res.PrimaryQueryResult) {
for(var row of res.PrimaryQueryResult.RelevantResults.Table.Rows) {
helpDeskItems.push(this.buildHelpDeskItem(row));
}
}
resolve(helpDeskItems);
});
}
Retrieving Data
Notes on legacy APIs support
• SharePoint APIs cover a wide-range of options, but not everything
• You “might” have to revert to JSOM for some scenarios (Managed
Metadata, etc.)
• Or even to the ASMXWeb Services for more specific scenarios
(Recurring Events in Calendars, etc.)
• The SharePoint Framework supports those scenarios, but will require
some extra work
Microsoft Graph and Custom APIs
What is the Microsoft Graph?
Groups
People
Conversations
Insights
Microsoft Graph is all about you
If you or your customers are part of the millions of users that are using Microsoft
cloud services, then Microsoft Graph is the fabric of all your data
It all starts with /me
Gateway to your data in the Microsoft
cloud
Your app
Gateway
Your or your
customer’s
data
Office 365 Windows 10 Enterprise Mobility + Security
1Microsoft Graph
Microsoft Graph
ALL
Microsoft 365
Office 365
Windows 10
EMS
ALL ONE
https://graph.microsoft.com
Microsoft 365 Platform
web, device,
and service apps
Extend Microsoft 365 experiences
1
iOS/Android/Windows/Web
Build your experience
Microsoft Graph
Options for the Microsoft Graph
• Using the built-in MsGraphClient class that takes care of the entire
authentication flow and token management for you
• Using a custom implementation using ADAL or MSAL
Are there any limitations?
• Every scope will have to be defined beforehand and could open some
security challenges
• Authentication challenges could bring a broken experience to your
users depending on the platform and browser used
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// In your package-solution.json
{
// …
"webApiPermissionRequests": [
{
"resource": "Microsoft Graph",
"scope": "Sites.ReadWrite.All"
},
// …
]
// …
}
Enabling Graph in your solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Getting all the sessions of the specified list using the Microsoft Graph
public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> {
let graphUrl: string = `https://graph.microsoft.com/v1.0` +
`/sites/${this.getCurrentSiteCollectionGraphId()}` +
`/lists/${this._listId}` +
`/items?expand=fields(${this.getFieldsToExpand()})`;
return new Promise<IHelpDeskItem[]>((resolve, reject) => {
this._client.api(graphUrl).get((error, response: any) => {
let helpDeskItems:IHelpDeskItem[] = [];
for(let helpDeskListItem of response.value) {
helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem));
}
resolve(helpDeskItems);
});
});
}
Retrieving Data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Creating a new item in the specified list
public addItem(item: IHelpDeskItem): Promise<void> {
let graphUrl: string = `https://graph.microsoft.com/v1.0` +
`/sites/${this.getCurrentSiteCollectionGraphId()}` +
`/lists/${this._listId}` +
`/items`;
return new Promise<void>((resolve, reject) => {
const body: any = { "fields" : {
"Title": item.title,
"HelpDeskDescription": item.description,
"HelpDeskLevel": item.level
}};
this._client.api(graphUrl).post(body, (error, response: any) => {
resolve();
});
});
}
Creating Data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Deleting the specified item form the specified list
public deleteItem(id: number): Promise<void> {
let graphUrl: string = `https://graph.microsoft.com/v1.0` +
`/sites/${this.getCurrentSiteCollectionGraphId()}` +
`/lists/${this._listId}` +
`/items/${id}`;
return new Promise<void>((resolve, reject) => {
this._client.api(graphUrl).delete((error, response: any) => {
resolve();
});
});
}
Deleting Data
Custom APIs
• Using the built-in AadGraphClient class that takes care of the entire
authentication flow and token management for you
• Using a custom implementation using ADAL or MSAL
• You can use user impersonation (or not) to query SharePoint content
based on user permissions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Getting all the sessions of the specified list using the AAD Client
public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> {
return new Promise<IHelpDeskItem[]>((resolve, reject) => {
let apiUrl: string = "<url>/api/GetHelpDeskItems";
this._client
.get(apiUrl, AadHttpClient.configurations.v1)
.then((res: HttpClientResponse): Promise<any> => {
return res.json();
}).then((res: any): void => {
let helpDeskItems:IHelpDeskItem[] = [];
for(let helpDeskListItem of res) {
helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem));
}
resolve(helpDeskItems);
});
});
}
}
Retrieving Data
Patterns & Practices JS Core
What is PnP JS Core?
PnPJS is a fluent JavaScript API for consuming SharePoint and Office 365
REST APIs in a type-safe way.You can use it with SharePoint Framework,
Nodejs, or JavaScript projects.This an open source initiative that
complements existing SDKs provided by Microsoft offering developers
another way to consume information from SharePoint and Office 365.
https://github.com/pnp/pnpjs
Benefits of PnP JS Core
• Type safe so you get your errors while you code and not when you
execute and test
• Works on all versions of SharePoint (On-Premises, Online, etc.)
• Offers built-in caching mechanisms
• Heavily used in the SharePoint Development Community
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { sp } from "@pnp/sp";
// ...
public onInit(): Promise<void> {
return super.onInit().then(_ => {
// other init code may be present
sp.setup({
spfxContext: this.context
});
});
}
// ...
Sample – Setup PnP JS for SharePoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Getting all the sessions of the specified list using PnP JS Core
public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> {
return new Promise<IHelpDeskItem[]>((resolve, reject) => {
sp.web.lists.getById(this._listId).items
.select("*", "HelpDeskAssignedTo/Title")
.expand("HelpDeskAssignedTo").getAll().then((sessionItems: any[]) => {
let helpDeskItems:IHelpDeskItem[] = [];
for(let helpDeskListItem of sessionItems) {
helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem));
}
resolve(helpDeskItems);
});
});
}
Retrieving Data
Next Steps
Resources
• https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-
parts/guidance/connect-to-sharepoint-using-jsom
• https://www.techmikael.com/2014/03/sharepoint-search-queries-
explained.html
• https://github.com/pnp/pnpjs
• https://github.com/sebastienlevert/apis-apis-everywhere
Share your experience
• Use hashtags to share your experience
• #Office365Dev
• #MicrosoftGraph
• #SPFx
• Log issues & questions to the GitHub Repositories
Thanks!
@sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at

More Related Content

PPTX
APIs, APIs Everywhere!
BIWUG
 
PDF
Hidden Docs in Angular
Yadong Xie
 
PPTX
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Ali Parmaksiz
 
PPTX
10 wp7 local database
Tao Wang
 
PDF
Angular 2 introduction
Christoffer Noring
 
PDF
Nativescript angular
Christoffer Noring
 
PPTX
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
David Wengier
 
PPTX
A (very) opinionated guide to MSBuild and Project Files
David Wengier
 
APIs, APIs Everywhere!
BIWUG
 
Hidden Docs in Angular
Yadong Xie
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Ali Parmaksiz
 
10 wp7 local database
Tao Wang
 
Angular 2 introduction
Christoffer Noring
 
Nativescript angular
Christoffer Noring
 
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
David Wengier
 
A (very) opinionated guide to MSBuild and Project Files
David Wengier
 

What's hot (20)

PDF
Android DevConference - Android Clean Architecture
iMasters
 
PPTX
Converting Your Mobile App to the Mobile Cloud
Roger Brinkley
 
PPTX
Mobile for SharePoint with Windows Phone
Edgewater
 
PPTX
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
goodfriday
 
PDF
Creating lightweight JS Apps w/ Web Components and lit-html
Ilia Idakiev
 
PDF
React lecture
Christoffer Noring
 
PDF
Vaadin7
Joonas Lehtinen
 
PPTX
Data Access Options in SharePoint 2010
Rob Windsor
 
PPTX
Firebase ng2 zurich
Christoffer Noring
 
PPT
Active x
Karthick Suresh
 
PPTX
Angular mix chrisnoring
Christoffer Noring
 
PDF
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
PDF
Engage 2013 - Why Upgrade to v10 Tag
Webtrends
 
PDF
Server side data sync for mobile apps with silex
Michele Orselli
 
PDF
Implementing data sync apis for mibile apps @cloudconf
Michele Orselli
 
PDF
Practical
rajesh samata
 
PPTX
Reactive programming every day
Vadym Khondar
 
PPTX
Grails Advanced
Saurabh Dixit
 
PPT
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
Daniel Fisher
 
PDF
AtlasCamp 2015: Web technologies you should be using now
Atlassian
 
Android DevConference - Android Clean Architecture
iMasters
 
Converting Your Mobile App to the Mobile Cloud
Roger Brinkley
 
Mobile for SharePoint with Windows Phone
Edgewater
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
goodfriday
 
Creating lightweight JS Apps w/ Web Components and lit-html
Ilia Idakiev
 
React lecture
Christoffer Noring
 
Data Access Options in SharePoint 2010
Rob Windsor
 
Firebase ng2 zurich
Christoffer Noring
 
Active x
Karthick Suresh
 
Angular mix chrisnoring
Christoffer Noring
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
Engage 2013 - Why Upgrade to v10 Tag
Webtrends
 
Server side data sync for mobile apps with silex
Michele Orselli
 
Implementing data sync apis for mibile apps @cloudconf
Michele Orselli
 
Practical
rajesh samata
 
Reactive programming every day
Vadym Khondar
 
Grails Advanced
Saurabh Dixit
 
2005 - .NET Chaostage: 1st class data driven applications with ASP.NET 2.0
Daniel Fisher
 
AtlasCamp 2015: Web technologies you should be using now
Atlassian
 
Ad

Similar to SharePoint Conference 2018 - APIs, APIs everywhere! (20)

PPTX
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
Sébastien Levert
 
PPTX
harePoint Framework Webinar Series: Consume Graph APIs in SharePoint Framework
Jenkins NS
 
PPTX
SPFx Webinar Loading SharePoint data in a SPFx Webpart
Jenkins NS
 
PDF
SharePoint goes Microsoft Graph
Markus Moeller
 
PPTX
SharePoint Saturday Chicago - Everything your need to know about the Microsof...
Sébastien Levert
 
PPTX
#SPSToronto The SharePoint Framework and the Microsoft Graph on steroids with...
Vincent Biret
 
PPTX
Working with a super model for SharePoint Tuga IT 2016
Sonja Madsen
 
PPTX
Create the Modern Workplace with the SharePoint Framework
SharePoint Patterns and Practices
 
PPTX
#SPSottawa The SharePoint Framework and The Microsoft Graph on steroids with ...
Vincent Biret
 
PPTX
SPS Utah - Everything your need to know about the Microsoft Graph as a ShareP...
Sébastien Levert
 
PPTX
Granite state #spug The #microsoftGraph and #SPFx on steroids with #AzureFunc...
Vincent Biret
 
PPTX
SharePoint Saturday Vienna Slides
David Opdendries
 
PPTX
Sps mad2018 joel rodrigues - pn-p reusable controls and pnpjs
Joel Rodrigues
 
PDF
Xamarin microsoft graph
Nicolò Carandini
 
PDF
Office Add-in & Microsoft Graph - Development 101
Hongbo Miao
 
PPTX
ATD 13 - Enhancing your applications using Microsoft Graph API
Dragan Panjkov
 
PPTX
SharePoint Fest Seattle 2017 - Everything your need to know about the Microso...
Sébastien Levert
 
PPTX
The happy developer - SharePoint Framework React and Mindfulness
Olli Jääskeläinen
 
PPTX
SharePoint Fest DC 2018 - Everything your need to know about the Microsoft Gr...
Sébastien Levert
 
PPTX
SharePoint Fest DC - Everything your need to know about the Microsoft Graph a...
Sébastien Levert
 
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
Sébastien Levert
 
harePoint Framework Webinar Series: Consume Graph APIs in SharePoint Framework
Jenkins NS
 
SPFx Webinar Loading SharePoint data in a SPFx Webpart
Jenkins NS
 
SharePoint goes Microsoft Graph
Markus Moeller
 
SharePoint Saturday Chicago - Everything your need to know about the Microsof...
Sébastien Levert
 
#SPSToronto The SharePoint Framework and the Microsoft Graph on steroids with...
Vincent Biret
 
Working with a super model for SharePoint Tuga IT 2016
Sonja Madsen
 
Create the Modern Workplace with the SharePoint Framework
SharePoint Patterns and Practices
 
#SPSottawa The SharePoint Framework and The Microsoft Graph on steroids with ...
Vincent Biret
 
SPS Utah - Everything your need to know about the Microsoft Graph as a ShareP...
Sébastien Levert
 
Granite state #spug The #microsoftGraph and #SPFx on steroids with #AzureFunc...
Vincent Biret
 
SharePoint Saturday Vienna Slides
David Opdendries
 
Sps mad2018 joel rodrigues - pn-p reusable controls and pnpjs
Joel Rodrigues
 
Xamarin microsoft graph
Nicolò Carandini
 
Office Add-in & Microsoft Graph - Development 101
Hongbo Miao
 
ATD 13 - Enhancing your applications using Microsoft Graph API
Dragan Panjkov
 
SharePoint Fest Seattle 2017 - Everything your need to know about the Microso...
Sébastien Levert
 
The happy developer - SharePoint Framework React and Mindfulness
Olli Jääskeläinen
 
SharePoint Fest DC 2018 - Everything your need to know about the Microsoft Gr...
Sébastien Levert
 
SharePoint Fest DC - Everything your need to know about the Microsoft Graph a...
Sébastien Levert
 
Ad

More from Sébastien Levert (20)

PPTX
SharePoint Fest Chicago 2019 - Build a Full Intranet in 70 minutes
Sébastien Levert
 
PPTX
SharePoint Fest Chicago 2019 - Building tailored search experiences in Modern...
Sébastien Levert
 
PPTX
SharePoint Fest Chicago 2019 - From SharePoint to Office 365 Development
Sébastien Levert
 
PPTX
ESPC19 - Supercharge Your Teams Experience with Advanced Development Techniques
Sébastien Levert
 
PPTX
ESPC19 - Build Your First Microsoft Teams App Using SPFx
Sébastien Levert
 
PPTX
SharePoint Fest Seattle 2019 - From SharePoint to Office 365 Development
Sébastien Levert
 
PPTX
SharePoint Fest Seattle 2019 - Building tailored search experiences in Modern...
Sébastien Levert
 
PPTX
SPC19 - Building tailored search experiences in Modern SharePoint
Sébastien Levert
 
PPTX
SharePoint Fest 2019 - Build an intelligent application by connecting it to t...
Sébastien Levert
 
PPTX
SharePoint Fest DC 2019 - Bot Framework and Microsoft Graph - Join The Revolu...
Sébastien Levert
 
PPTX
SharePoint Fest DC 2019 - From SharePoint to Office 365 Development
Sébastien Levert
 
PPTX
Webinar - 2020-03-24 - Build your first Microsoft Teams app using SPFx
Sébastien Levert
 
PPTX
SPTechCon Austin 2019 - Top 10 feature trends to make you fall in love with y...
Sébastien Levert
 
PPTX
SPTechCon Austin 2019 - From SharePoint to Office 365 development
Sébastien Levert
 
PPTX
SharePoint Fest Chicago 2018 - From SharePoint to Office 365 development
Sébastien Levert
 
PPTX
SharePoint Saturday Vienna 2018 - Top 10 feature trends to make you fall in l...
Sébastien Levert
 
PPTX
SharePoint Saturday Vienna 2018 - Building a modern intranet in 60 minutes
Sébastien Levert
 
PPTX
European SharePoint Conference 2018 - Build an intelligent application by con...
Sébastien Levert
 
PPTX
Nashville SharePoint User Group 2018 - Building a modern intranet in 60 minutes
Sébastien Levert
 
PPTX
SharePoint Fest Seattle 2018 - Build an intelligent application by connecting...
Sébastien Levert
 
SharePoint Fest Chicago 2019 - Build a Full Intranet in 70 minutes
Sébastien Levert
 
SharePoint Fest Chicago 2019 - Building tailored search experiences in Modern...
Sébastien Levert
 
SharePoint Fest Chicago 2019 - From SharePoint to Office 365 Development
Sébastien Levert
 
ESPC19 - Supercharge Your Teams Experience with Advanced Development Techniques
Sébastien Levert
 
ESPC19 - Build Your First Microsoft Teams App Using SPFx
Sébastien Levert
 
SharePoint Fest Seattle 2019 - From SharePoint to Office 365 Development
Sébastien Levert
 
SharePoint Fest Seattle 2019 - Building tailored search experiences in Modern...
Sébastien Levert
 
SPC19 - Building tailored search experiences in Modern SharePoint
Sébastien Levert
 
SharePoint Fest 2019 - Build an intelligent application by connecting it to t...
Sébastien Levert
 
SharePoint Fest DC 2019 - Bot Framework and Microsoft Graph - Join The Revolu...
Sébastien Levert
 
SharePoint Fest DC 2019 - From SharePoint to Office 365 Development
Sébastien Levert
 
Webinar - 2020-03-24 - Build your first Microsoft Teams app using SPFx
Sébastien Levert
 
SPTechCon Austin 2019 - Top 10 feature trends to make you fall in love with y...
Sébastien Levert
 
SPTechCon Austin 2019 - From SharePoint to Office 365 development
Sébastien Levert
 
SharePoint Fest Chicago 2018 - From SharePoint to Office 365 development
Sébastien Levert
 
SharePoint Saturday Vienna 2018 - Top 10 feature trends to make you fall in l...
Sébastien Levert
 
SharePoint Saturday Vienna 2018 - Building a modern intranet in 60 minutes
Sébastien Levert
 
European SharePoint Conference 2018 - Build an intelligent application by con...
Sébastien Levert
 
Nashville SharePoint User Group 2018 - Building a modern intranet in 60 minutes
Sébastien Levert
 
SharePoint Fest Seattle 2018 - Build an intelligent application by connecting...
Sébastien Levert
 

Recently uploaded (20)

PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Doc9.....................................
SofiaCollazos
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 

SharePoint Conference 2018 - APIs, APIs everywhere!

  • 3. Hi! I’m Seb! @sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at
  • 7. Our Scenario • Building a SharePoint Framework webpart that connects to a SharePoint list to play with its data • Using a single Interface to define our Data Access services to enable easy on-the-fly switch of data sources • Mocking Service for swapping and localWorkbench development
  • 8. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import { IHelpDeskItem } from "./../models/IHelpDeskItem"; import { WebPartContext } from "@microsoft/sp-webpart-base"; export default interface IDataService { getTitle(): string; isConfigured(): boolean; getItems(context: WebPartContext): Promise<IHelpDeskItem[]>; addItem(context: WebPartContext, item: IHelpDeskItem): Promise<void>; updateItem(context: WebPartContext, item: IHelpDeskItem): Promise<void>; deleteItem(context: WebPartContext, item: IHelpDeskItem): Promise<void>; } export default class SharePointDataService implements IDataService { //… } Data Service Architecture
  • 9. Using the SharePoint REST APIs? • Enable almost all your CRUD scenarios in the solutions you are building on SharePoint Online and SharePoint On-Premises • When called from a SharePoint context, no authentication required as it’s all cookie based • It follows the OData standards, making it easy to query your content
  • 10. OData URI at a glance
  • 11. OData URI at a glance
  • 12. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # Creating a new SPFx Project yo @Microsoft/sharepoint --skip-install # Installing all dependencies npm install # Opening the newly created project code . Creating a new SPFx Project
  • 13. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Getting all the sessions of the specified list using SharePoint REST APIs public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> { return new Promise<IHelpDeskItem[]>((resolve, reject) => { context.spHttpClient.get( `${absoluteUrl}/_api/web/lists/GetById('${this._listId}')/items` + `?$select=*,HelpDeskAssignedTo/Title&$expand=HelpDeskAssignedTo`, SPHttpClient.configurations.v1) .then(res => res.json()) .then(res => { let helpDeskItems:IHelpDeskItem[] = []; for(let helpDeskListItem of res.value) { helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem)); } resolve(helpDeskItems); }).catch(err => console.log(err)); }); } Retrieving Data
  • 14. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Creating a new session in the specified list public addItem(item: IHelpDeskItem): Promise<void> { return new Promise<void>((resolve, reject) => { //… return this._webPartContext.spHttpClient.post( `${currentWebUrl}/_api/web/lists/GetById('${this._listId}')/items`, SPHttpClient.configurations.v1, { headers: { "Accept": "application/json;odata=nometadata", "Content-type": "application/json;odata=verbose", "odata-version": "" }, body: body }); }).then((response: SPHttpClientResponse): Promise<any> => { return response.json(); }).then((item: any): void => { resolve(); }); }); } Creating Data
  • 15. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Deleting a specific item from the specified list public deleteItem(id: number): Promise<void> { return new Promise<void>((resolve, reject) => { if (!window.confirm(`Are you sure?`)) { return; } return this._webPartContext.spHttpClient.post( `${currentWebUrl}/_api/web/lists/GetById('${this._listId}')/items(${id})`, SPHttpClient.configurations.v1, { headers: { "Accept": "application/json;odata=nometadata", "Content-type": "application/json;odata=verbose", "odata-version": "", "IF-MATCH": "*", "X-HTTP-Method": "DELETE" } }).then((response: SPHttpClientResponse): void => { resolve(); }); }); } Deleting Data
  • 16. Using SharePoint Search • Using search allows you to query content in multiple lists or multiple sites or site collections • Uses a totally other query language (KQL or Keyword Query Language) • Very performant and optimized for fetching a lot of data, but has a 15 minutes-ish delay in terms of data freshness • Does not support any data modification
  • 17. KQL Crash Course • See Mickael Svenson blog series “SharePoint Search Queries Explained” • https://www.techmikael.com/2014/03/sharepoint-search-queries- explained.html
  • 18. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Getting all the sessions of the specified list using SharePoint Search public getItems(context: IWebPartContext): Promise<IHelpDeskItem[]> { return new Promise<IHelpDeskItem[]>((resolve, reject) => { context.spHttpClient.get(`${absoluteUrl}/_api/search/query?` + `querytext='ContentTypeId:0x0100…* AND ListID:${this._listId}'` + `&selectproperties='…'` + `&orderby='ListItemID asc'`, SPHttpClient.configurations.v1, { headers: { "odata-version": "3.0" } }).then(res => res.json()).then(res => { let helpDeskItems:IHelpDeskItem[] = []; if(res.PrimaryQueryResult) { for(var row of res.PrimaryQueryResult.RelevantResults.Table.Rows) { helpDeskItems.push(this.buildHelpDeskItem(row)); } } resolve(helpDeskItems); }); } Retrieving Data
  • 19. Notes on legacy APIs support • SharePoint APIs cover a wide-range of options, but not everything • You “might” have to revert to JSOM for some scenarios (Managed Metadata, etc.) • Or even to the ASMXWeb Services for more specific scenarios (Recurring Events in Calendars, etc.) • The SharePoint Framework supports those scenarios, but will require some extra work
  • 20. Microsoft Graph and Custom APIs
  • 21. What is the Microsoft Graph? Groups People Conversations Insights
  • 22. Microsoft Graph is all about you If you or your customers are part of the millions of users that are using Microsoft cloud services, then Microsoft Graph is the fabric of all your data It all starts with /me
  • 23. Gateway to your data in the Microsoft cloud Your app Gateway Your or your customer’s data Office 365 Windows 10 Enterprise Mobility + Security 1Microsoft Graph
  • 24. Microsoft Graph ALL Microsoft 365 Office 365 Windows 10 EMS ALL ONE https://graph.microsoft.com
  • 25. Microsoft 365 Platform web, device, and service apps Extend Microsoft 365 experiences 1 iOS/Android/Windows/Web Build your experience Microsoft Graph
  • 26. Options for the Microsoft Graph • Using the built-in MsGraphClient class that takes care of the entire authentication flow and token management for you • Using a custom implementation using ADAL or MSAL
  • 27. Are there any limitations? • Every scope will have to be defined beforehand and could open some security challenges • Authentication challenges could bring a broken experience to your users depending on the platform and browser used
  • 28. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // In your package-solution.json { // … "webApiPermissionRequests": [ { "resource": "Microsoft Graph", "scope": "Sites.ReadWrite.All" }, // … ] // … } Enabling Graph in your solution
  • 29. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Getting all the sessions of the specified list using the Microsoft Graph public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> { let graphUrl: string = `https://graph.microsoft.com/v1.0` + `/sites/${this.getCurrentSiteCollectionGraphId()}` + `/lists/${this._listId}` + `/items?expand=fields(${this.getFieldsToExpand()})`; return new Promise<IHelpDeskItem[]>((resolve, reject) => { this._client.api(graphUrl).get((error, response: any) => { let helpDeskItems:IHelpDeskItem[] = []; for(let helpDeskListItem of response.value) { helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem)); } resolve(helpDeskItems); }); }); } Retrieving Data
  • 30. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Creating a new item in the specified list public addItem(item: IHelpDeskItem): Promise<void> { let graphUrl: string = `https://graph.microsoft.com/v1.0` + `/sites/${this.getCurrentSiteCollectionGraphId()}` + `/lists/${this._listId}` + `/items`; return new Promise<void>((resolve, reject) => { const body: any = { "fields" : { "Title": item.title, "HelpDeskDescription": item.description, "HelpDeskLevel": item.level }}; this._client.api(graphUrl).post(body, (error, response: any) => { resolve(); }); }); } Creating Data
  • 31. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Deleting the specified item form the specified list public deleteItem(id: number): Promise<void> { let graphUrl: string = `https://graph.microsoft.com/v1.0` + `/sites/${this.getCurrentSiteCollectionGraphId()}` + `/lists/${this._listId}` + `/items/${id}`; return new Promise<void>((resolve, reject) => { this._client.api(graphUrl).delete((error, response: any) => { resolve(); }); }); } Deleting Data
  • 32. Custom APIs • Using the built-in AadGraphClient class that takes care of the entire authentication flow and token management for you • Using a custom implementation using ADAL or MSAL • You can use user impersonation (or not) to query SharePoint content based on user permissions
  • 33. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Getting all the sessions of the specified list using the AAD Client public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> { return new Promise<IHelpDeskItem[]>((resolve, reject) => { let apiUrl: string = "<url>/api/GetHelpDeskItems"; this._client .get(apiUrl, AadHttpClient.configurations.v1) .then((res: HttpClientResponse): Promise<any> => { return res.json(); }).then((res: any): void => { let helpDeskItems:IHelpDeskItem[] = []; for(let helpDeskListItem of res) { helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem)); } resolve(helpDeskItems); }); }); } } Retrieving Data
  • 35. What is PnP JS Core? PnPJS is a fluent JavaScript API for consuming SharePoint and Office 365 REST APIs in a type-safe way.You can use it with SharePoint Framework, Nodejs, or JavaScript projects.This an open source initiative that complements existing SDKs provided by Microsoft offering developers another way to consume information from SharePoint and Office 365. https://github.com/pnp/pnpjs
  • 36. Benefits of PnP JS Core • Type safe so you get your errors while you code and not when you execute and test • Works on all versions of SharePoint (On-Premises, Online, etc.) • Offers built-in caching mechanisms • Heavily used in the SharePoint Development Community
  • 37. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import { sp } from "@pnp/sp"; // ... public onInit(): Promise<void> { return super.onInit().then(_ => { // other init code may be present sp.setup({ spfxContext: this.context }); }); } // ... Sample – Setup PnP JS for SharePoint
  • 38. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Getting all the sessions of the specified list using PnP JS Core public getItems(context: WebPartContext): Promise<IHelpDeskItem[]> { return new Promise<IHelpDeskItem[]>((resolve, reject) => { sp.web.lists.getById(this._listId).items .select("*", "HelpDeskAssignedTo/Title") .expand("HelpDeskAssignedTo").getAll().then((sessionItems: any[]) => { let helpDeskItems:IHelpDeskItem[] = []; for(let helpDeskListItem of sessionItems) { helpDeskItems.push(this.buildHelpDeskItem(helpDeskListItem)); } resolve(helpDeskItems); }); }); } Retrieving Data
  • 41. Share your experience • Use hashtags to share your experience • #Office365Dev • #MicrosoftGraph • #SPFx • Log issues & questions to the GitHub Repositories