Zapier 从 Tsheets 数据在 Google Sheet 中创建多行

Zapier to create multiple rows in Google Sheet from Tsheets data

在 Zapier Zap 中,我使用对 Tsheets 的 API GET 调用来获取 Timesheets 的列表。我想将每次 sheet 分成行项目,例如 Xero 发票中的行项目,因为我想将每次 sheet 的项目数据保存到 Google 中它自己的行sheet。 (理想情况下,我想将行数据直接保存到 MySQL 数据库,但我看到 Zapier 目前仅支持 Google sheets 一次保存多行。)但是我有没有快乐。 我怀疑是以下两个问题之一:

  1. Zapier 期望响应中包含 lineitems 一词或
  2. 回复的格式不正确 - 我似乎有两个 "results" 类别

在我设置 Google Sheets Spreadsheet 行的步骤中,我没有选择逗号分隔的项目,如下图所示: Add an action app that supports line items, and each item will be saved individually 图片来自此页面:https://zapier.com/blog/formatter-line-item-automation/ with the caption "Add an action app that supports line items, and each item will be saved individually" For what I get see photo https://cdn.zapier.com/storage/photos/f055dcf11a4b11b86f912f9032780429.png 在 returns 来自 API 的数据的步骤中,文本响应显示在 https://cdn.zapier.com/storage/photos/33129fb7425cfae44be4a81533d6e892.png 中 如果我 return json 数据是这样的:https://cdn.zapier.com/storage/photos/34da1b98f8941324c35befef8efe350d.png

谁能证实我的怀疑是正确的,1 还是 2 是可能的罪魁祸首。

这个 link 是否可以引导我找到解决方案?看起来可能,但我不明白作者是如何将它融入到他的 Zap 中的。

编辑:我从 API 编辑的数据 return 如下所示:

{
 "results": {
  "timesheets": {
   "11515534": {
    "id": 11515534,
    "user_id": 1260679,
    "jobcode_id": 11974818,
    "start": "2018-07-13T14:58:00+10:00",
    "end": "2018-07-13T14:58:00+10:00",
    "duration": 0,
    "date": "2018-07-13",
    "tz": 10,
    "tz_str": "Australia\/Brisbane",
    "type": "regular",
    "location": "(Brisbane, Queensland, AU?)",
    "on_the_clock": false,
    "locked": 0,
    "notes": "",
    "customfields": {
     "118516": "",
     "121680": "",
     "118530": "",
     "118518": "Field supplies, materials"
    },
    "last_modified": "2018-07-13T04:59:27+00:00",
    "attached_files": [

    ]
   },
   "11515652": {
    "id": 11515652,
    "user_id": 1260679,
    "jobcode_id": 11974830,
    "start": "2018-07-13T14:59:00+10:00",
    "end": "2018-07-13T14:59:00+10:00",
    "duration": 0,
    "date": "2018-07-13",
    "tz": 10,
    "tz_str": "Australia\/Brisbane",
    "type": "regular",
    "location": "(Brisbane, Queensland, AU?)",
    "on_the_clock": false,
    "locked": 0,
    "notes": "",
    "customfields": {
     "118516": "",
     "121680": "",
     "118530": ""
    },
    "last_modified": "2018-07-13T05:00:30+00:00",
    "attached_files": [

    ]
   },
   "39799840": {
    "id": 39799840,
    "user_id": 1260679,
    "jobcode_id": 19280104,
    "start": "2018-10-24T11:45:00+11:00",
    "end": "2018-10-24T12:00:00+11:00",
    "duration": 900,
    "date": "2018-10-24",
    "tz": 11,
    "tz_str": "Australia\/Brisbane",
    "type": "regular",
    "location": "(Sydney, New South Wales, AU?)",
    "on_the_clock": false,
    "locked": 0,
    "notes": "",
    "customfields": {
     "118516": "",
     "121680": "FP - Field plant Installation",
     "118530": "Site cleanup"
    },
    "last_modified": "2018-10-24T05:56:27+00:00",
    "attached_files": [

    ]
   },
   "39801850": {
    "id": 39801850,
    "user_id": 1260679,
    "jobcode_id": 19280204,
    "start": "2018-10-24T12:00:00+11:00",
    "end": "2018-10-24T13:45:00+11:00",
    "duration": 6300,
    "date": "2018-10-24",
    "tz": 11,
    "tz_str": "Australia\/Brisbane",
    "type": "regular",
    "location": "(Sydney, New South Wales, AU?)",
    "on_the_clock": false,
    "locked": 0,
    "notes": "",
    "customfields": {
     "118516": "",
     "121680": "OP - Plant, Vehicles",
     "118530": "Load\/Unload"
    },
    "last_modified": "2018-10-24T05:57:04+00:00",
    "attached_files": [

    ]
   },
   "40192757": {
    "id": 40192757,
    "user_id": 1260679,
    "jobcode_id": 19280110,
    "start": "2018-10-25T08:00:00+11:00",
    "end": "2018-10-25T10:00:00+11:00",
    "duration": 7200,
    "date": "2018-10-25",
    "tz": 11,
    "tz_str": "Australia\/Brisbane",
    "type": "regular",
    "location": "TSheets Android App",
    "on_the_clock": false,
    "locked": 0,
    "notes": "From my mobile",
    "customfields": {
     "118516": "",
     "121680": "FW - Plant Assembly",
     "118530": "Panels"
    },
    "last_modified": "2018-10-24T23:02:56+00:00",
    "attached_files": [

    ]
   },
   "40193033": {
    "id": 40193033,
    "user_id": 1260679,
    "jobcode_id": 19280108,
    "start": "2018-10-25T10:00:00+11:00",
    "end": "2018-10-25T10:00:00+11:00",
    "duration": 0,
    "date": "2018-10-25",
    "tz": 11,
    "tz_str": "Australia\/Brisbane",
    "type": "regular",
    "location": "TSheets Android App",
    "on_the_clock": false,
    "locked": 0,
    "notes": "",
    "customfields": {
     "118516": "",
     "121680": "FW - Plant Assembly",
     "118530": "Panels"
    },
    "last_modified": "2018-10-24T23:06:05+00:00",
    "attached_files": [

    ]
   }
  }
 },
 "more": false
}

这是我的 Python 代码:https://imgur.com/a/8W1X1em

好的,我想我已经为您解决了一些问题。您提供的示例 绝对是正确的,但是,因为它依赖于 webhook,所以除非您可以 POST 来自发票应用程序的数据,否则它可能对您不起作用。

注意: 我在 Python 中编码,所以我的示例将在 Python 中,也就是说这些示例几乎与代码无关,可以复制在 Javascript 中也是如此。

我设置了一个虚拟 Zap 来复制你的 Zap 当前发生的事情

# results = requests.get(url, headers=header)
# results = results.json()
# Dummy result data converted to JSON object after API GET request:
results =  { 
    "results" : {
        "timesheets" : {
            "timesheet_id_1" : {
                "data_1" : "data",
                "data_2" : "data",
                "data_3" : "data"
                },
            "timesheet_id_2" : {
                "data_1" : "data",
                "data_2" : "data",
                "data_3" : "data"
                },
            "timesheet_id_3" : {
                "data_1" : "data",
                "data_2" : "data",
                "data_3" : "data"
                }
            }
        }
    }

return results

进一步阅读 here in order for Zapier to map line items it needs to receive the data in an array. The above output is a dictionary object, Zapier does map the values in this dictionary to data that can be accessed later, however it maps the entire dictionary which is why you are seeing the output as multiple fields and as is replicated in my output。您要做的是映射字典的子集 AND 将每个子集作为单独的输出提供。

您要做的是遍历结果字典对象的内部字段并在嵌套的 "timesheet_id_n" 上执行 zaps。为此,我们必须 return 一个订单项列表,如上所述,订单项必须放入一个数组中。因此我实现此目的的代码如下所示:

# results = requests.get(url, headers=header)
# results = results.json()
# Dummy result data converted to JSON object after API GET request:
results =  { 
    "results" : {
        "timesheets" : {
            "timesheet_id_1" : {
                "data_1" : "data",
                "data_2" : "data",
                "data_3" : "data"
                },
            "timesheet_id_2" : {
                "data_1" : "data",
                "data_2" : "data",
                "data_3" : "data"
                },
            "timesheet_id_3" : {
                "data_1" : "data",
                "data_2" : "data",
                "data_3" : "data"
                }
            }
        }
    }

# Container for my line items. Each element in this list will be executed on separately
return_results = []

results = results.get("results")
results = results.get("timesheets")
for item in results:
    return_results.append({"sheet_id" : item, "sheet_data" : results.get(item)})

return return_results

return_results 的输出将是一个字典对象数组。由于这些字典对象在数组中,Zapier 会将它们视为行项目,此外,因为每个行项目都是一个字典对象,Zapier 会自动映射每个值,以便它们可以在后面的操作步骤中独立使用。您可以在以下屏幕截图中的触发器 zap 输出中看到这一点:

output 1
output 2
output 3

希望对您有所帮助!