Search code examples
sharepointsharepoint-rest-api

Sharepoint rest api - Create field and add to all content type


i am able to create a new field in a sharepoint list using the "createfieldasxml" method of "fields" endpoint. There is a way to add this field to all content type, and not just to the default content type? The other way i thought is to add manually every field i need to all the content type, but it's not the best solution. I did not find in the documentation that parameter, but it is present in the csom approach.

Thanks


Solution

  • I answered you question here: https://learn.microsoft.com/en-us/answers/questions/541651/sharepoint-rest-api-create-field-and-add-to-all-co.html

    You could set the Options property to 4(AddToAllContentTypes) in the body using createfieldasxml method like the below:

     {
       "parameters": {
         "__metadata": {
           "type": "SP.XmlSchemaFieldCreationInformation"
         },
         "SchemaXml": "<Field Type='Text' DisplayName='test' Name='test'></Field>",
         "Options":4
       }
     } 
    

    The AddFieldOptions value can be found here: https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee542202(v=office.15)