none
Web.Contents POST query in PowerBI Desktop RRS feed

  • Question

  • Hi,

    I am trying to call a REST API to retrieve an authentication token from Maas360 using PowerBI Desktop. the API reference guide says that I need to use "application/xml" Content-Type and an XML body with credentials and other corporate identification details. This is my query

    let
       body = Text.ToBinary("<authRequest><maaS360AdminAuth><billingID>XXX</billingID><platformID>XXX</platformID><appID>XXX</appID><appVersion>XXX</appVersion><appAccessKey>XXX</appAccessKey><userName>XXX</userName><password>XXX</password></maaS360AdminAuth></authRequest>"),
       actualUrl = "https://services.m3.maas360.com/auth-apis/auth/1.0/authenticate/XXX/",
       options = [Headers =[#"Content-type"="application/xml",Content=body]],
       result = Web.Contents(actualUrl, options)
     in
         result

    This returns : Expression.Error: We cannot convert a value of type Binary to type Text.

    If I try to remove the Text.ToBinary function (that I saw in pretty much all examples on the internet so far), then the call fails :(

    DataSource.Error: Web.Contents failed to get contents from 'https://services.m3.maas360.com/auth-apis/auth/1.0/authenticate/XXX/' (500): Internal Server Error

    I am able to do this in powershell using Invoke-RestMethod, also, if I retrieve the auth token manually, I'm able to do GET queries to that API which makes me think that the error resides in my query above. Any idea ? 


    David Sebban | Nelite North America | My Blog : http://dsebban.wordpress.com | Follow me on twitter : http://twitter.com/davidsebban

    Monday, April 11, 2016 2:24 PM

Answers

  • I found my error, I put the Content in the Headers ... the correct syntax is

    let
       body = Text.ToBinary("<authRequest><maaS360AdminAuth><billingID>XXX</billingID><platformID>XXX</platformID><appID>XXX</appID><appVersion>XXX</appVersion><appAccessKey>XXX</appAccessKey><userName>XXX</userName><password>XXX</password></maaS360AdminAuth></authRequest>"),
       actualUrl = "https://services.m3.maas360.com/auth-apis/auth/1.0/authenticate/XXX/",
       options = [
          Headers =[#"Content-type"="application/xml"],
          Content=body
       ],
       result = Web.Contents(actualUrl, options)
     in
         result


    David Sebban | Nelite North America | My Blog : http://dsebban.wordpress.com | Follow me on twitter : http://twitter.com/davidsebban

    Monday, April 11, 2016 4:04 PM

All replies

  • "Content" is not a header; it's a separate option to Web.Contents. It should be:

       options = [Headers =[#"Content-type"="application/xml"], Content=body],

    Monday, April 11, 2016 3:47 PM
  • I found my error, I put the Content in the Headers ... the correct syntax is

    let
       body = Text.ToBinary("<authRequest><maaS360AdminAuth><billingID>XXX</billingID><platformID>XXX</platformID><appID>XXX</appID><appVersion>XXX</appVersion><appAccessKey>XXX</appAccessKey><userName>XXX</userName><password>XXX</password></maaS360AdminAuth></authRequest>"),
       actualUrl = "https://services.m3.maas360.com/auth-apis/auth/1.0/authenticate/XXX/",
       options = [
          Headers =[#"Content-type"="application/xml"],
          Content=body
       ],
       result = Web.Contents(actualUrl, options)
     in
         result


    David Sebban | Nelite North America | My Blog : http://dsebban.wordpress.com | Follow me on twitter : http://twitter.com/davidsebban

    Monday, April 11, 2016 4:04 PM