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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors