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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
viniciuscastilh
Frequent Visitor

API IN POWER BI POST

Good afternoon

I need to integrate the Mercado Livre api into Power BI, I need to make a Post inside the Body
But I never made a Post on Power Bi, could you help me?

The basis for calling the API is as follows:

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'


I tried to develop the following code, but still the Token still does not return as needed

 

 

let
body = "
{
""grant_type"": ""authorization_code"",
""client_id"": ""--"",
""client_secret"": ""--"",
""code"": ""--"",
""redirect_uri"": ""--""
}
",

getToken =
Json.Document(
Web.Contents (
"https://api.mercadolibre.com",
[
RelativePath = "/oauth/token",
Content=Text.ToBinary(body),
Headers = [
#"ContentType" = "application/json"
]
]
)
)
in body


Could you help me?



 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @viniciuscastilh 

 

Does that cURL POST work?

 

The general form for making a POST in PBI/PQ is

 

Source = Json.Document(Web.Contents(url,[
Headers = [#"Content-Type"="application/json"],
Content = Text.ToBinary(body)
]
))

 

 

In your particular case try this

 

let
    api_url = "https://api.mercadolibre.com/",
    token_path = "oauth/token",
    ClientID = "xxxxxxxx",
    ClientSecret = "xxxxxxxx",
    
    EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & ClientSecret), BinaryEncoding.Base64),
    
    Token_Response  = Json.Document(Web.Contents(api_url,
    [ 
      RelativePath = token_path,
      Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
      Content=Text.ToBinary("grant_type=authorization_code")
    ]
    )
    )
in
    Token_Response

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

7 REPLIES 7
PhilipTreacy
Super User
Super User

Hi @viniciuscastilh 

 

Does that cURL POST work?

 

The general form for making a POST in PBI/PQ is

 

Source = Json.Document(Web.Contents(url,[
Headers = [#"Content-Type"="application/json"],
Content = Text.ToBinary(body)
]
))

 

 

In your particular case try this

 

let
    api_url = "https://api.mercadolibre.com/",
    token_path = "oauth/token",
    ClientID = "xxxxxxxx",
    ClientSecret = "xxxxxxxx",
    
    EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & ClientSecret), BinaryEncoding.Base64),
    
    Token_Response  = Json.Document(Web.Contents(api_url,
    [ 
      RelativePath = token_path,
      Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
      Content=Text.ToBinary("grant_type=authorization_code")
    ]
    )
    )
in
    Token_Response

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks

Perfect solution, I just had to make adaptations but it worked, thank you very much!

Regards

Vinicius

Anonymous
Not applicable

Hi again, could you please paste the query that worked for you to connect to the Mercadolibre API with PBI??

Anonymous
Not applicable

Hi Vinicius, I'm looking to do exactly the same thing that you are doing here. Could you please help me? I've done a registry of app on Meli and have the Id and Secret... but still can't connect...!!!

Don't forget that you have to base64 encode the client id and secret as shown in the solution.

Anonymous
Not applicable

Could you please help me with this??

lbendlin
Super User
Super User

When you POST you normally push content to the server. In Power Query you do that by providing a value for the Content parameter (usually by packing it with JSON.FromValue() ).  That will automatically convert the GET call to a POST call.

 

Web.Contents - PowerQuery M | Microsoft Docs

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors