Forum Discussion
numersoz
7 years agoHelper III
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,...
- 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 dataI finally got it working with this code. Thanks for the support.
tonmcg
7 years agoResolver II
Can you provide a screenshot of the error you're receiving? And can you remove the Keep-Alive parameter?
Here are a few things to check:
- What's the data type of the token variable? Is it a text value?
- Is the Url for the endpoint constructed correctly? Generally, REST-ful APIs require query parameters to be appended to the endpoint via a question mark ('?'), like api_base_url.com?get_this_data. I don't see a question mark anywhere in your Url.
- What data format does the endpoint expect? I suggest adding Accept = "application/json" to the 'Headers' record.
numersoz
7 years agoHelper III
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
dataI finally got it working with this code. Thanks for the support.