Forum Discussion

SomeDataDude's avatar
SomeDataDude
Advocate I
3 years ago
Solved

Connecting API

Hello,   I've read through several posts here but can't figure it out. I want to realize an API connection in Power BI. I have a GET API and a POST API. I can't get both to work. For the POST API I...
  • SomeDataDude's avatar
    SomeDataDude
    3 years ago

    I have found the solution. The following M code works for the API:

     

    let
    content = "{
                ""mode"" : ""raw"",
                ""ColCoCode"": ""00"",
                ""PayerNumber"" : ""AA00000000"",
                ""InvoiceStatus"": ""A"",
                ""FromDate"":""2021-12-12"",
                ""PageSize"":""-1""
    }",
    
    Source = Json.Document(Web.Contents("https://url.api",
                           [Headers=[#"Authorization"="Basic****", 
                                     #"apikey" = "****", 
                                     #"ContentType"="application/json"], 
                                      
                            ManualStatusHandling = {404, 400},
    
    Content=Text.ToBinary(content)]))
    
    in
    Source