sql-server - Azure 逻辑应用 HTTP 将 JSON 发布到 SQL 行
问题描述
我正在构建一个将 Wordpress Woocommerce 数据作为 HTTP-POST JSON 并将其放入 MSSQL 数据库的逻辑应用程序。
设置 - HTTP Post URL SQL 连接响应 200
当我在设计视图下构建 SQL 连接时,它会为 Products 和 Coupon 上的每个表达式创建一个。
我得到 ExpressionEvaluationFailed。模板操作“For_each”的执行失败:“foreach”表达式“@triggerBody()”的评估结果为“Null”类型。结果必须是有效的数组。尝试运行代码时。该表的列设置正确,它们映射在设计视图上,但我不确定为什么我会收到 ExpressionEvaluationFailed。注意:为安全起见,删除了订阅 ID。
任何帮助将不胜感激。我知道它与数组有关。
JSON SCHEMA for HTTP POST
{
"items": {
"properties": {
"Customer User Email": {
"type": "string"
},
"Customer User ID": {
"type": "string"
},
"billing_address": {
"type": "string"
},
"billing_city": {
"type": "string"
},
"billing_company": {
"type": "string"
},
"billing_country": {
"type": "string"
},
"billing_email": {
"type": "string"
},
"billing_first_name": {
"type": "string"
},
"billing_last_name": {
"type": "string"
},
"billing_phone": {
"type": "string"
},
"billing_postcode": {
"type": "string"
},
"billing_state": {
"type": "string"
},
"cart_discount": {
"type": "string"
},
"coupons": {
"items": {
"properties": {
"code": {
"type": "string"
},
"discount_amount": {
"type": "string"
},
"discount_amount_tax": {
"type": "string"
}
},
"required": [
"code",
"discount_amount",
"discount_amount_tax"
],
"type": "object"
},
"type": "array"
},
"customer_note": {
"type": "string"
},
"order_date": {
"type": "string"
},
"order_number": {
"type": "string"
},
"order_refund": {
"type": "integer"
},
"order_shipping": {
"type": "string"
},
"order_status": {
"type": "string"
},
"order_subtotal": {
"type": "string"
},
"order_total": {
"type": "string"
},
"order_total_tax": {
"type": "integer"
},
"payment_method_title": {
"type": "string"
},
"products": {
"items": {
"properties": {
"item_price": {
"type": "integer"
},
"line_id": {
"type": "integer"
},
"name": {
"type": "string"
},
"qty": {
"type": "string"
},
"sku": {
"type": "string"
}
},
"required": [
"line_id",
"sku",
"name",
"qty",
"item_price"
],
"type": "object"
},
"type": "array"
},
"shipping_address": {
"type": "string"
},
"shipping_city": {
"type": "string"
},
"shipping_country": {
"type": "string"
},
"shipping_first_name": {
"type": "string"
},
"shipping_last_name": {
"type": "string"
},
"shipping_method_title": {
"type": "string"
},
"shipping_postcode": {
"type": "string"
},
"shipping_state": {
"type": "string"
}
},
"required": [
"order_number",
"order_status",
"order_date",
"customer_note",
"Customer User ID",
"Customer User Email",
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_address",
"billing_city",
"billing_state",
"billing_postcode",
"billing_country",
"billing_email",
"billing_phone",
"shipping_first_name",
"shipping_last_name",
"shipping_address",
"shipping_city",
"shipping_state",
"shipping_postcode",
"shipping_country",
"shipping_method_title",
"payment_method_title",
"cart_discount",
"order_subtotal",
"order_shipping",
"order_refund",
"order_total",
"order_total_tax",
"products",
"coupons"
],
"type": "object"
},
"type": "array"
}
Logic App Code View
{
"$connections": {
"value": {
"sql_1": {
"connectionId": "/subscriptions/---/resourceGroups/cogpubwebapps/providers/Microsoft.Web/connections/sql-3",
"connectionName": "sql-3",
"id": "/subscriptions/---/providers/Microsoft.Web/locations/eastus/managedApis/sql"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"For_each_3": {
"actions": {
"Insert_row": {
"inputs": {
"body": {
"Customer_User_Email": "@items('For_each')['Customer User Email']",
"Customer_User_ID": "@items('For_each')['Customer User ID']",
"billing_address": "@items('For_each')['billing_address']",
"billing_city": "@items('For_each')['billing_city']",
"billing_company": "@items('For_each')['billing_company']",
"billing_country": "@items('For_each')['billing_country']",
"billing_email": "@items('For_each')['billing_email']",
"billing_first_name": "@items('For_each')['billing_first_name']",
"billing_last_name": "@items('For_each')['billing_last_name']",
"billing_phone": "@items('For_each')['billing_phone']",
"billing_postcode": "@items('For_each')['billing_postcode']",
"billing_state": "@items('For_each')['billing_state']",
"cart_discount": "@items('For_each')['cart_discount']",
"coupons0code": "@items('For_each_3')['code']",
"coupons0discount_amount": "@items('For_each')['cart_discount']",
"coupons0discount_amount_tax": "@items('For_each_3')['discount_amount_tax']",
"customer_note": "@items('For_each')['customer_note']",
"order_date": "@items('For_each')['order_date']",
"order_number": "@items('For_each') ['order_number']",
"order_refund": "@items('For_each') ['order_refund']",
"order_shipping": "@items('For_each') ['order_shipping']",
"order_status": "@items('For_each')['order_status']",
"order_subtotal": "@items('For_each') ['order_subtotal']",
"order_total": "@items('For_each') ['order_total']",
"order_total_tax": "@items('For_each')['order_total_tax']",
"payment_method_title": "@items('For_each')['payment_method_title']",
"products0item_price": "@{items('For_each_2')['item_price']}",
"products0line_id": "@{items('For_each_2')['line_id']}",
"products0name": "@items('For_each_2')['name']",
"products0qty": "@items('For_each') ['qty']",
"products0sku": "@items('For_each_2')['sku']",
"shipping_address": "@items('For_each')['shipping_address']",
"shipping_city": "@items('For_each')['shipping_city']",
"shipping_country": "@items('For_each')['shipping_country']",
"shipping_first_name": "@items('For_each')['shipping_first_name']",
"shipping_last_name": "@items('For_each')['shipping_last_name']",
"shipping_method_title": "@items('For_each')['shipping_method_title']",
"shipping_postcode": "@items('For_each')['shipping_postcode']",
"shipping_state": "@items('For_each')['shipping_state']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['sql_1']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('[dbo].[PWBSWebOrders]'))}/items"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"foreach": "@items('For_each')['coupons']",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "@items('For_each')['products']",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "@triggerBody()",
"runAfter": {},
"type": "Foreach"
},
"Response": {
"inputs": {
"statusCode": 200
},
"kind": "Http",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Response"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {
"items": {
"properties": {
"Customer User Email": {
"type": "string"
},
"Customer User ID": {
"type": "string"
},
"billing_address": {
"type": "string"
},
"billing_city": {
"type": "string"
},
"billing_company": {
"type": "string"
},
"billing_country": {
"type": "string"
},
"billing_email": {
"type": "string"
},
"billing_first_name": {
"type": "string"
},
"billing_last_name": {
"type": "string"
},
"billing_phone": {
"type": "string"
},
"billing_postcode": {
"type": "string"
},
"billing_state": {
"type": "string"
},
"cart_discount": {
"type": "string"
},
"coupons": {
"items": {
"properties": {
"code": {
"type": "string"
},
"discount_amount": {
"type": "string"
},
"discount_amount_tax": {
"type": "string"
}
},
"required": [
"code",
"discount_amount",
"discount_amount_tax"
],
"type": "object"
},
"type": "array"
},
"customer_note": {
"type": "string"
},
"order_date": {
"type": "string"
},
"order_number": {
"type": "string"
},
"order_refund": {
"type": "integer"
},
"order_shipping": {
"type": "string"
},
"order_status": {
"type": "string"
},
"order_subtotal": {
"type": "string"
},
"order_total": {
"type": "string"
},
"order_total_tax": {
"type": "integer"
},
"payment_method_title": {
"type": "string"
},
"products": {
"items": {
"properties": {
"item_price": {
"type": "integer"
},
"line_id": {
"type": "integer"
},
"name": {
"type": "string"
},
"qty": {
"type": "string"
},
"sku": {
"type": "string"
}
},
"required": [
"line_id",
"sku",
"name",
"qty",
"item_price"
],
"type": "object"
},
"type": "array"
},
"shipping_address": {
"type": "string"
},
"shipping_city": {
"type": "string"
},
"shipping_country": {
"type": "string"
},
"shipping_first_name": {
"type": "string"
},
"shipping_last_name": {
"type": "string"
},
"shipping_method_title": {
"type": "string"
},
"shipping_postcode": {
"type": "string"
},
"shipping_state": {
"type": "string"
}
},
"required": [
"order_number",
"order_status",
"order_date",
"customer_note",
"Customer User ID",
"Customer User Email",
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_address",
"billing_city",
"billing_state",
"billing_postcode",
"billing_country",
"billing_email",
"billing_phone",
"shipping_first_name",
"shipping_last_name",
"shipping_address",
"shipping_city",
"shipping_state",
"shipping_postcode",
"shipping_country",
"shipping_method_title",
"payment_method_title",
"cart_discount",
"order_subtotal",
"order_shipping",
"order_refund",
"order_total",
"order_total_tax",
"products",
"coupons"
],
"type": "object"
},
"type": "array"
}
},
"kind": "Http",
"type": "Request"
}
}
}
}
从 Woocommerce 接收数据并放入 SQL 数据库行。
解决方案
推荐阅读
- typescript - typescript flatten array with children (lodash)
- angular - ipfs npm package with Angular not working
- android - How to clear all session cookies in an Ionic app on Android?
- c - C字符串长度错误
- jsf - Jsf Omnifaces After sessiontimeout called unload throught Jaas the result is white screen Empty Result
- php - Storing Excel file using Binary content issue
- javascript - How to seperate elements of string by space Java Script
- angular - 角leafeat json文件输入
- google-apps-script - Browser.msgBox 与 CANCEL
- amazon-web-services - AWS SSM 发送命令 CLI 中的转义字符