如何使用 Power Query 从 Toggl API 中提取数据? [英] How to pull data from Toggl API with Power Query?

查看:43
本文介绍了如何使用 Power Query 从 Toggl API 中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接 API 时的第一个计时器.我正在尝试使用我的 API 令牌从 Toggl 中提取数据,但我无法获得凭据.我试图复制 Chris Webb 的方法 (https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/) 但我无法让它工作.这是我的 M 代码:

First timer when it comes to connecting to API. I'm trying to pull data from Toggl using my API token but I can't get credentials working. 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. Here's my M code:

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

之后,我将我的 API 令牌输入到 Access Web 内容窗口中的 Web API 方法中,但出现无法验证凭据的错误.这是 Toggl API 规范:https://github.com/toggl/toggl_api_docs/blob/master/reports.md

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. Here's Toggl API specification: https://github.com/toggl/toggl_api_docs/blob/master/reports.md

推荐答案

Web.Contents 函数接收两个参数:url + options

Web.Contents function receives two parameters: url + options

选项中,您定义标题api_key,以及其他可查询的属性,例如:

Inside options, you define the headers and the api_key, and other queryable properties, such as:

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

baseUrl 是最小的有效且永不改变的 URL;RelativePath 是 URL 中第一个?"之前的下一部分.查询 记录是您将所有要查询的属性定义为记录的位置.

The baseUrl is the smallest url that works and never changes; The RelativePath is the next part of the url before the first "?". The Query record is where you define all the attributes to query as a record.

这通常是格式,但请检查您要查询的 API 的文档,看看它是否相似.

This is usually the format, but check the documentation of the API you're querying to see if it is similar.

这篇关于如何使用 Power Query 从 Toggl API 中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆