Showing results for 
Search instead for 
Did you mean: 
Resolver I
Resolver I

Bad Gateway Error Creating Item in Document Library

In my scenario, I want my flow to create a document in a library based on a managed content type.  This results in a templatized document that pulls in dynamic values based on the ListItem that backs it.  Here are some details


  • I am using the Create item SharePoint action
  • In the action, I have to type the Library name by hand since I assume it's filtering for Lists only
  • The content type properties do show up
  • When the flow runs I see the following error
    • "status": 502, "message": "To add an item to a document library, use SPFileCollection.Add()

Hoping this is an easy fix or there is a work-around as this is a super easy way to do dynamic document generation through Flow.




Resolver I
Resolver I

Re: Bad Gateway Error Creating Item in Document Library

I think the Create Item action would be a much cleaner way of doing this, however I was able to develop a hacky work-around detailed below:


  1. Instead of Creating a new file, have a clean "template" version of your file ready.
  2. Use the Copy file action to create the new file
  3. Next use the Get items action with a filter query of FileLeafRef eq 'YourNewFileName'.
  4. Initialize a new string variable called FileIdentifier
  5. In an Apply to each loop, use the Update item action to set the content type column values
    1. Also set the FileIdentifier to the Identifier of the Get Item action.  I did this so I could get the contents of the file to send as an attachment in an email.  You could skip this and use the get file contents by path.
  6. Do something with the file.

Again, being able to create the item instead of copying and looping to update it would be much appreciate.






Community Support
Community Support

Re: Bad Gateway Error Creating Item in Document Library

Hi @JoeHerres,


All feature requests and ideas could be posted in Idea forum where others can also vote on it:



Mona Li

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

Helpful resources


August 2020 CYST Winners!

Check out the winners of the recent 'Can You Solve These?' community challenge!


Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.


Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021


Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Users online (5,390)