简体   繁体   English

如何使用 Power Query 从 Toggl API 中提取数据?

[英]How to pull data from Toggl API with Power Query?

First timer when it comes to connecting to API.连接到 API 时的第一个计时器。 I'm trying to pull data from Toggl using my API token but I can't get credentials working.我正在尝试使用我的 API 令牌从 Toggl 中提取数据,但我无法获得凭据。 I tried to replicate the method by Chris Webb ( https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/ ) but I can't get it working.我试图通过 Chris Webb ( https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/ ) 复制该方法,但我无法理解在职的。 Here's my M code:这是我的 M 代码:

let
    Source = Web.Contents(
 "https://toggl.com/reports/api/v2/details?workspace_id=xxxxx&client=xxxxxx6&billable=yes&user_agent=xxxxxxx",
 [
  Query=[ #"filter"="", #"orderBy"=""],
  ApiKeyName="api-token"
 ])
in
    Source

After that I'm inputting my API Token into Web API method in Access Web content windows but I get an error that credentials could not be authenticated.之后,我将我的 API 令牌输入到访问 Web 内容窗口中的 Web API 方法中,但出现无法验证凭据的错误。 Here's Toggl API specification: https://github.com/toggl/toggl_api_docs/blob/master/reports.md这是 Toggl API 规范: https : //github.com/toggl/toggl_api_docs/blob/master/reports.md

Web.Contents function receives two parameters: url + options Web.Contents函数接收两个参数: url + options

Inside options , you define the headers and the api_key , and other queryable properties, such as:options 中,您定义标头api_key以及其他可查询的属性,例如:

let
    baseUrl = "https://toggl.com/",
    // the token part can vary depending on the requisites of the API
    accessToken = "Bearer" & "insert api token here"
    options = [
                Headers = [Authorization = accessToken, #"Content-Type" = 
                  "application/Json"], RelativePath ="reports/api/v2/details", Query = 
                  [workspace_id=xxxxx, client=xxxxxx6 , billable=yes, user_agent=xxxxxxx]
              ]
    Source = Web.Contents(baseUrl, options)
    // since Web.Contents() doesn't parse the binaries it fetches, you must use another 
    // function to see if the data was retreived, based on the datatype of the data
    parsedData = Json.Document(Source)
in
    parsedData

The baseUrl is the smallest url that works and never changes; baseUrl是最小的有效且永不改变的 url; The RelativePath is the next part of the url before the first " ? ".相对路径是第一个“ ? ”之前的 url 的下一部分。 The Query record is where you define all the attributes to query as a record.查询记录是您将所有要查询的属性定义为记录的地方。

This is usually the format, but check the documentation of the API you're querying to see if it is similar.这通常是格式,但请检查您正在查询的 API 的文档以查看它是否相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM