SharePoint REST API
Translated from the Spanish original. Read in Spanish
Special Operations
Below you’ll find examples of SharePoint Online API operations that are uncommon or not fully documented. If you’re looking for information about the basic operations, you can check the official documentation at this link.
Create a Contact Field
Prerequisites: first, we need the GUID of the SitePages library. To get it, we simply do a GET to _api/web/lists/getbytitle(‘Site%20Pages’)/id
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/lists/getbytitle('Site%20Pages')/id
We take the value of <d:Id m:type="Edm.Guid">. We’ll use it as our ID.
Create the Contact Field
POST https://zerogap.sharepoint.com/sites/zerogap/_api/web/lists/getbyid('theid')/Fields
HEADERS
"accept": "application/json; odata=verbose",
"content-type": "application/json;odata=verbose"
BODY
{
"__metadata": {
"type": "SP.FieldUser"
},
"Title": "Owner",
"FieldTypeKind": 20,
"Required": "false",
"EnforceUniqueValues": "false",
"InternalName": "Owner",
"AllowDisplay": "true",
"Sortable": "true",
"UserDisplayOptions": "NamePhoto"
}
Add the new column to the Default View
POST https://zerogap.sharepoint.com/sites/zerogap/_api/Web/Lists(guid'ID')/Views(guid'defaultview')/ViewFields/AddViewField('Owner')
The ID is the one we got in the first step. The GUID of the Default View depends on which view is set as the default. You can get it, for example, with a GET to this endpoint:
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/lists/getByTitle('Site%20Pages')/Views/GetByTitle('All%20Pages')
Update the value of a Field
Using the file’s GUID
POST https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByid('GUID')/ListItemAllFields
HEADERS
"content-type": "application/json;odata=verbose",
"X-HTTP-Method": "PATCH",
"if-match": "*"
BODY
{
"__metadata": {
"type": "SP.PropertyValues"
},
"Alguna_Fecha": "Fecha"
}
Using the path to the file
https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByServerRelativePath(decodedurl='/sites/testmaxsite/SitePages/post.aspx')/ListItemAllFields
Update a Taxonomy Field
Prerequisites: get the ID of the file to update.
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByServerRelativePath(decodedurl='/sites/zerogap/SitePages/post.aspx')/ListItemAllFields
The ID is in the following attribute <d:Id m:type="Edm.Int32">7</d:Id>.
Update the Field
POST https://zerogap.sharepoint.com/sites/zerogap/_api/web/lists/getByTitle('Site%20Pages')/items('id')/ValidateUpdateListItem()
BODY
{
"formValues": [
{"FieldName":"Archive","FieldValue":"Zero |sdsdd0-1sd08-4ed8-a9d5-25a43434sdsd93"}
],
"bNewDocumentUpdate":false,
"checkInComment":null
}
Modify a page’s Layout Webparts Content
Prerequisites: get the ID of the page to modify. There are several ways to do this, for example with a GET using the file’s GUID:
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByid('sadf-sadsf5-sdfsdfsd5-sfsdgsdg')
Get the Layout using the ID
GET https://zerogap.sharepoint.com/sites/zerogap/_api/sitepages/pages('ID')
Update the Layout: replace the content of the Layout we got in the last request with the new data.
POST https://zerogap.sharepoint.com/sites/zerogap/_api/sitepages/pages(itemid)
HEADER
"Accept": "application/json;odata=nometadata",
"Content-type": "application/json;odata=verbose",
"odata-version": "",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
BODY
{
'__metadata': {
'type': 'SP.Publishing.SitePage'
},
'TopicHeader': 'Archived',
'LayoutWebpartsContent': '
[{
"id": "xxx-xxxxx-xxxx-xxxx",
"instanceId": "xxx-xxx-xxxxx-xxx",
"title": "\n Title area\n ",
"description": "\n Title area description\n ",
"audiences": [],
"htmlStrings": {},
"imageSources": {},
"links": {},
"dataVersion": "1.4",
"properties": {
"imageSourceType": 2,
"title": "Publish me",
"textAlignment": "Left",
"showPublishDate": false,
"authors": [{}],
"showTopicHeader": true,
"topicHeader": "",
"authorByline": [],
"layoutType": "FullWidthImage",
"enableGradientEffect": true
"htmlStrings": {},
"searchablePlainTexts": {},
"imageSources": {}
}]'
}
