web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Issue in using SharePo...
Power Automate
Answered

Issue in using SharePoint - Send http request action for SharePoint document libraries

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Team,

 

Currently we are facing an issue with using SharePoint - Send Http request action in order insert, update a SharePoint Document library content type based list items. When we tried to Post a JSON message to SharePoint Rest API for creating a new list item in Document library we are getting following error:

 

{
  "error": {
    "code"502,
    "source""firstrelease-001.azure-apim.net",
    "clientRequestId""22630973-c0d1-4dfd-b644-de9a2148ce68",
    "message""BadGateway",
    "innerError": {
      "message""To add an item to a document library, use SPFileCollection.Add()\r\nclientRequestId: 22630973-c0d1-4dfd-b644-de9a2148ce68\r\nserviceRequestId: 1a73779e-6003-0000-9acb-ea7611f705ab",
      "status"502,
      "source""..../_api/web/lists/getbytitle('DemoContent')/items",
      "errors": [
        "-2146232832",
        "Microsoft.SharePoint.SPException"
      ]
    }
  }
}

 

Do we need to have two actions for dealing with inserting a new item in to document library? We are trying to provide all the list item details in a JSON based on document library metadata, but still we are getting an error to use SPFileCollection.Add() method. Is this we need to create a file first and then we need to insert the list item in to Document library when we use SharePoint Rest API? Please provide us some pointers about resolving this issue...

 

Thanks,

Vdeevi 

Categories:
I have the same question (0)
  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @vedeevi,

     

    Could you please share a screenshot of your flow's configuration?

    Do you want to upload a file into your SP library using the "Send an HTTP request to SharePoint" action?

     

    I have made a test on my side and don't have the issue that you mentioned. Please take a try with the following workaround:6.JPG

     

     

    Within "Send an HTTP request to SharePoint" action, Uri field set to following formula:

    _api/web/GetFolderByServerRelativeUrl('Reporting1/Upload')/Files/Add(url='@{triggerBody()['text']}', overwrite=true)

    Note: The Reporting1 represents the Library name in my SP site, the Upload represents a folder in the Reporting1 library.

     

    The standard format of the SP REST API for uploading a file to SP library as below:

    _api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/Add(url='file name', overwrite=true)

    The flow works successfully as below:7.JPG

     

     

     

    More details about uploading a file into SP library using SP REST API, please check the following article:

    https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest#working-with-files-by-using-rest

     

     

    Best regards,

    Kris

     

     

  • vedeevi Profile Picture
    Microsoft Employee on at

    Hi Kris,

     

    Thanks for providing the details about adding a file to Document library using SharePoint - Send http request action. Howerver in our flow scenario we will not have any physical file that need to be saved, but we need to create a virtual file based on the text that is provided in "Title" field of the content type enabled document library and we get these details as part of JSON file which is uploaded in to another SharePoint site Document library.... 

     

    Following are the are our Flow step requirements...

    1. External team provides JSON file in SharePoint site (Let us name it as "A" site) Document Library.

    2. Flow has to read this JSON file from "A" SharePoint site document library, iterate through the contents of this JSON file,

    3. It has to insert this in to another SharePoint site (Let us name it as "B" site) Document library as content type ("Approved Shared Link to Non-SharePoint Content") enabled List items with link associated to "Title" field of "B" SharePoint site (link is a virtual file link which physically does not exists)

     

    To implement this functionality, do we need to use two "SharePoint - Send Http Request" actions (one for creating the file in Document Library and another one for insterting item field values)?

     

    Thanks & Regards,

    VEDEEVI.

     

  • Verified answer
    vedeevi Profile Picture
    Microsoft Employee on at

    We could able to resolve this issue in two steps using SharePoint - Send Http request to SharePoint actions.

     

    1. First SharePoint - Send Http request to SharePoint action is used to add a file in to document library. To this we used following API

     

    _api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/Add(url='file name', overwrite=true)

    2. Next SharePoint Http request action is used to update the ListItem all fields which are associate with file which was inserted. To this we used following API to update the all the list item fields

     

    _api/web/GetFileByServerRelativeUrl('/Relative Path with Folder Name/FileName')/ListItemAllFields

    Following are the Header that need to be provided for 2nd action

     

    "Method" : "POST"

    "accept" : "application\json; odata=verbose",

    "content-type" : "application\json; odata=verbose",

    "IF-MATCH" : "*",

    "X-HTTP-Method" : "MERGE"

     

    In the body portion of this action, we need to provide JSON format of List Item field values..

     

    {
     "__metadata" : { "type" : "SP.Data.<ListName>Item"},
    
     "Title" : "Test document",
    
     "Description" : "This is a test document",
    
     …….
    
     …….
    }

     

    Following are the site links which helped us to fix this issue:

    https://sharepoint.stackexchange.com/questions/160779/sharepoint-rest-api-c-update-document-metadata

    https://sharepoint.stackexchange.com/questions/234408/rest-api-for-adding-metadata-to-folder 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 293

#2
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 223 Most Valuable Professional

Last 30 days Overall leaderboard