Operaciones Especiales
A continuación, encontrarás ejemplos de operaciones con la API de SharePoint Online que son poco comunes o no están completamente documentadas. Si estás buscando información sobre las operaciones básicas, puedes revisar la documentación oficial en este enlace.
Crear un Contact Field
Pasos previos Primero, necesitamos el GUID de la SitePages Library. Para ello, simplemente hacemos un GET a _api/web/lists/getbytitle(‘Site%20Pages’)/id
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/lists/getbytitle('Site%20Pages')/id
Obtenemos el valor de <d:Id m:type="Edm.Guid">
. Lo usaremos como nuestro ID.
Crear el 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"
}
Agregamos la nueva columna a la Default View
POST https://zerogap.sharepoint.com/sites/zerogap/_api/Web/Lists(guid'ID')/Views(guid'defaultview')/ViewFields/AddViewField('Owner')
El ID es el que obtuvimos en el primer paso. El GUID del Default View depende del que esté configurado por defecto. Se puede obtener, por ejemplo, haciendo un GET con el endpoint:
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/lists/getByTitle('Site%20Pages')/Views/GetByTitle('All%20Pages')
Actualizar el valor de un Field
Usando el GUID del archivo
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"
}
Usando el path al archivo
https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByServerRelativePath(decodedurl='/sites/testmaxsite/SitePages/post.aspx')/ListItemAllFields
Actualizar un Taxonomy Field
Pasos previos Obtener el ID del archivo a actualizar.
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByServerRelativePath(decodedurl='/sites/zerogap/SitePages/post.aspx')/ListItemAllFields
El ID se encuentra en el siguiente atributo <d:Id m:type="Edm.Int32">7</d:Id>
.
Actualizar el 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
}
Modificar el Layout Webparts Content de una página
Pasos previos Obtener el ID de la página a modificar. Hay varias formas de hacer esto, por ejemplo, con un GET usando el GUID del archivo:
GET https://zerogap.sharepoint.com/sites/zerogap/_api/web/GetFileByid('sadf-sadsf5-sdfsdfsd5-sfsdgsdg')
Obtener el Layout usando el ID
GET https://zerogap.sharepoint.com/sites/zerogap/_api/sitepages/pages('ID')
Actualizar el Layout Cambiar el contenido del Layout que obtuvimos en el último request con los nuevos datos.
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": {}
}]'
}
- ChromaDB + Autenticación y Colecciones - mayo 17, 2024
- PowerShell + REST APIs para monitorear el estado de MS Flows - mayo 17, 2024
- IA Agent - mayo 11, 2024