An Entry Without a Type Name Was Found Rest API

Recently, while creating a folder in the SharePoint List using SharePoint Rest Api, I came across this error: An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.

You can refer to the image below.

An entry without a type name was found, but no expected type was specified error

In this SharePoint tutorial, we will discuss in detail how I got this error: “An entry without a type name was found, but no expected type was specified error” and how to fix it.

Error: An Entry Without a Type Name Was Found Rest API

When I was creating a folder in the SharePoint list using REST API, I used the code below to execute:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    function createFolderInList(listTitle, folderName) {
    // Construct the endpoint URL for adding a folder
    var endpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items";

    // Construct the folder metadata
    var folderMetadata = {
        "fields": {
            "Title": folderName
        },
        "contentType": { "id": "0x0120" }
    };

    // Create the folder
    return $.ajax({
        url: endpointUrl,
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(folderMetadata),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            console.log("Folder created successfully:", data);
        },
        error: function (error) {
            console.error("Failed to create folder:", error);
        }
    });
}

// Usage example
var listTitle = "Sales"; // Replace with your SharePoint list title
var folderName = "Test"; // Specify the name of the folder to be created

createFolderInList(listTitle, folderName);

</script>

When I ran this code in SharePoint, I got the error: “An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.

An entry without a type name was found, but no expected type was specified error


This error usually occurs when the SharePoint REST API is used to create or update items in SharePoint. It shows that because the required type information is missing, SharePoint is unable to process the data in the request payload.

See also  SharePoint modern list view customization example

This indicates that SharePoint expects the request payload to contain metadata (such as list item properties) specifying the kind of data being provided. SharePoint is unable to appropriately evaluate the request without this information, which results in the error message seen.

If you highlight this section of the code, the error happened because we didn’t provide the metadata type information needed to create a folder.

  // Construct the folder metadata
    var folderMetadata = {
        "fields": {
            "Title": folderName
        },
        "contentType": { "id": "0x0120" }
    };

In the next section, we will see how to resolve this error by providing the information type.

Solution: An Entry Without a Type Name Was Found Rest API

To resolve this error, we need to replace the code var folderMetadata with the below code:

  var folderMetadata = {
        "__metadata": { "type": "SP.Data." + listTitle + "ListItem" },
        "Title": folderName,
        "ContentTypeId": "0x0120" // Content Type ID for folders
    };

Now, run the code, and you can create a folder in the SharePoint list using SharePoint rest API, as shown below.

An entry without a type name was found, but no expected type was specified error in SharePoint

Also, you may like:

Conclusion

In this SharePoint tutorial, we saw how to fix the error: An entry without a type name was found, but no expected type was specified. The expected type must also be specified when the model is specified to allow entries without type information while working with REST API.

>