How to update ModerationStatus (approval status) of a file in share point using Rest API
-
27-01-2021 - |
문제
after check in a file using rest api , it having approval status as 'draft', do we have any rest api url (postman) to update approval status of a file in share point.
해결책
HTTP POST:
https://<org>.sharepoint.com/sites/dev/_api/web/lists/getByTitle('list title')/items(<item id>)
Payload:
{
"__metadata": {
"type": "SP.Data.ClientsListItem" // your might be different
},
"OData__ModerationStatus": 0,
"OData__ModerationComments": "Approved by <user name>"
}
To find out your list's type you can issue http get to https://<org>.sharepoint.com/sites/dev/_api/web/lists/getByTitle('<list title>')?$select=ListItemEntityTypeFullName
. You should also provide x-requestdigest
in http headers, since it's POST request.
or change moderation status with pnpjs library:
sp.web.lists.getByTitle('Clients').items.getById(1).update({
'OData__ModerationStatus' : 0, // 1 - rejected
'OData__ModerationComments': `Approved by <user name>`
}).then(data => {
console.log(data);
});
다른 팁
As told by Sergei Sergeev. We can change approval status of a file using Rest.
1. post request header.
We need all these parameters in header. (if access token have fullControl as permission then we even don't need x-requestdigest in header)
Accept: application/json;odata=verbose
Authorization: Bearer <Your access token>
Content-Type: application/json;odata=verbose
X-HTTP-Method: MERGE
If-Match: *
As you can see i got response as 204 - that's success. so after post above post request check your share point site.