Create Lookup Field In Existing SharePoint List Using REST API Schema XML

Introduction

In this article, we will learn how to create a lookup field in an existing SharePoint list using REST API and schema XML. The REST API enables us to communicate with SharePoint using standard HTTP methods, such as GET, POST, PUT, and DELETE. The API provides access to various SharePoint entities including lists, libraries, and sites, allowing us to retrieve data, create and update lists, fields, items, upload files and manage user permissions.

Prerequisites

  • Access to a SharePoint site with permissions to create lists and fields

Below are the steps,

Step 1. Create a lookup list

The first step is to create the list that you want to be the source of the lookup field. I will use the "Department" list with the "Title" column as a source for creating the lookup field in this demo.

Create Lookup Field In Existing SharePoint List Using REST API Schema XML

Step 2. Create a new list

Create a new list and use it to create a multiselect lookup field by using the lookup list created in the previous step as its source.

Create Lookup Field In Existing SharePoint List Using REST API Schema XML

Step 3. Create REST API request body

For creating the multiselect lookup field using the REST API, we need to define the request body for the API call. This body will contain the schema XML for the field, which must include the following properties:

  • FieldType: Specifies the type of the field. For multiselect lookup fields, the value should be "LookupMulti".
  • Name: The internal name of the field.
  • DisplayName: The name of the field as it will be displayed in the list.
  • Required: Specifies whether the field is required or not.
  • List: The ID of the lookup list.
  • Mult: Specifies that the field is a multiselect field.
  • ShowField: The name of the source field from the lookup list.
    <Field Type=" LookupMulti"
        Name="{column-internal-name}"
        DisplayName="{column-display-name}"
        Required="TRUE"
        List="{lookup-list-id}"
        ShowField="{source-column}"
    Mult="TRUE"/>

Step 4. Make the REST API Call

With the request body defined, you are now ready to make the REST API call. You can use any REST client to make the call, such as Postman. The REST API call should be made to the following URL:

_api/web/lists/getbytitle('[source-list-name]')/fields/CreateFieldAsXml

The request should be a POST request and the request body should contain the schema XML defined in the previous step.

Create Lookup Field In Existing SharePoint List Using REST API Schema XML

Output

After making the REST API call, you can verify that the multiselect lookup field was created by going to the destination list's settings page and checking the list of fields.

List view

Conclusion

In this article, we have learned to create multiselect lookup field using REST API and schema XML. Thank you for reading.