Forum Discussion
A generic REST API connector?
- Anonymous5 years ago
Hi mrgou,
You can try to use the following M query code if they work on your side:
let rooturl = "https://myserver.com/", //profile id oath_oidc_profile_id = "xxxxxx", //access token from your portal configurations token = "xxxxxxx", relativeURL = "auth/oauth/session/" & oath_oidc_profile_id, //connect to server GetJson = Web.Contents( rooturl, [ Headers = [ #"Authorization" = "Bearer" & token, #"Content-Type" = "application/x-www-form-urlencoded" ], RelativePath = relativeURL ] ), //'session Id' for advanced operation sessionId = Json.Document(GetJson)[sessionId], Source = Web.Contents( rooturl, [ Headers = [ #"Authorization" = "Bearer" & token, #"Content-Type" = "application/x-www-form-urlencoded" ], RelativePath = "xxxx/xxxxx/xxxxx", Content = Text.ToBinary("client_id=" & sessionId) ] ) in SourceIf the above not help, you can also take a look at the following link about pull data from the rest API with authentication:
Pull data from a REST API Authentication
Regards,Xiaoxin Sheng
Hi mrgou,
You can try to use the following M query code if they work on your side:
let
rooturl = "https://myserver.com/",
//profile id
oath_oidc_profile_id = "xxxxxx",
//access token from your portal configurations
token = "xxxxxxx",
relativeURL =
"auth/oauth/session/"
& oath_oidc_profile_id,
//connect to server
GetJson =
Web.Contents(
rooturl,
[
Headers = [
#"Authorization" = "Bearer" & token,
#"Content-Type" = "application/x-www-form-urlencoded"
],
RelativePath = relativeURL
]
),
//'session Id' for advanced operation
sessionId = Json.Document(GetJson)[sessionId],
Source =
Web.Contents(
rooturl,
[
Headers = [
#"Authorization" = "Bearer" & token,
#"Content-Type" = "application/x-www-form-urlencoded"
],
RelativePath = "xxxx/xxxxx/xxxxx",
Content = Text.ToBinary("client_id=" & sessionId)
]
)
in
Source
If the above not help, you can also take a look at the following link about pull data from the rest API with authentication:
Pull data from a REST API Authentication
Regards,
Xiaoxin Sheng
Anonymous Thank you for sharing this. I looked into the M reference, and also found a WebAction.Request method that appears to allow using other HTTP methods. I guess I'll have to go ahead and study the language. Unfortunately, I couldn't find any good learning resource, so I'll have to do it the hard way with the specification and reference documentation from Microsoft!
- Anonymous5 years agoNot applicable
HI mrgou,
If you can't find enough code sample/tutorials of power query functions. You can also take a look at Chris Webb's blog, he shares lots of blogs of power query function usage:
Chris Webb's BI Blog # Web.Contents
Regards,Xiaoxin Sheng