How to configure a custom list form header using SharePoint Rest API?
It can be done using GUI : Configure custom header but I am interested in doing the same using Rest API calls from a flow.
How to configure a custom list form header using SharePoint Rest API?
It can be done using GUI : Configure custom header but I am interested in doing the same using Rest API calls from a flow.
Yes, you can do it using SharePoint REST API in Power automate flow using "Send HTTP Request to SharePoint" action.
Here are the details required for configuring the list form using JSON (with example data/values):
Method: POST
Request URL:
https://contoso.sharepoint.com/sites/JSONFormatting/_api/web/web/lists/getbytitle('DemoList')/contentTypes('0x010068C1DD7A88F89747A3F7FCACD851E20E')
Here you have to use the content type ID in the list for which you want to apply the JSON formatting.
Body/Payload:
{
"__metadata": {
"type": "SP.ContentType"
},
"ClientFormCustomFormatter": "{\"headerJSONFormatter\":{\"elmType\":\"div\",\"txtContent\":\"[$Title]\"},\"footerJSONFormatter\":{\"elmType\":\"div\",\"txtContent\":\"[$Description]\"},\"bodyJSONFormatter\":{\"sections\":[{\"displayname\":\"\",\"fields\":[\"Title\",\"Description\"]}]}}"
}
Here:
headerJSONFormatter object is associated with the list form "header" layout.
[$Title] and [$Description] inside the headerJSONFormatter and footerJSONFormatter object are internal names of column in this format: [$InternalNameOfColumn]. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?
Title and Description in bodyJSONFormatter object are display name of columns
You can take above example as reference and convert this as per your requirements in the Power automate flow.
Related thread: SharePoint Online - Removing faulty list form custom body JSON
Thank you Ganesh for your help, here is how it started to work for me:
_api/web/lists/getByTitle('DemoList')/ContentTypes?$filter=Name eq 'Item'Extract the StringId from above API call response as the Content Type Id which will be used in the next step.
_api/web/lists/getByTitle('DemoList')/contentTypes('StringIdFromPreviousStep')Set these additional headers:
IF-MATCH *
X-HTTP-Method MERGE
Content-Type application/json;odata=verbose
body example:
{"__metadata":{"type":"SP.ContentType"},"ClientFormCustomFormatter":"{\"headerJSONFormatter\":{\"elmType\":\"div\",\"txtContent\":\"test\"}}"}