简体   繁体   中英

Using Azure Logic App to Insert Response from SurveyGizmo via HTTP Post (JSON)

SurveyGizmo provides a "webhook" that posts data to a given URL as JSON or a simple post. I need to insert this data into a SQL Server database in Azure. I am able to get the trigger (the post) to initiate the app but am having difficulty extracting the data out of the JSON submitted.

I used webhook.site to get a sample of the JSON sent via SurveyGizmo. I used this to paste into the "sample payload" for the schema under the trigger (HTTP Request). I see the data, the field names, etc. in the sample but I can't seem to get values out of it in my second step which is the insert record into SQL Server. I'll paste the sample JSON below. What I see when I select a "parameter" under the SQL part is many, many "answer" choices under dynamic content. I see that is repeated many times in the below sample so I'm thinking it's just not reading the schema correctly or I need to write out the schema. Any thoughts?

{
  "is_test_data": null,
  "session_id": "1567451759_5d6d6a6f705997.66294551",
  "language": "English",
  "date_started": "2019-09-02 15:15:59 EDT",
  "link_id": null,
  "url_variables": [

  ],
  "ip_address": "99.85.42.146",
  "referer": "https:\/\/app.surveygizmo.com\/builder\/test\/id\/5147523",
  "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.102 Safari\/537.36 Edge\/18.18362",
  "response_time": null,
  "data_quality": [

  ],
  "survey_data": {
    "3": {
      "id": 3,
      "type": "TEXTBOX",
      "question": "Please enter your email address.\u00a0 Doing so will allow you to retrieve your individual report at a later date.",
      "section_id": 1,
      "answer": "adan13@example.net",
      "shown": true
    },
    "119": {
      "id": 119,
      "type": "HIDDEN",
      "question": "org",
      "section_id": 1,
      "answer": "",
      "answer_id": 0,
      "shown": true
    }
}

I expect that by choosing "ip_address" for example the app would insert "99.85.42.146". But I get nothing in the field ("parameter") I chose.

enter image description here

Per my understanding , SurveyGizmo will post json data to your logic app and your logic app will accept the json data and insert part of this data into your SQL server. Firstly, you create use a http trigger with JSON schema below :

{
    "properties": {
        "data_quality": {
            "type": "array"
        },
        "date_started": {
            "type": "string"
        },
        "ip_address": {
            "type": "string"
        },
        "is_test_data": {},
        "language": {
            "type": "string"
        },
        "link_id": {},
        "referer": {
            "type": "string"
        },
        "response_time": {},
        "session_id": {
            "type": "string"
        },
        "survey_data": {
            "properties": {
                "3": {
                    "properties": {
                        "answer": {
                            "type": "string"
                        },
                        "id": {
                            "type": "integer"
                        },
                        "question": {
                            "type": "string"
                        },
                        "section_id": {
                            "type": "integer"
                        },
                        "shown": {
                            "type": "boolean"
                        },
                        "type": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "119": {
                    "properties": {
                        "answer": {
                            "type": "string"
                        },
                        "answer_id": {
                            "type": "integer"
                        },
                        "id": {
                            "type": "integer"
                        },
                        "question": {
                            "type": "string"
                        },
                        "section_id": {
                            "type": "integer"
                        },
                        "shown": {
                            "type": "boolean"
                        },
                        "type": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        },
        "url_variables": {
            "type": "array"
        },
        "user_agent": {
            "type": "string"
        }
    },
    "type": "object"
}

And then create a SQL sever insert action , with the config you need. In this demo , I created a simple table in my sql server , I'll extract ip_address from JSON and then save it to SQL server : 在此处输入图片说明

在此处输入图片说明

As schema has been defined correctly , you can pick params you need here.

Save and run this logic app using the json data you provided, everything works as expected : 在此处输入图片说明 在此处输入图片说明

If you have any unclear , pls feel free to let me know : )

Hi, Mike , if you want to test this logic app with your custom JSON data, you can just use some some http client tools such as postman or rest client to do some test, you will get a 202 code if you triggered it successfully : 在此处输入图片说明

You can find the http trigger url here : 在此处输入图片说明

As you can see , when I post the json , a new ip record as been inserted :

在此处输入图片说明

Btw, I have no freelance work now, so what can I help ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM