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 / how to create a pdf fi...
Power Automate
Unanswered

how to create a pdf file using SharePoint HTTP request

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi All, This is regarding "creating a pdf file in SharePoint Library using "send http request of SharePoint". Below is the action I am using.

 

Ref_Image.png

 

 

 

Content-Length: length(variables('varContent'))
Uri: _api/web/GetFolderByServerRelativeUrl('students')/Files/add(url='a.txt',overwrite=true)
Content: body('pmw')?['$content']

 

 

 

PMW - Populate a Microsoft Word template

 

For testing purpose - I was trying to create .txt file:

 

Error Message:

 

Spoiler (Highlight to read)
{
  "error": {
    "code"500,
    "source""flow-apim-msmanaged-na-westus2-01.azure-apim.net",
    "clientRequestId""4776e0da-1c7d-40a0-98d8-c30044bc33cd",
    "message""BadGateway",
    "innerError": {
      "status"500,
      "message""Bytes to be written to the stream exceed the Content-Length bytes size specified.\r\nclientRequestId: 4776e0da-1c7d-40a0-98d8-c30044bc33cd",
      "errors": []
    }
  }
}
{  "error": {    "code": 500,    "source": "flow-apim-msmanaged-na-westus2-01.azure-apim.net",    "clientRequestId": "4776e0da-1c7d-40a0-98d8-c30044bc33cd",    "message": "BadGateway",    "innerError": {      "status": 500,      "message": "Bytes to be written to the stream exceed the Content-Length bytes size specified.\r\nclientRequestId: 4776e0da-1c7d-40a0-98d8-c30044bc33cd",      "source": "https://sharepointonline-eus2.azconn-eus2.p.azurewebsites.net/datasets/https%253A%252F%252FABCD.sharepoint.com%252Fsites%252FTEAMAPPS/httprequest",      "errors": []    }  }}
Size of the word document: 25KB

 

 

Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,502 Most Valuable Professional on at

    Hi @Anonymous,

     

    If I understand correctly you just want to create a .txt file.

     

    Try and use this approach. I believe all those headers are not required to create a .txt file.

    createtextfile_postrequest.png

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @Expiscornovus, thank you for the update. Yeah, I am unable to create the file only with Content-Type:application/json. But the issue is with pdf files. able to create PDF files but those are not correctly getting created, any thoughts on this?

  • Expiscornovus Profile Picture
    33,502 Most Valuable Professional on at

    Hi @Anonymous,


    You could use a Populate a word template with a text control and input that with text and use a convert file action to generate a pdf. Maybe this is also approach which is useful for you?

     

    1. Use a populate word template to populate a docx file with your text. I added a HTMLTable text control via the Word Developer options. You could populate that control with text of your flow. In this case I am using some random text (Testing). populatewordtemplatewithtext.png

     

    2. Create a temporary docx file in OneDrive

    createworddocument.png

    3. Convert the content of the docx to pdf in OneDrive

    convertfilecontenttopdf.png

     

    4. Create a pdf file in a SharePoint location

    createpdffileinsharepoint.png

     

     

    More details about this approach can be found in this nice blog from Jon Levesque: 

    https://flow.microsoft.com/nl-nl/blog/intermediate-flow-of-the-week-create-pdf-invoices-using-word-templates-with-microsoft-flow/

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
David_MA Profile Picture

David_MA 86 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 55

#3
Ellis Karim Profile Picture

Ellis Karim 53 Super User 2026 Season 1

Last 30 days Overall leaderboard