Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SCHGroupDA
Regular Visitor

Error making HTTP POST requests with XML body in Web.Contents function

I am having difficulty finding product documentation on Power Query that breaks down how to construct the body parameter within the Web.Contents() function when passing XML into the body of the HTTP POST request. I receive an error message of "We cannot convert a value of type Table to type Records".

 

For example, I have a set of 5 environmental variables that I want to pass into the xml before passing xml into function:

senderid = "Someusername";
senderidpassword = "somepassword";
userid = "anotherusername";
useridpassword = "anotherpassword";
companyid = "acompanyname";

I then want to pass in above variables to XML:

  "<?xml version=""1.0"" encoding=""UTF-8""?>
        <request>
          <control>
            <senderid>"&senderid&"</senderid>
            <password>"&password&"</password>
            <controlid>{{$timestamp}}</controlid>
            <uniqueid>true</uniqueid>
            <dtdversion>3.0</dtdversion>
            <includewhitespace>false</includewhitespace>
          </control>
          <operation>
            <authentication>
              <login>
                <userid>"&userid&"</userid>
                <companyid>"&companyid&"{{temp_slide_in}}</companyid>
                <password>"&password&"</password>
              </login>
            </authentication>
            <content>
              <function controlid=""{{$guid}}"">
                <getAPISession />
              </function>
            </content>
          </operation>
        </request>"

And I want to pass above XML into the Web.Contents() function code below:

let
url = "https://examplewebsite.com",
    body  = [Above XML formatted to pass into Web.Contents() function] ,
    Parsed_XML = XML.Document(body),
    BuildQueryString = Uri.BuildQueryString(Parsed_XML),
    Source = XML.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/xml"], Content = Text.ToBinary(BuildQueryString) ] ))
in
    Source;

Any advice on how I need to pass in the variables to XML & then structure the XML body portion of the Web.Contents function?

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @SCHGroupDA 

How about "Xml.Tables" instead of "Xml.Documents"?

You could use Xml Driver as a workaround.

https://zappysys.com/blog/call-soap-api-power-bi-read-xml-web-service-data/#Import_XML_SOAP_Web_Serv...

 

Best Regards

Maggie

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors