25

I'm trying to add a new item in a existing list using SharePoint 2013 with the REST API.

There is pretty good documentation for this here: http://msdn.microsoft.com/en-us/library/jj164022(office.15).aspx#ListItems

The list I am trying to add items to is called "Resources", so I do the following http POST operation to add the new item:

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"
    }

But I get back the following error:

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.

So I presume I don't have the correct name for the name for the resource. In the documentation, it says:

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.

But I don't know how to get the ListItemEntityTypeFullName for my list, and the documentation does not seem explain how-- I copied the pattern from the doc (SP.Data.< LIST_NAME >ListItem") but I guess that is not right.

How can I find the name for my list?

kimon
  • 2,481
  • 2
  • 23
  • 33

1 Answers1

24

You can get the name as follows:

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

The list name will be under: content -> m:properties -> d:ListItemEntityTypeFullName

kimon
  • 2,481
  • 2
  • 23
  • 33
  • 1
    Once you know the Entity type is there any way to find out what properties are part of that type? I'm having an issue where I am getting an error: "The property 'MyColumn' does not exist on type 'SP.Data.MyListListItem'. Make sure to only use property names that are defined by the type." MyColumn is part of MyList's default ContentType – Jerzakie Oct 11 '13 at 16:16
  • @Jerzakie Most likely you're using a display name of the column instead of the original. You can do 2 things to find the original: 1) look under List Settings > hover over/select the field. The URL will have something like `Field=SomeName`. `SomeName` is what you want. 2) If you don't have access to the List Settings, you can go to `http://yoursite/_vti_bin/listdata.svc/ListName` (SP 2010) or `http://yoursite/_api/Web/Lists/GetByTitle('ListName')` (SP 2013+). The field names will be under `Your Display Name` (in 2013+: omit ). – vapcguy Mar 25 '19 at 15:59