0

I am trying to copy an existing SharePoint List using SharePoint REST API. I was able to achieve what I wanted to do, but the display names for the fields and the list itself is not displayed within the view. However, when I get field or list information, the internalName and the displayName is updated. What am I doing wrong?

To copy a list, I am doing the following steps:

  1. Get field information from existing list
GET
let requestUrl = "/_api/web/lists/getbytitle('<ListTitle>')/Fields?$filter=Hidden eq false and ReadOnlyField eq false and InternalName ne 'Attachments' and InternalName ne 'ContentType'"
  1. Create list using internalName
POST
let requestUrl = "/_api/web/lists"
let body: [String: Any] = [
    "__metadata": ["type": "SP.List"],
    "BaseTemplate": 100,
    "Title": "<ListInternalName>"
]
  1. Update new list name
MERGE 
let requestUrl = "/_api/web/lists(guid'<NewListId>')"
let body: [String: Any] = [
    "__metadata": ["type": "SP.List"],
    "Title": "<ListDisplayName>",
]
  1. Add fields to new list using data from step 1
POST
let requestUrl = "/_api/web/lists(guid'\(listInfo.listsId)')/Fields"
let body: [String: Any] = [
    "__metadata": ["type": "SP.Field"],
    "Title": <FieldInternalName>,
    "FieldTypeKind": <FieldTypeKind>,
]
  1. Update new field name
MERGE
let requestUrl = "/_api/web/lists(guid'<NewListId>')/Fields('<NewFieldId>')"
let body: [String: Any] = [          
    "__metadata": ["type": "SP.Field"],
    "Title": "<NewFieldDisplayName>"
]
  1. Add fields to default view("All Items")
POST 
let requestUrl = "/_api/web/lists(guid'<NewListId>')/views(guid'<ViewId>')/ViewFields/AddViewField('<NewFieldInternalName>')"
1
  • There are tools available to copy lists, like ShareGate. Commented Oct 9 at 1:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.