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
CoolP
Regular Visitor

POSTing an XML file/contents as a request to an API endpoint

Hello Experts,

 

I'm able to pass an XML file (multipart/form-data) to an API endpoint paramter (xmlRequest) using the POST method and get the response in a csv file/records.

 

The above worked using Postman and also via Python.

 

How to do this in Power Query / M?

 

I have tried to do it using "Web.Contents" method and by passing the XML data to the "Content" attribute with no luck.

 

Thanks

CoolP

1 REPLY 1
zoloturu
Memorable Member
Memorable Member

Hello @CoolP,

 

I have an example of POST request:

 

 

let
    strBody = "[{""Text"":""" & Text.Replace(varInputText,"""","'") & """}]",
    Source = Web.Contents("https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=en", [Headers=[#"Ocp-Apim-Subscription-Key"="11111111111111111", #"Content-type"="application/json"], Content=Text.ToBinary(strBody)])
in
    Source

The logic here is:

 

* to use Content=Text.ToBinary(), so then your GET request will be transformed to POST

* to have strBody variable which stores content you want to send via POST request

Some information about this approach - https://blog.crossjoin.co.uk/2014/04/19/web-services-and-post-requests-in-power-query/

 

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

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.