cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
retrofuture
Regular Visitor

Send http request to SharePoint error

Hi All, 

I'm trying to build a flow which takes the content from a word file and creates a SitePage with this content. The flow passes with no errors and the page is created, however the content stays unchanged - it's the same as the content of the template page. Tried to change few of the page details by hand by hardcoding some data - again no changes. I'm using this video https://www.youtube.com/watch?v=QtBqeEEOgdE as a guide. The only difference is that my trigger is when a file is created. 

Untitled2.pngUntitled1.jpgUntitled.jpgUntitled3.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
MarvinBangert
Solution Sage
Solution Sage

Hey @retrofuture 

took me a while to create this flow and getting everything running on my side. I guess the action "Get file content" does not return what you are looking for, the content is like in an encoded string, which is not usable for the next steps. Also, I cannot find any dynamic content from the "Get file content" within your last HTTP to update the information within the body, did you tried to use some hardcoded values first?

 

I found a fantastic article that describes how to get the content of a Word document using Power Automate and OneDrive: https://www.tachytelic.net/2021/05/power-automate-extract-text-from-word-docx-file/ . I recreated this using SharePoint, so that you do not need to use OneDrive, it looks like this:

Image 028.png

 

Extract folder (as in the blog post, docx is something like a zip that you can extract, inside this you will find a xml with your actual content):

 

Site Address: <Your SharePoint Site>
Source File Path: @triggerOutputs()?['body/{FullPath}']
Destination Folder Path: /Temp/@{triggerOutputs()?['body/{Name}']}
Overwrite Flag: Yes

 

 

Get file content using path (the path to the xml is always the same, we only use the name of the trigger file to separate different documents):

 

Site Address: <Your SharePoint Site>
File Path: /Temp/@{triggerOutputs()?['body/{Name}']}/word/document.xml

 

 

Compose 2:

 

@{xpath(xml(outputs('Get_file_content_using_path')?['body']), '//*[name()=''w:t'']/text()')}

 

 

The output of the "get file content using path" is the full xml document, we only need our actual content, so we need to convert the output into XML and then parse the xml using xpath(), the XPath expression in the end will evaluate the XML and returns the nodeset.

 

After this, the compose should already return your document content.

Within the innerHTML from the SharePoint Page template you created in the very first beginning, you will find the structure for our HTML, in my case just a paragraph tag.

Image 030.png

The return of my XML parsing is already in a pretty good format:

 

[
  "Name: Marvin Bangert",
  "Job Title: Consultant",
  "Department: Consulting"
]

 

 

Apply to each:

 

Select an output from previous steps: @{outputs('Compose_2')}

 

 

Within the apply to each, use a "Append to string variable" (Create an empty variable string in the beginning of the flow:

 

Name: varString
Value: <p>@{items('Apply_to_each')}</p>

 

 

The apply to each adds the paragraph tag to each item extracted from the XML.

 

Then you go on with your HTTP, that what already works on your side. In the last HTTP SharePoint, within your body, you need to look for your "innerHTML" and change the content with your new generated HTML. Whatever you maybe have (like pictures etc.) also needs to be changed.

 

Afterwards it should work and adds the content from your document to a SharePoint page.

 

Hope this helps you

Best regards
Marvin

If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

View solution in original post

5 REPLIES 5
retrofuture
Regular Visitor

Am I using wrong endpoint?

retrofuture
Regular Visitor

So I tried to execute the final https request manually and got the following error""The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again." It appears that the x digest header should be added to the request, however I have no Idea how to do that and also I wonder why there was no such error in the youtube video. Any Ideas or suggestions are welcome.

MarvinBangert
Solution Sage
Solution Sage

Hey @retrofuture 

took me a while to create this flow and getting everything running on my side. I guess the action "Get file content" does not return what you are looking for, the content is like in an encoded string, which is not usable for the next steps. Also, I cannot find any dynamic content from the "Get file content" within your last HTTP to update the information within the body, did you tried to use some hardcoded values first?

 

I found a fantastic article that describes how to get the content of a Word document using Power Automate and OneDrive: https://www.tachytelic.net/2021/05/power-automate-extract-text-from-word-docx-file/ . I recreated this using SharePoint, so that you do not need to use OneDrive, it looks like this:

Image 028.png

 

Extract folder (as in the blog post, docx is something like a zip that you can extract, inside this you will find a xml with your actual content):

 

Site Address: <Your SharePoint Site>
Source File Path: @triggerOutputs()?['body/{FullPath}']
Destination Folder Path: /Temp/@{triggerOutputs()?['body/{Name}']}
Overwrite Flag: Yes

 

 

Get file content using path (the path to the xml is always the same, we only use the name of the trigger file to separate different documents):

 

Site Address: <Your SharePoint Site>
File Path: /Temp/@{triggerOutputs()?['body/{Name}']}/word/document.xml

 

 

Compose 2:

 

@{xpath(xml(outputs('Get_file_content_using_path')?['body']), '//*[name()=''w:t'']/text()')}

 

 

The output of the "get file content using path" is the full xml document, we only need our actual content, so we need to convert the output into XML and then parse the xml using xpath(), the XPath expression in the end will evaluate the XML and returns the nodeset.

 

After this, the compose should already return your document content.

Within the innerHTML from the SharePoint Page template you created in the very first beginning, you will find the structure for our HTML, in my case just a paragraph tag.

Image 030.png

The return of my XML parsing is already in a pretty good format:

 

[
  "Name: Marvin Bangert",
  "Job Title: Consultant",
  "Department: Consulting"
]

 

 

Apply to each:

 

Select an output from previous steps: @{outputs('Compose_2')}

 

 

Within the apply to each, use a "Append to string variable" (Create an empty variable string in the beginning of the flow:

 

Name: varString
Value: <p>@{items('Apply_to_each')}</p>

 

 

The apply to each adds the paragraph tag to each item extracted from the XML.

 

Then you go on with your HTTP, that what already works on your side. In the last HTTP SharePoint, within your body, you need to look for your "innerHTML" and change the content with your new generated HTML. Whatever you maybe have (like pictures etc.) also needs to be changed.

 

Afterwards it should work and adds the content from your document to a SharePoint page.

 

Hope this helps you

Best regards
Marvin

If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

View solution in original post

retrofuture
Regular Visitor

Hi Marvin, in the end I was able to extract the data from a word document but as a plain string and the page had the content as text and no formatting whatsoever. My mistake was that I was targeting the wrong page ID. Your solution looks more complete and I'll definitely give it a try. Thanks!

MarvinBangert
Solution Sage
Solution Sage

Hey @retrofuture 

because of the complexity of this, I also wrote an article about this to help others if they have similar things to achieve: Power Automate - Create SharePoint Page from Word document | CLOUD KUMPEL

This Blog post is more in detail, maybe it will also help you.


Best regards
Marvin

If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

Blog: Cloudkumpel

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,742)