cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

Re: Connect to a Web Service sending parameters

If you click on "Show Error": Is this what you get?

Please send full code.

Please also send link to relevant FB-api-doc.

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Imke Feldmann

How to integrate M-code into your solution -- Check out more PBI- learning resources here -- Performance Tipps for M-queries




emudria Member
Member

Re: Connect to a Web Service sending parameters

DN Member
Member

Re: Connect to a Web Service sending parameters

Hi @emudria. could you please share your code here?

I am having trouble with my API too.

emudria Member
Member

Re: Connect to a Web Service sending parameters

There you go @DN

let
auth_key ="Basic FNekV5WHpNNVpJReFl6VTNZalJpNTM3ZTVhZmEzNTc5YzUxNTlmNDg0N2QzNWI=",
base_url = "https://api.testwebsite.com/",
extension = "0/facebook/metrics",
url = base_url &extension,
header= [#"Authorization" = auth_key,
#"Content-Type" = "application/json; charset=utf-8"],
content1= "{
""date_start"":""2017-10-01"",
""date_end"":""2017-10-30"",
""profiles"":[""id1"",""id2""],
""metrics"":[
""fans_change"",""fans_count_lifetime"",
""insights_engaged_users_count"",
""insights_impressions_by_age_gender_unique"",""insights_impressions"",""insights_impressions_by_paid_non_paid_unique"",
""insights_negative_feedback"",""insights_positive_feedback""
]
}",
webdata1 = Web.Contents(url, [Headers=header,Content = Text.ToBinary(content1)]),
response1 = Json.Document(webdata1)
in
response1

 

Highlighted
DN Member
Member

Re: Connect to a Web Service sending parameters

thanks a lot for your reply!
I manage to make it work in my API using a little bit different code. POST Rest API.
My API needs full URL, and I needed to add timeout parameter. For default, Power BI has a 5 minute timout limit.
The way the timeout duration works is (day,hour,minute,second). So my code below has a 2 hours timeout limit.

 

for authentication, my API uses login password encoded on base 64.

The command #"Authorization" = "base64-encoded user: password" did not work, so I changed to #"Authorization" = "basic dXNlcjpwYXNzd29yZA==". (there is no space after "user:", but ":" and "p" makes a useless emoji... userSmiley Tongueassword)

Where "user: password" equals to "dXNlcjpwYXNzd29yZA==", using https://www.base64encode.org/ to encode/decode.

 

let
url = "http://full.api/url/here/including/all/subfolders",
body = "{""parameter as date"":""2017-10-31"",
""parameter as boolean"":true,
""parameter as number"":3
}",

Source = Json.Document(Web.Contents(url,[
Headers =[#"Content-Type"="application/json", #"Authorization" = "basic "],
Content = Text.ToBinary(body) , Timeout=#duration(0,2,0,0)
]
)),

in
#"Source"

emudria Member
Member

Re: Connect to a Web Service sending parameters

@DN Great if you managed to make it work.

yes, I also changed my userSmiley Tongueass in to 64encode externally and then entered in M.

My API only returns a limited data, so now I am working to paginate it, recursively.

DN Member
Member

Re: Connect to a Web Service sending parameters

nice! once you get it paginated correctly, please share the pagination code here.

thanks!