Question

I am using on premise SharePoint server 2016.I am using rest api to update a list.I have a list having space in it's name so while passing this name it causes problem.Is it possible to pass file name having space to update operation. Suppose list name is 'abc list'.

 $.ajax  
    ({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('abc%20list')/items("+Idtoupdate+")", // list item ID  
        type: "POST",  
        data: JSON.stringify  
        ({  
            __metadata:  
            {  
                type: "SP.Data.abc%20list"  
            },  
            Uploaded:value

        }),  
        headers:  
        {  
            "Accept": "application/json;odata=verbose",  
            "Content-Type": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "IF-MATCH": "*",  
            "X-HTTP-Method": "MERGE"  
        },  
async: false,  
        success: function(data, status, xhr)  
        {  
            debugger;
        },  
        error: function(xhr, status, error)  
        {  
            debugger;
        }  
    });

I am getting error at json.strignify.

Error:

{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"A type named 'SP.Data.Approver DashboardListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.\"}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A type named 'SP.Data.Approver DashboardListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."}}},"status":400,"statusText":"Bad Request"}

Était-ce utile?

La solution

You can pass the display name of your SharePoint List in REST API call like below:

_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('abc list')/items"

Also make sure you are passing correct ListItemEntityTypeFullName in type property inside __metadata.

You can check ListItemEntityTypeFullName of your list using below URL:

/_api/web/lists/GetByTitle('listName')/ListItemEntityTypeFullName

Common Format of ListItemEntityTypeFullName:

SP.Data.ListNameListItem

Replace only ListName with your list name.

Update:

For your case try using below:

data: JSON.stringify  
    ({  
        __metadata:  
        {  
            type: "SP.Data.Approver_x0020_DashboardListItem"  
        },  
        Uploaded:value

    })

Generally in ListItemEntityTypeFullName, Space is replaced by _x0020_. But, it is always recommended to check ListItemEntityTypeFullName of your list by using:

/_api/web/lists/GetByTitle('listName')/ListItemEntityTypeFullName
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top