Task
I needed to set ReadOnly property of a SPList Content Type from my SPFx web part. I’m using @pnp/sp library, but it doesn’t support modifying existing Content Types.
Solution
Changing the ReadOnly property of an existing list content type is possible using REST, but I had some troubles finding out correct set of HTTP body and header payloads. Working code can be found below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | const spOpts: ISPHttpClientOptions = { headers: { 'Accept': 'application/json;odata=verbose', 'X-HTTP-Method': 'MERGE', 'odata-version': '3.0' }, body: JSON.stringify({ __metadata: { type: 'SP.ContentType' }, ReadOnly: false }) }; let oldCt: ContentType = list.contentTypes.getById('0x01CONTENTTYPEID'); await this.props.context.spHttpClient.post( oldCt.toUrlAndQuery(), SPHttpClient.configurations.v1, spOpts ); |
ThoughtsFor later reference when investigating similar issues, here’s a collection of error messages depending what Header parameter is missing or invalid.
|
|||||||||
Thank you! I missed the first "-" in X-HTTP-Method. Had me going crazy for a few hours. That table with errors was pretty darn sweet. Microsoft should have a complete list like that.
ReplyDelete