Forum Discussion

SarahAlsterspre's avatar
3 years ago

Pull Data from timebutler

Hey,

 

I want to get some data from our employees absences from the tool we use called timebutler. Unfortunately they only accept http POST requests and Power BI seems to use GET. I have a link (https://timebutler.de/api/v1/absencesand an API Token. According to the documentary a  CSV UTF-8 coded will be provided. I also have to set a parameter for the year (YYYY). So my question now is... How.. 😄 I am a newbie regarding these M queries so I am looking forward to your help for generating a customized query in M.

 

Greets

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi SarahAlsterspre ,

     

    1. In Power BI Desktop, go to Home > Advanced Editor.
    2. Replace the existing code with the following M query:

     

    let
        apiToken = "your_api_token_here",
        year = "2022",
        url = "https://timebutler.de/api/v1/absences",
        headers = [
            #"Content-Type" = "application/json",
            #"Authorization" = "Bearer " & apiToken
        ],
        options = [
            Headers = headers,
            Content = Text.ToBinary("year=" & year),
            ManualStatusHandling = {400, 404}
        ],
        response = Web.Contents(url, options),
        statusCode = Value.Metadata(response)[Response.Status],
        result = if statusCode = 200 then
                    Csv.Document(response, [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.None])
                 else
                    error "Request failed with status code: " & Text.From(statusCode)
    in
        result

     

    1. Replace with your actual API token.

    Please refer to the following document for more information.

    Power Query Web connector - Power Query | Microsoft Learn

    Pull data from API using POST method in Power BI - Microsoft Fabric Community

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.