Приложение Azure Logic HTTP Post из JSON в строку SQL - PullRequest
0 голосов
/ 06 января 2019

Я создаю приложение логики, которое принимает данные Wordpress Woocommerce в виде HTTP-POST JSON и помещает их в базу данных MSSQL.

Setup- HTTP Post URL SQL-соединение Ответ 200

Когда я создаю соединение SQL в режиме конструктора, оно создает для каждого выражения в продуктах и ​​купонах.

Я получаю ExpressionEvaluationFailed. Не удалось выполнить действие шаблона «For_each»: результат вычисления выражения «foreach» @triggerBody () имеет тип «Null». Результат должен быть действительным массивом. при попытке запустить код. Таблица правильно настроена для столбцов, и они отображаются в представлении конструктора, но я не уверен, почему я получаю ExpressionEvaluationFailed. Примечание. Удален идентификатор подписки для обеспечения безопасности.

Любая помощь будет принята с благодарностью. Я знаю, что это как-то связано с массивами.

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.

...