Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
viniciuscastilh
Frequent Visitor

Problem Api

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

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

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/ 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

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/ 

lbendlin
Super User
Super User

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.