Failed to create folder through Sharepoint API

Andy Cen (IVC) 96 Reputation points

Request information:
"__metadata": {
"type": "SP.Folder"
"ServerRelativeUrl": "/PODEV/SAP%20Library/test"

Response information:
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "The property '__metadata' does not exist on type 'SP.Folder'. Make sure to only use property names that are defined by the type."

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
6,016 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
1,673 questions
No comments
{count} votes

Accepted answer
  1. Andy Cen (IVC) 96 Reputation points

    I solved the problem.
    The problem with the content-type parameter is in the official documentation

    Send the request based on the above example
    The server will report an error

    Then I refer to your answer and change the content-type parameter to: application/json; odata=verbose

    The folder is created successfully

    No comments

2 additional answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 14,306 Reputation points Microsoft Employee

    Hi @Andy Cen (IVC) ,
    Per my test the "ServerRelativeUrl" should be SAP%20Library/test. There might be something wrong in your request header. Please refer to the following sample to create the folder

    POST https://{site_url}/_api/web/folders  
    Authorization: "Bearer " + accessToken  
    Accept: "application/json;odata=verbose"  
    Content-Type: "application/json"  
    Content-Length: {length of request body as integer}  
    X-RequestDigest: "{form_digest_value}"  
      "__metadata": {  
        "type": "SP.Folder"  
      "ServerRelativeUrl": "document library/folder name"  

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  2. RaytheonXie_MSFT 14,306 Reputation points Microsoft Employee

    Hi @Andy Cen (IVC) ,
    Could you provide us the Request Header? One case when this error often happens is when you set ContentType request header as "application/json" instead of "application/json;odata=verbose". I have tested my code and it works. Please take a reference:

    		function createFolder() {  
    			var folderName = "test99";  
    			var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/folders";  
    				url: fullUrl,  
    				type: "POST",  
    				data: JSON.stringify({  
    					"__metadata": {  
    						"type": "SP.Folder"  
    					"ServerRelativeUrl": "Document Lib/" + folderName  
    				headers: {  
    					"accept": "application/json;odata=verbose",  
    					"content-type": "application/json;odata=verbose",  
    					"X-RequestDigest": $("#__REQUESTDIGEST").val()  
    				success: onQuerySucceeded,  
    				error: onQueryFailed