Forum Discussion
Connect to a Web Service sending parameters
- Anonymous9 years ago
got my query working.
Thanks everyone.
If you click on "Show Error": Is this what you get?
Please send full code.
Please also send link to relevant FB-api-doc.
got my query working.
Thanks everyone.
- Anonymous8 years agoNot applicable
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 - Anonymous8 years agoNot applicable
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... user:password)
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" - Anonymous8 years agoNot applicable
Hi Anonymous. could you please share your code here?
I am having trouble with my API too.
- Anonymous8 years agoNot applicable
Anonymous Great if you managed to make it work.
yes, I also changed my user:pass 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.
- Anonymous8 years agoNot applicable
nice! once you get it paginated correctly, please share the pagination code here.
thanks!
- Anonymous5 years agoNot applicable
Hi,
I am trying to connect Power BI to the Spotify API, but somehow struggling to get it work.
Trying to use some code of this thread, but ending up with the following error message:
DataSource.Error: Web.Contents failed to get contents from 'https://accounts.spotify.com/api/token?grant_type=client_credentials' (405): Method Not Allowed
Details:
DataSourceKind=Web
DataSourcePath=https://accounts.spotify.com/api/token
Url=https://accounts.spotify.com/api/token?grant_type=client_credentials
The code I used was:let
url="https://accounts.spotify.com/api/token?grant_type=client_credentials",
auth_key = "BASIC <Base64encoded clientID and secret",
header= [#"Authorization" = auth_key,
#"Content-Type" = "application/json; charset=utf-8"],webdata = Web.Contents(url , [Headers=header]),
response = Json.Document(webdata)
in
responseAny suggestions on how to make this work?
Thanks!!!
- navneet05124 years agoHelper III
let
Content = "{
"methodType": "details",
"pageNum": "0",
"pageSize": "3",
"searchParameter": [
{
"key": "order_number",
"value": "469584336"
},
{
"key": "global_bu_id",
"value": "11"
}
],
"sourceApplication": "MORC"
}",
Source = Json.Document(Web.Contents("https://goss-csvc-prod.us.mac.com/gossv3/purchase/search/",[Content=Text.ToBinary(content)]))
in
SourceGetting error "Token comma expected"
- ImkeF4 years agoCommunity Champion
Hello navneet0512 ,
you must escape the quotes and also regard that M is case sensitive. So the correct code would look like so:let Content = "{ ""methodType"": ""details"", ""pageNum"": ""0"", ""pageSize"": ""3"", ""searchParameter"": [ { ""key"": ""order_number"", ""value"": ""469584336"" }, { ""key"": ""global_bu_id"", ""value"": ""11"" } ], ""sourceApplication"": ""MORC"" }", Source = Json.Document(Web.Contents("https://goss-csvc-prod.us.mac.com/gossv3/purchase/search/",[Content=Text.ToBinary(Content)])) in Source - navneet05123 years agoHelper III
Agree with above link and solution