SlideShare a Scribd company logo
Hard learned CSOM and REST
SAHIL MALIK
WWW.WINSMARTS.COM
@SAHILMALIK

SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013
ZAGREB, NOVEMBER 27-28 2013
sponsors
C:>whoami

11xMVP
15xAuthor
Pluralsight Author
Microsoft Metro Trainer
Funny and Honest

HTTP://BLAH.WINSMARTS.COM
@SAHILMALIK
Hard learned SharePoint dev tips
0945AM

Hard learned CSOM and REST

0345PM
Client side technologies in SharePoint 2013
Why Microsoft created REST and CSOM?
Why Microsoft created REST and CSOM
Why do you need to learn about REST and CSOM?

* There are some minor differences in the REST/CSOM API in Office 365
Synchronous vs. Asynchronous
var data = DownloadData(...);
ProcessData(data);

DownloadDataAsync(... , data => {
ProcessData(data);
});
Synchronous vs. Asynchronous
var data = DownloadData(...);
ProcessData(data);

DownloadDataAsync(... , data => {
ProcessData(data);
});
Asynch Code challenges – Error Handling

DownloadDataAsync(... , data => {
ProcessData(data);
});
Asynch Code Challenges – Timing issues
Asynch Code Challenges - Concurrency
Async code challenges
Concurrency, so how does it work?
The general theme
CSOM/REST comparison
What

CSOM

REST

Going to the server

ExecuteQuery
ExecuteQueryAsync

$.get
$.getJSON
$.ajax

Concurrency

Checks built into framework during save
operations.
Object Identity & Object Tracking

eTAG support

Data Objects

Objects that inherit from ClientObject

JavaScript objects, or similar non-intelligent
business objects

Usual application

Usually C# etc. (server side code in apps)

Usually browser side code (usually
JavaScript)

Security

Piggy backs on transport security + OAuth

Piggy backs on browser security + OAuth

Community support

SharePoint specific – some support.

JavaScript and jQuery and REST are open
standards – lots of support.
CSOM
How CSOM works
Create a ClientContext

Use Load/LoadQuery to specify what data you wish to get

Get data using ExecuteQuery/ExecuteQueryAsync

Make changes to data

Save data using ExecuteQuery/ExecuteQueryAsync
How CSOM works
Client Application

Server

Sequence of
commands:

Client.svc

command 1;
command 2;
command 3;
context.ExecuteQuery();

Process results

XML
JSON

Execute commands
in the batch:
command 1;
command 2;
command 3;
Send results back
ClientContext
Client Objects
Server
(Microsoft
.SharePoint)

.NET Managed
(Microsoft.SharePoint
.Client)

Silverlight
(Microsoft.SharePoint
.Client.Silverlight)

JavaScript
(SP.js)

SPContext

ClientContext

ClientContext

ClientContext

SPSite

SPSite

SPSite

Site

SPWeb

SPWeb

SPWeb

Web

SPList

SPList

SPList

List

SPListItem

SPListItem

SPListItem

ListItem

SPField

SPField

SPField

Field

SPWeb.Title

SPWeb.Title

SPWeb.Title

web.get_Title();
web.set_Title();

Member names mostly the same from server to client
(e. g., SPWeb.QuickLaunchEnabled = SPWeb.QuickLaunchEnabled)
JavaScript frequently has get_ set_ methods instead of properties
Load vs LoadQuery
Update Data
ExecuteQuery vs ExecuteQueryAsync
Upload file using CSOM
How to use CSOM? – Silverlight

http://blah.winsmarts.com/2010-3-Integrating_Silverlight_BING_Maps_with_SharePoint_2010.aspx
How to use CSOM? – Windows Phone
How to use CSOM? – JavaScript
Referencing CSOM by hand
Get and Set Web properties
Get List Items
Method Chaining
CRUD Operations
REST API
What is REST?
REST Data Formats
REST API
SharePoint 2013 REST URL structure

http://server/site/_api/site
SharePoint REST API Parameter structure

http://server/site/_api/web/getAvailableWebTemplates(lcid=1033, includeCrossLanguage=true)
SharePoint REST service parameter aliasing syntax

http://server/site/_api/userProfiles/People(7)/GetWorkplace(@address)?@address={"__metadata":{"type:
"ODataDemo.Address"},"Street":"NE 228th", "City":"Sammamish","State":"WA","ZipCode":"98074","Country":
"USA"}
REST service syntax for parameters in query string

http://<server>/<site>/_api/web/applyWebTemplate?template=”STS#0”
Query Operator Support
REST Query Operators
Supported
Numeric comparisons
•Lt
•Le
•Gt
•Ge
•Eq
•Ne
String comparisons
•startsWith
•substringof
•Eq
•Ne

Date and time functions
•day()
•month()
•year()
•hour()
•minute()
•second()

Not supported
•Arithmetic operators
(Add, Sub, Mul, Div, Mod)
•Basic math functions
(round, floor, ceiling)

•endsWith
•replace
•substring
•tolower
•toupper
•trim
•concat
•DateTimeRangesOverlap operator
•Querying as to whether a date time falls inside a recurrent date time pa
Example
Example Queries
Description

URL endpoint

HTTP method

Body content

Retrieves the title of a list

web/title

GET

Not applicable

Retrieves all lists on a site

lists

GET

Not applicable

Retrieves a single 'list's metadata

lists/getbytitle('listname')

GET

Not applicable

Retrieves items within a list

lists/getbytitle('listname')/items

GET

Not applicable

Retrieves a specific property of a document. (In
this case, the document title.)

lists/getbytitle('listname')?select=Ti
tle

GET

Not applicable

Creates a list

lists

POST

{ '_metadata':{'type':SP.List}, 'AllowContentTypes': true, 'BaseTemplate': 104,
'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'RestTest' }

Adds an item to a list

lists/getbytitle('listname')/items

POST

{ '_metadata':{'type':SP. listnameListItem}, 'Title': 'MyItem' }
HTTP Methods
HTTP Methods
Form Digest
/contextinfo

Property

Description

webFullUrl

Gets the server-relative URL of the nearest site.

siteFullUrl

Gets the server-relative URL of the root of the site
collection that the site is contained within.
If the nearest web is the root of a site collection, then
the value of the webFullUrl property is equal to
the siteFullUrl property.

formDigestValue

Gets the server's request form digest.

LibraryVersion

Gets the current version of the REST library.

SupportedSchemaVersions

Gets the versions of the schema of the REST/CSOM
library that are supported.
Traversing Folders
CRUD Operations
Create a site
Create a list
Create a file in a doc lib

Create a file in a folder
Update – Either PUT or PATCH(MERGE)
Update using PUT
Update using PATCH
Getting contents of a file
Deletes
ETags
Get Changes since last refresh
REST Error Diagnosis
questions?
HTTP://BLAH.WINSMARTS.COM
@SAHILMALIK
thank you.
SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013
ZAGREB, NOVEMBER 27-28 2013

More Related Content

PPTX
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
PPTX
SharePoint REST vs CSOM
PPTX
SharePoint 2013 REST APIs
PPTX
SharePoint Client Object Model (CSOM)
PPTX
Understanding and programming the SharePoint REST API
PPTX
Client Object Model and REST Improvements in SharePoint 2013
PPT
Share point apps the good, the bad, and the pot of gold at the end of the r...
PPTX
Developing a Provider Hosted SharePoint app
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
SharePoint REST vs CSOM
SharePoint 2013 REST APIs
SharePoint Client Object Model (CSOM)
Understanding and programming the SharePoint REST API
Client Object Model and REST Improvements in SharePoint 2013
Share point apps the good, the bad, and the pot of gold at the end of the r...
Developing a Provider Hosted SharePoint app

What's hot (20)

PPTX
Introduction to the SharePoint Client Object Model and REST API
PPTX
Designing for SharePoint Provider Hosted Apps
KEY
SharePoint 2010 Client Object Model
PPTX
SharePoint 2013 APIs demystified
PPTX
Integrating SharePoint 2010 and Visual Studio Lightswitch
PPTX
Developing SharePoint 2013 apps with Visual Studio 2012 - Microsoft TechDays ...
PPTX
Webtrends and bright starr webinar 01282015 sharepoint is evolving
PPTX
SharePoint 2013 APIs
PPTX
[Vochten/Harbar] SharePoint Server On Premises & Hybrid PowerClass
PPTX
Sviluppare App per Office 2013 e SharePoint 2013
PPTX
SharePoint 2013 REST and CSOM
PPT
Introduction to the Client OM in SharePoint 2010
PDF
Taking Advantage of the SharePoint 2013 REST API
PPTX
SharePoint 2013 App Provisioning Models
PPTX
SharePoint 2013 Sneak Peek
PPTX
Microsoft Flow best practices European Collaboration Summit 2018
PPTX
SharePoint 2010 Application Development Overview
PPTX
[Wilen] Enriching conversations with your data in Microsoft Teams
PPTX
SPCA2013 - Developing Provider-Hosted Apps for SharePoint 2013
PDF
O365Con18 - Site Templates, Site Life Cycle Management and Modern SharePoint ...
Introduction to the SharePoint Client Object Model and REST API
Designing for SharePoint Provider Hosted Apps
SharePoint 2010 Client Object Model
SharePoint 2013 APIs demystified
Integrating SharePoint 2010 and Visual Studio Lightswitch
Developing SharePoint 2013 apps with Visual Studio 2012 - Microsoft TechDays ...
Webtrends and bright starr webinar 01282015 sharepoint is evolving
SharePoint 2013 APIs
[Vochten/Harbar] SharePoint Server On Premises & Hybrid PowerClass
Sviluppare App per Office 2013 e SharePoint 2013
SharePoint 2013 REST and CSOM
Introduction to the Client OM in SharePoint 2010
Taking Advantage of the SharePoint 2013 REST API
SharePoint 2013 App Provisioning Models
SharePoint 2013 Sneak Peek
Microsoft Flow best practices European Collaboration Summit 2018
SharePoint 2010 Application Development Overview
[Wilen] Enriching conversations with your data in Microsoft Teams
SPCA2013 - Developing Provider-Hosted Apps for SharePoint 2013
O365Con18 - Site Templates, Site Life Cycle Management and Modern SharePoint ...
Ad

Viewers also liked (8)

PPTX
Rencore Webinar: SharePoint Customizations - the most overlooked road block t...
PPTX
SPS Barcelona 2016 - Branding Strategies for SharePoint and Add-ins - From De...
PDF
[120316] node.js 프로그래밍 5장
PPTX
Chris O'Brien - Comparing SharePoint add-ins (apps) with Office 365 apps
PPTX
Atlassian JIRA Plugin 및 REST API를 이용한 기능 확장
PPTX
Introduction to Azure Functions - Tutorial
PPTX
Open API 발표자료 - 김연수
PPTX
소프트웨어 개발 트랜드 및 MSA (마이크로 서비스 아키텍쳐)의 이해
Rencore Webinar: SharePoint Customizations - the most overlooked road block t...
SPS Barcelona 2016 - Branding Strategies for SharePoint and Add-ins - From De...
[120316] node.js 프로그래밍 5장
Chris O'Brien - Comparing SharePoint add-ins (apps) with Office 365 apps
Atlassian JIRA Plugin 및 REST API를 이용한 기능 확장
Introduction to Azure Functions - Tutorial
Open API 발표자료 - 김연수
소프트웨어 개발 트랜드 및 MSA (마이크로 서비스 아키텍쳐)의 이해
Ad

Similar to Hard learned CSOM and REST tips (20)

PPTX
SharePoint for the .NET Developer
PPTX
Develop iOS and Android apps with SharePoint/Office 365
PPTX
06 web api
PPTX
Apps 101 - Moving to the SharePoint 2013 App Model - Presented 7/27/13 at Sha...
ODP
Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o F...
PPTX
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
PPTX
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
PDF
SFScon22 - Francesco Corcoglioniti - Integrating Dynamically-Computed Data an...
PPTX
Working with a super model for SharePoint Tuga IT 2016
PDF
MuleSoft London Community February 2020 - MuleSoft and OData
PDF
Comsharepoint2013pdf
PPTX
Azuresatpn19 - An Introduction To Azure Data Factory
PPTX
REST: So What's It All About? (SAP TechEd 2011, MOB107)
PDF
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
PPTX
Rest API and Client OM for Developer
PPTX
Why and how to leverage the simplicity and power of SQL on Flink
PPTX
2013 - Back to the Future with Client/Server Development
PDF
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
PPTX
Integration with Dynamics CRM
PDF
J1 T1 4 - Azure Data Factory vs SSIS - Regis Baccaro
SharePoint for the .NET Developer
Develop iOS and Android apps with SharePoint/Office 365
06 web api
Apps 101 - Moving to the SharePoint 2013 App Model - Presented 7/27/13 at Sha...
Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o F...
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
SFScon22 - Francesco Corcoglioniti - Integrating Dynamically-Computed Data an...
Working with a super model for SharePoint Tuga IT 2016
MuleSoft London Community February 2020 - MuleSoft and OData
Comsharepoint2013pdf
Azuresatpn19 - An Introduction To Azure Data Factory
REST: So What's It All About? (SAP TechEd 2011, MOB107)
Decompose That WAR! Architecting for Adaptability, Scalability, and Deployabi...
Rest API and Client OM for Developer
Why and how to leverage the simplicity and power of SQL on Flink
2013 - Back to the Future with Client/Server Development
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
Integration with Dynamics CRM
J1 T1 4 - Azure Data Factory vs SSIS - Regis Baccaro

More from SPC Adriatics (20)

PPTX
How to secure your data in Office 365
PPTX
Do you know, where your sensitive data is?
PPTX
Securing Intellectual Property using Azure Rights Management Services
PPTX
Creating Workflows in Project Online
PPTX
Faster than a flash behind the scenes of patching SharePoint Online
PPTX
Role based views in Project and Resource Center
PPTX
OneDrive, TwoDrive, Whiterive, BlueDrive (hahaha)
PPTX
SharePoint Governance and Compliance
PDF
From analyses to successful Implementation
PDF
The key to a successful Office 365 implementation is adoption
PPTX
Office 365 Video
PPTX
10 Steps to be Successful with Enterprise Search
PPTX
How the Cloud Changes Business Solution Design and Delivery
PDF
Scaling SharePoint 2016 Farms with MinRole & Other Tools
PPTX
SharePoint 2013 Search Operations
PDF
Office Online Server 2016 - a must for on-premises installation for SharePoin...
PPTX
Custom Code-The Missing Piece of the SharePoint Governance Puzzle
PPTX
SharePoint 2016 Hybrid Sites Inside Out
PPTX
Microsoft BI demystified: SharePoint 2016 BI or for PowerBI v2?
PPTX
What's New for the BI workload in SharePoint 2016 and SQL Server 2016
How to secure your data in Office 365
Do you know, where your sensitive data is?
Securing Intellectual Property using Azure Rights Management Services
Creating Workflows in Project Online
Faster than a flash behind the scenes of patching SharePoint Online
Role based views in Project and Resource Center
OneDrive, TwoDrive, Whiterive, BlueDrive (hahaha)
SharePoint Governance and Compliance
From analyses to successful Implementation
The key to a successful Office 365 implementation is adoption
Office 365 Video
10 Steps to be Successful with Enterprise Search
How the Cloud Changes Business Solution Design and Delivery
Scaling SharePoint 2016 Farms with MinRole & Other Tools
SharePoint 2013 Search Operations
Office Online Server 2016 - a must for on-premises installation for SharePoin...
Custom Code-The Missing Piece of the SharePoint Governance Puzzle
SharePoint 2016 Hybrid Sites Inside Out
Microsoft BI demystified: SharePoint 2016 BI or for PowerBI v2?
What's New for the BI workload in SharePoint 2016 and SQL Server 2016

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Hard learned CSOM and REST tips