Forum Discussion
mrgou
5 years agoFrequent Visitor
A generic REST API connector?
I need to query data from a REST API but couldn't find any appropriate connector, or even a generic connector. Such a connector should be able to handle requests in any HTTP method, manage authentica...
- 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
sherodkeen
3 years agoFrequent Visitor
The code to generate the token seems to work great, except when I use it against an api endpoint where there are so many records that the token eventually expires. It seems that the code only uses the same token over and over.
See my issue here: