The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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?
Solved! Go to Solution.
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
Proud to be a Super User!
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
Proud to be a Super User!
Thanks
Perfect solution, I just had to make adaptations but it worked, thank you very much!
Regards
Vinicius
Hi again, could you please paste the query that worked for you to connect to the Mercadolibre API with PBI??
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.
Could you please help me with this??
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.