Introduction
Recently, I came across a use case where the file properties need to be updated after processing the file. The business scenario here is to read the Excel file (.xlsx) from the document library and transform this data to a SharePoint list and once the process is completed, it is required to update the metadata property called ‘FileProcessed’ to ‘Yes’. By default, the value of this property is set to ‘No’ before the file processing. This ‘FileProcessed’ metadata is of type ‘Choice’ in SharePoint. The environment is SharePoint online.
According to the MSFT documentation, to work with Files and Folders in using REST API, it is required to pass header data and JSON body in a particular format. Here are the steps I have followed.
- Method: POST
- Uri: /_api/web/lists/getbytitle/(‘TailSpin Library’)/items(6). The syntax is as follows /_api/web/lists/getbytitle/(‘DISPLAY TITLE’)/items(ITEMID).
- Headers
- accept: application/json;odata=nometadata
- content-type: application/json;odata=nometadata
- IF-MATCH: *
- X-HTTP-Method: MERGE
- Body
{
"__metadata": {
"type": "SP.Data.TailSpinLibraryItem"
},
"FileProcessed": "Yes"
}
The syntax is,
{
"__metadata": {
"type": "SP.Data.{INTERNALIBRARYNAME}Item"
},
"Metadata Field": "VALUE"
}
You may also refer to the screen capture below for reference for the above values mentioned in the ‘Send an HTTP request to SharePoint’ PowerAutomate action.
Below is the error I have got.
Error
- {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The property '__metadata' does not exist on type 'SP.Data.DeficiencyLitigationItem'. Make sure to only use property names that are defined by the type."}}}
- clientRequestId: 5e414111-eb3f-4ab9-94fa-7431bcffe051
- serviceRequestId: 838954a1-90d9-6000-67a5-29234e8de6b7
Fix
Basically, the error says there is no “__metada” property existing on the data type library item. All it is required to do is remove the “__metada” JSON in the ‘Body’ and save the action. Below is the correct format for reference. Here, the metadata field's internal name should be given in double quotes, and the respective value should also be in double quotes, which is standard JSON format.
{
"FileProcessed": "Yes"
}
Once saved, and run, you should see the error go away and the required meta-data should be updated in the SharePoint library.
For more information, you can refer to the official MSFT documentation in the references sections that explains REST API operations (GET, PUT, POST, PATCH, DELETE) with SharePoint lists and libraries.
Conclusion
Thus, in this article, we have seen how to update the file metadata in the SharePoint online document library using the ‘Send an HTTP request to SharePoint’ action item using Power Automate.
References