How to access Clockify API through Power Query

大城市里の小女人 提交于 2019-12-25 01:08:50

问题


I am trying to get my time entries from Clockify API directly via Power Query to Excel. I use the following code in the Power Query:

= Web.Contents("https://api.clockify.me/api/workspaces/ID of my workspace/timeEntries/", [
 Query=[ #"filter"="", #"orderBy"=""],
 ApiKeyName="APIToken"
])

When I then try to run the code I am prompted to enter the Web API authentification, which delivers an error ("English translation: Authentification does not work. Try again") after I enter my correct Web API code see screenshot here

Does anyone have an idea how to solve this?


回答1:


There are two things to keep in mind when making calls to REST-based APIs in Power Query/M:

  1. When using the Web.Contents() function, it's best to pass your API key as a parameter within the request header itself. In your case X-Api-Key should equal to {your API key}.

  2. Use anonymous access to connect to the API. Your screenshot suggests you're trying to connect using "Web API". Clear the value in the "Schlüssel" field and use "Anonym" instead.

Here's a simple example where I return the information about a workspace by workspace ID. (I've masked both my workspace ID and API key; replace these values with your workspace ID and API key.)

This works for me in both Excel and Power BI:

let
    Source = 
        Web.Contents(
            "https://api.clockify.me/api/workspaces/{your workspace ID}", 
            [
                Headers=[
                    #"Content-Type"="application/json", 
                    #"X-Api-Key"={your API key}
                ]
            ]
        ),
    jsonResponse = Json.Document(Source)
in
    jsonResponse



回答2:


Doesn't it have to be X-Api-Key instead of ApiKeyName?



来源:https://stackoverflow.com/questions/53164563/how-to-access-clockify-api-through-power-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!