How to create a Folder via curl in sharepoint?

Mocoloco 0 Reputation points
2024-09-09T07:01:40.2366667+00:00

How do i create an Empty Folder via curl? I have AllSites.FullControl permission, but I still get the following response:

{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied."}}}

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.
2,987 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 17,150 Reputation points Microsoft Vendor
    2024-09-09T08:43:29.58+00:00

    Hi @Mocoloco,

    Thank you for posting in this community.

    The following example shows how to create a folder by using Rest API.

    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 relative url/folder name"
    }
    

    If you continue to encounter System.UnauthorizedAccess Exception, I recommend that you first parse your access token into this widget and check that the permissions recorded in your SCP section match the permissions you should be granted. Also, make sure you're using the access token of the Rest API and not the access token of the Graph API.

    Sometimes people confuse these two which leads to UnauthorizedAccess Exception.

    Here is a method to obtain the access token of the REST API: Access SharePoint Online data using postman tool.


    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.