cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Microsoft
Microsoft

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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

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

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 

View solution in original post

3 REPLIES 3
Highlighted
Community Support
Community Support

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

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#...

 

 

Best regards,

Kris

 

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Microsoft
Microsoft

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

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.

 

Highlighted
Microsoft
Microsoft

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

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 

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Users online (6,731)