使用SharePoint 2013 REST API添加列表项

时间:2013-02-09 20:49:41

标签: rest sharepoint sharepoint-api sharepoint-2013

我正在尝试使用带有REST API的SharePoint 2013在现有列表中添加新项目。

这里有很好的文档:http://msdn.microsoft.com/en-us/library/jj164022(office.15).aspx#ListItems

我尝试添加项目的列表称为“资源”,因此我执行以下http POST操作来添加新项目:

POST https://<site>/apps/reserve/_api/lists/getbytitle('Resources')/items
    X-RequestDigest: <digest_key>
    Content-Type: application/json;odata=verbose

    {
        "__metadata":    {"type": "SP.Data.ResourcesListItem"},
        "Title":         "New Title",
        "Description":   "New Description",
        "Location":      "Sunnyvale"
    }

但我收回了以下错误:

A type named 'SP.Data.ResourcesListItem' could not be resolved by the model.
When a model is available, each type name must resolve to a valid type.

所以我认为我没有资源名称的正确名称。在文档中,它说:

To do this operation, you must know the ListItemEntityTypeFullName property of the list
and pass that as the value of type in the HTTP request body.

但我不知道如何为我的列表获取ListItemEntityTypeFullName,文档似乎没有解释 - 我从doc(SP.Data。&lt; LIST_NAME&gt; ListItem“)复制了模式但是我猜猜那不对。

如何找到列表名称?

1 个答案:

答案 0 :(得分:21)

您可以按如下方式获取名称:

GET https://<site>/apps/reserve/_api/lists/getbytitle('Resources')?$select=ListItemEntityTypeFullName

列表名称将位于:content - &gt; m:属性 - &gt; d:ListItemEntityTypeFullName