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
Super User
Super User

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

6 REPLIES 6
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
Super User
Super User

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.

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
Super User
Super User

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

mjburley
Resolver II
Resolver II

@MarvinBangert  Thanks for the detail in this article, which I followed and works well.

In my case I am trying to extract different strings out of the Word (template) file, so instead of the w:t text

//*[name()=''w:t'']/text()')

I am trying to get the values from:

<w:tag w:val="Organisation"/><w:id w:val="2094280072"/>

but I cannot work out how to refer to these with xpath. I've tried various ways but always get an empty array back - examples:

xpath(xml(body('Get_file_content_using_path')), '//@w:tag/@w:val/text()')
xpath(xml(body('Get_file_content_using_path')), '//*[@'w:id']')

Etc.

Any ideas how to refer to these elements?

Thanks, Mark

Full chunk of XML:

    <w:sdtPr>
        <w:rPr>
            <w:rFonts w:cs="Tahoma"/>
            <w:color w:val="000000"/>
            <w:szCs w:val="28"/>
        </w:rPr>
        <w:alias w:val="Organisation"/>
        <w:tag w:val="Organisation"/>
        <w:id w:val="1938709613"/>
        <w:placeholder>
            <w:docPart w:val="057F9AEFB56E42B38153A11E699DDE9F"/>
        </w:placeholder>
        <w:text/>
    </w:sdtPr>

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,496)