第一次连接到API。我正在尝试使用我的API令牌从Toggl中提取数据,但是我无法获得凭据。我试图复制Chris Webb(https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/)的方法,但是无法正常工作。这是我的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
在那之后,我将我的API令牌输入到Access Web内容窗口中的Web API方法中,但是收到一个错误,提示无法对凭据进行身份验证。这是Toggl API规范: https://github.com/toggl/toggl_api_docs/blob/master/reports.md
答案 0 :(得分:1)
Web.Contents 功能接收两个参数: url + 选项
在选项中,您定义标题和 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
baseUrl 是最小的有效网址,永远不会更改; RelativePath 是网址的下一部分,位于第一个“ ?”之前。 在 Query 记录中,您可以定义要查询的所有属性作为记录。
通常是这种格式,但是请检查您要查询的API的文档,以了解是否相似。