Forum Discussion

viniciuscastilh's avatar
viniciuscastilh
Frequent Visitor
5 years ago
Solved

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 ...
  • PhilipTreacy's avatar
    5 years ago

    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