Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi
I'm trying to pull the Token from Mercado Livre by Api inside Power Query, but without result I've already created a previous topic, but I thought it had resolved, but it hasn't been resolved, this is the code I'm using:
let
api_url = "https://api.mercadolibre.com/",
token_path = "oauth/token",
ClientID = "---",
ClientSecret = "---",
code = "---",
redirect_uri = "---",
EncodedCredentials = Binary.ToText(Text.ToBinary(ClientID & ":" & ClientSecret & ":" & code & ":" & redirect_uri), BinaryEncoding.Base64),
Token_Response = Json.Document(Web.Contents(api_url,
[
RelativePath = token_path,
Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=code],
Content=Text.ToBinary("grant_type=authorization_code")
]
)
)
in
It displays the following error:
DataSource.Error: Web.Contents failed to get content from 'https://api.mercadolibre.com/oauth/token' (400): Bad Request
Detalhes:
DataSourceKind=Web
DataSourcePath=https://api.mercadolibre.com/oauth/token
Url=https://api.mercadolibre.com/oauth/token
Follows the material that the API provider makes available:
curl -X POST \
-H 'accept: application/json' \
-H 'content-type: application/x-www-form-urlencoded' \
'https://api.mercadolibre.com/oauth/token' \
-d 'grant_type=authorization_code' \
-d 'client_id=$APP_ID' \
-d 'client_secret=$SECRET_KEY' \
-d 'code=$SERVER_GENERATED_AUTHORIZATION_CODE' \
-d 'redirect_uri=$REDIRECT_URI'
Can someone help me with this code, I don't know what I can do to work
Thanks
Vinicius
Solved! Go to Solution.
instead of
Content=Text.ToBinary("grant_type=authorization_code")
you need to write
Content=Text.ToBinary("grant_type=authorization_code,client_id=app_id,client_secret=key,code=auth,redirect_uri=redirect")
of course with the appropriate substitutions.
You can always test your API call at https://reqbin.com/
instead of
Content=Text.ToBinary("grant_type=authorization_code")
you need to write
Content=Text.ToBinary("grant_type=authorization_code,client_id=app_id,client_secret=key,code=auth,redirect_uri=redirect")
of course with the appropriate substitutions.
You can always test your API call at https://reqbin.com/
your Content parameter needs to contain all five key/value pairs (like the CURL call), not just grant_type.
(You have an EncodedCredentials step but you don't use the result anywhere)
Hi
I haven't been able to make it work yet, I'm suspicious that this way the API doesn't work, but I'm not managing to develop another one, this part is not my specialty