Forum Discussion

numersoz's avatar
numersoz
Helper III
7 years ago
Solved

Power Query Open ID and OAuth 2.0 Rest API

Hello, I have a RESTful API where it has two-factor authentication. First, it used my username and password to get a Bearer authentication key using OpenID. After this with the authentication key,...
  • numersoz's avatar
    numersoz
    7 years ago
    let
        token_url = "tokenurl.com",    
        api_base_url = "apiurl.com",
        qry_str = "?myparameter",
    
       body="grant_type=password&client_id=CLIENTID&client_secret=PASSWORD&username=EMAIL&password=PASSWORD",
       Source  = Json.Document(Web.Contents(token_url,
       [ 
         Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
         Content=Text.ToBinary(body)
       ]
       )
       ),
        token = Source[access_token],
    
        data= Json.Document(Web.Contents(api_base_url&qry_str,
       [ 
         Headers = [
                    #"Authorization"="Bearer "&token,#"Content-Type"="application/json"]
         
       ]
       )
       ),  
    in
        data

    I finally got it working with this code. Thanks for the support.