2013-02-09 59 views
21

我试图在使用SharePoint 2013和REST API的现有列表中添加一个新项。使用SharePoint 2013 REST API添加列表项

有这个位置相当不错的文档: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我的列表,该文档似乎并不能解释how--我复制从文档的模式(SP.Data 。?< LIST_NAME>列表项“),但我想这是不正确的

我如何才能找到名称为我的名单

回答

19

你可以得到的名称如下:

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

列表名称将位于:content - > m:properties - > d:ListItemEntityTypeFullName

+1

一旦您知道实体类型是否有任何方法可以找出哪些属性是该类型的一部分?我遇到了一个问题,出现错误: “属性'MyColumn'不存在于'SP.Data.MyListListItem'类型中,请确保只使用由该类型定义的属性名称。” MyColumn是MyList的默认ContentType的一部分 – Jerzakie 2013-10-11 16:16:03

相关问题