【发布时间】:2016-01-07 18:02:52
【问题描述】:
当产品更新或下订单时,Wommcommerce 会触发 Webhook。我正在尝试使用作为 WebApp 发布的 Google Apps 脚本 (GAS) 来捕获此 Webhook。我最终想要实现的是将收到的订单写入 Google 电子表格。
我无法从这些 webhook 中获取正确(或至少部分)数据。我尝试了不同的方法将数据写入工作表,但我在工作表中发现的唯一内容是“未定义”。老实说,我不知道如何处理 JSON 数据。我的测试函数现在是:
function doPost(e){
var doc = DocumentApp.openById('myDocId');
var jstring = Utilities.jsonStringify(e);
doc.appendParagraph(jstring);
}
当触发 webhook(订单更新)时,我在文档中得到以下输出:
{"parameter":{},"contextPath":"","contentLength":1523,"queryString":null,"parameters":{},"postData":"FileUpload"}
显然根本没有解析,但我尝试的所有方法(例如 getContentText())都不起作用。 Woocommerce 中的 Webhook-Log 告诉我这是发送的:
{"product":{"title":"testprodukt","id":136,"created_at":"2015-10-06T13:15:38Z","updated_at":"2015-10-09T15: 19:04Z","type":"simple","status":"publish","downloadable":true,"virtual":true,"permalink":"http://MYDOMAIN/produkt/testprodukt/","sku":"", "price":"5.00","regular_price":"5.00","sale_price":null,"price_html":"€5,00","taxable":false,"tax_status":"taxable","tax_class" :"","managing_stock":false,"stock_quantity":"","in_stock":true,"backorders_allowed":false,"backordered":false,"sold_individually":false,"purchaseable":true,"featured" :false,"visible":true,"catalog_visibility":"visible","on_sale":false,"product_url":"","button_text":"","weight":null,"dimensions":{"length ":"","width":"","height":"","unit":"cm"},"shipping_required":false,"shipping_taxable":true,"shipping_class":"","shipping_class_id" :null,"描述":"
somedescription
n","short_description":"","reviews_allowed":false,"average_rating":"0.00","rating_count":0,"related_ids":[],"upsell_ids":[ ],"cross_sell_ids":[],"parent_id":0,"categories":[],"tags":[],"images":[{"id":0,"created_at":"2015-10- 09T15:19:05Z","updated_at":"2015-10-09T15:19:05Z","src":"http://MYDOMAIN/wp-content/plugins/woocommerce/assets/images/placeholder.png","title":"Platzhalter","alt":"Platzhalter"," position":0}],"featured_src":false,"attributes":[],"downloads":[],"download_limit":0,"download_expiry":0,"download_type":"","purchase_note": "","total_sales":7,"variations":[],"parent":[]}}
我正在寻找提示、链接、示例,以及如何从 webhook 中获取数据的正确方向。
【问题讨论】:
-
您好,您知道在哪里可以从 webhook 中找到一些示例数据吗?我必须实现客户 eshop 的 webhook,所以我不能“创建新产品”或“新订单”并手动测试它
-
@你用过谷歌电子表格库吗?如何为我的 WordPress 网站实现相同的功能?
标签: json google-apps-script google-sheets woocommerce webhooks