Forum Discussion

mrgou's avatar
mrgou
Frequent Visitor
5 years ago
Solved

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...
  • Anonymous's avatar
    Anonymous
    5 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
        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