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

Notifications

Announcements

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

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,402 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/

  • Community Power Platform Member Profile Picture
    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,402 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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 245 Super User 2025 Season 2

#2
Expiscornovus Profile Picture

Expiscornovus 207 Most Valuable Professional

#3
trice602 Profile Picture

trice602 185 Super User 2025 Season 2

Last 30 days Overall leaderboard