Forum Discussion
How to get data from a SOAP WS with Power BI
Actually, the next step of my project was this, because I'm going to publish this and I do not find it interesting to keep calling files to make the call.
So now I've put the XML inside PowerQuery.
Because I'm going to use the token return on other calls, it's unfeasible that it stays on file.
It looks like this:
let
Source = Xml.Tables(Web.Contents("https://advertising.criteo.com/API/v201305/AdvertiserService.asmx?WSDL"
,[Content=Text.ToBinary("<soapenv:Envelope xmlns="&Character.FromNumber(34)&"https://advertising.criteo.com/API/v201305"&Character.FromNumber(34)&" xmlns:soapenv="&Character.FromNumber(34)&"http://schemas.xmlsoap.org/soap/envelope/"&Character.FromNumber(34)&">
<soapenv:Body>
<clientLogin>
<username>[email protected]</username>
<password>aaaaaaaa</password>
</clientLogin>
</soapenv:Body>
</soapenv:Envelope>"),Headers=[#"Accept-Encoding"="gzip,deflate", #"Content-Type"="text/xml;charset=UTF-8"]]))
in
Source
Might want to consider using single quotes in your xml. Or if you need those double quoutes try using #(0022) in your query it is equivalent to Character.FromNumber(34), plus you don't need to concatenate them.
instead of
"<soapenv:Envelope xmlns="&Character.FromNumber(34)&"https"
try
"<soapenv:Envelope xmlns=#(0022)https"
Plus, have you considered using Text.Format to keep password and username out of the XML qurey builder?
- hugoberry9 years ago
Responsive Resident
Text.Format would help you to store username password in some parameter and pass it to the XML builder routine. Something like this:
Text.Format("longxml<username>#[username]</username>
<password>#[password]</password>
more xml",[username = parameter_username, password= parameter_password]) - Pubudu9 years agoRegular Visitor
Can you please share your next SOAP request with dummy key. Just to check how should I construct. I was trying as bellow.
let
Source = Xml.Tables(Web.Contents("https://api1.xxx.com/services/MainService?wsdl"
,[Content=Text.ToBinary("<x:Envelope xmlns:x="&Character.FromNumber(34)&"http://schemas.xmlsoap.org/soap/envelope/"&Character.FromNumber(34)&" xmlns:ser="&Character.FromNumber(34)&"http://services"&Character.FromNumber(34)&">
<x:Header/><x:Body>
<ser:getHistory>
<ser:sessionId>xxxxxxxxxx</ser:sessionId>
<ser:entityTypeId>4</ser:entityTypeId>
<ser:startYYYYMMDD>2016/08/04 05:49:05</ser:startYYYYMMDD>
<ser:endYYYYMMDD>2016/08/17 07:33:46</ser:endYYYYMMDD>
<ser:showRepeatingPerDay>false</ser:showRepeatingPerDay>
<ser:simpleDateFormat>yyyy/MM/dd HH:mm:ss</ser:simpleDateFormat>
</ser:getHistory>
</x:Body>
</x:Envelope>"),Headers=[#"Accept-Encoding"="gzip,deflate", #"Content-Type"="text/xml;charset=UTF-8"]]))
in
Source
But this start giving following error.
DataSource.Error: Web.Contents failed to get contents from 'https://api1.innotas.com/services/MainService?wsdl' (500): Internal Server Error
Details:
DataSourceKind=Web
DataSourcePath=https://api1.innotas.com/services/MainService
Url=https://api1.innotas.com/services/MainService?wsdl
I was using Anonymous as credentials to get the session id which was working. Can u please guide me? - juliovidigal9 years ago
Advocate I
Thank you for the tip.
I will certainly use it in other scenarios. In this scenario, I only use username and password at that moment, then I use the Token that I get from this authentication, and that email and password will not change.Thank you
- juliovidigal9 years ago
Advocate I
Good evening. I used your tips, and they really worked, the formatting was simpler. Thanks for the days. Regarding using the text.format, I really did not understand how to apply this. The idea is to receive this as a parameter? So you do not get stuck in the code? Thank you
- juliovidigal9 years ago
Advocate I
Good morning, sorry for the delay.
Is this the first call, or do you want to use her return to populate the sessionId?
- rodolfo_sgl9 years agoFrequent Visitor
Ok,
this will probably solve my request problem:
let
Source = Xml.Tables(Web.Contents("https://myWSDL"
,[Content=File.Contents("PathToMyXmlfile.xml"),Headers=[#"Accept-Encoding"="gzip,deflate", SOAPAction="", #"Content-Type"="text/xml;charset=UTF-8"]]))
in
SourceBut the response is a json file. There's a way to parse it?
- juliovidigal9 years ago
Advocate I
In the visual layer of PowerBI, you have to give a parse ..
But if it is your case, I have a scenario that I call an API that returns a json file, and I treat it as follows ..
let
SourceTESTE = "http://mediamanager.voxus.tv/api/?method=detailed&token=XXXXXX&start_date=" & "20/11/2016" & "&end_date=" & "30/12/2050",
Fonte = Json.Document(Web.Contents(SourceTESTE ))......
- ZappySys8 years ago
Helper I
Hi check below blog post. It explains concepts of calling any Web service in Power BI. Basically, you need to craft SOAP Body for POST request and need to supply credentials / http headers (e.g. Content-Type, SOAPAction )
https://zappysys.com/blog/call-soap-api-power-bi-read-xml-web-service-data/
Configure ZappySys XML ODBC DSNPreview SOAP API query using ZappySys XML DriverImport SOAP API data in Power BI using ODBC connection
Sample SQL to import SOAP Web Service Data in Power BI
SELECT * FROM $ WITH( src='http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx' ,DataConnectionType='HTTP' ,CredentialType='Basic' --OR SoapWss ,SoapWssPasswordType='PasswordText' ,UserName='myuser' ,Password='pass$$w123' ,Filter='$.soap:Envelope.soap:Body.GetHolidaysAvailableResponse.GetHolidaysAvailableResult.HolidayCode[*]' ,ElementsToTreatAsArray='HolidayCode' ,RequestMethod='POST' ,Header='Content-Type: text/xml;charset=UTF-8 || SOAPAction: "http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysAvailable"' ,RequestData=' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hol="http://www.holidaywebservice.com/HolidayService_v2/"> <soapenv:Header/> <soapenv:Body> <hol:GetHolidaysAvailable> <!--type: Country - enumeration: [Canada,GreatBritain,IrelandNorthern,IrelandRepublicOf,Scotland,UnitedStates]--> <hol:countryCode>UnitedStates</hol:countryCode> </hol:GetHolidaysAvailable> </soapenv:Body> </soapenv:Envelope>' )