{"_id":"5b5615e9ddebdc0003ac5423","project":"551e85be610f400d00837db7","version":{"_id":"58112e71ded0340f0085d02a","project":"551e85be610f400d00837db7","__v":4,"createdAt":"2016-10-26T22:30:09.862Z","releaseDate":"2016-10-26T22:30:09.862Z","categories":["58112e72ded0340f0085d02b","58112e72ded0340f0085d02c","58112e72ded0340f0085d02d","58112e72ded0340f0085d02e","58112e72ded0340f0085d02f","58112e72ded0340f0085d030","58112e72ded0340f0085d031","58112e72ded0340f0085d032","58112e72ded0340f0085d033","58112e72ded0340f0085d034","581137cc604d3c230048b7e4","58dc367221742d0f00a73f98","590768e54669da0f00db5c0b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"new designer","version_clean":"2.0.0","version":"2.0"},"category":{"_id":"58112e72ded0340f0085d030","version":"58112e71ded0340f0085d02a","project":"551e85be610f400d00837db7","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-25T20:14:44.667Z","from_sync":false,"order":4,"slug":"store-api-methods","title":"Store API Methods"},"user":"55694ec671f3960d00b1e754","githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-07-23T17:52:41.866Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"_Methods for getting and updating survey answer data for a subscription from the Store API._\n[block:html]\n{\n  \"html\": \"<div class=\\\"endpoint list\\\">\\n  <span class=\\\"method get\\\">GET</span>\\n  <span class=\\\"uri\\\">\\n    \\t\\t/v1/store/api/subscriptions/{subscription_id}/surveys/\\n  </span>\\n</div>\"\n}\n[/block]\n\n[block:html]\n{\n  \"html\": \"<div class=\\\"endpoint list\\\">\\n  <span class=\\\"method get\\\">GET</span>\\n  <span class=\\\"uri\\\">\\n    /v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\\n  </span>\\n</div>\"\n}\n[/block]\n\n[block:html]\n{\n  \"html\": \"<div class=\\\"endpoint list\\\">\\n  <span class=\\\"method put\\\">PUT</span>\\n  <span class=\\\"uri\\\">\\n    /v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\\n  </span>\\n</div>\"\n}\n[/block]\n# Get all subscription survey results\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$.get('/v1/store/api/subscriptions/{subscription_id}/surveys/');\",\n      \"language\": \"javascript\",\n      \"name\": \"List\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n   \\\"count\\\":2,\\n   \\\"next\\\":null,\\n   \\\"prev\\\":null,\\n   \\\"results\\\":[\\n      {\\n         \\\"answers\\\":[\\n            {\\n               \\\"field\\\":{\\n                  \\\"id\\\":1618805539,\\n                  \\\"survey\\\":{\\n                     \\\"id\\\":1618805536,\\n                     \\\"type\\\":\\\"product_survey\\\"\\n                  },\\n                  \\\"survey_id\\\":1618805536,\\n                  \\\"type\\\":\\\"product_survey_field\\\"\\n               },\\n               \\\"field_id\\\":1618805539,\\n               \\\"id\\\":1663879030,\\n               \\\"value\\\":\\\"I like turtles!\\\"\\n            },\\n            {\\n               \\\"field\\\":{\\n                  \\\"id\\\":1618805540,\\n                  \\\"survey\\\":{\\n                     \\\"id\\\":1618805536,\\n                     \\\"type\\\":\\\"product_survey\\\"\\n                  },\\n                  \\\"survey_id\\\":1618805536,\\n                  \\\"type\\\":\\\"product_survey_field\\\"\\n               },\\n               \\\"field_id\\\":1618805540,\\n               \\\"id\\\":1663879029,\\n               \\\"value\\\":\\\"2014-07-22\\\"\\n            }\\n         ],\\n         \\\"created_at\\\":\\\"Mon, 23 Jul 2018 10:09:33 GMT\\\",\\n         \\\"id\\\":1663879024,\\n         \\\"subscription_id\\\":1663878876,\\n         \\\"type\\\":\\\"product_survey_result\\\",\\n         \\\"updated_at\\\":\\\"Mon, 23 Jul 2018 10:09:33 GMT\\\",\\n         \\\"url\\\":\\\"/v1/store/api/subscriptions/<int:subscription_id>/surveys/1663879024/\\\"\\n      },\\n      {\\n         \\\"answers\\\":[\\n            {\\n               \\\"field\\\":{\\n                  \\\"id\\\":1618805541,\\n                  \\\"survey\\\":{\\n                     \\\"id\\\":1618805537,\\n                     \\\"type\\\":\\\"product_survey\\\"\\n                  },\\n                  \\\"survey_id\\\":1618805537,\\n                  \\\"type\\\":\\\"product_survey_field\\\"\\n               },\\n               \\\"field_id\\\":1618805541,\\n               \\\"id\\\":1663879019,\\n               \\\"value\\\":\\\"I am a zombie!\\\"\\n            }\\n         ],\\n         \\\"created_at\\\":\\\"Mon, 23 Jul 2018 10:09:32 GMT\\\",\\n         \\\"id\\\":1663879016,\\n         \\\"subscription_id\\\":1663878876,\\n         \\\"type\\\":\\\"product_survey_result\\\",\\n         \\\"updated_at\\\":\\\"Mon, 23 Jul 2018 10:09:32 GMT\\\",\\n         \\\"url\\\":\\\"/v1/store/api/subscriptions/<int:subscription_id>/surveys/1663879016/\\\"\\n      }\\n   ]\\n}\",\n      \"language\": \"javascript\",\n      \"name\": \"200 OK\"\n    }\n  ]\n}\n[/block]\n# Get results for an individual survey:\n[block:html]\n{\n  \"html\": \"<div class=\\\"endpoint list\\\">\\n  <span class=\\\"method get\\\">GET</span>\\n  <span class=\\\"uri\\\">\\n\\t\\t/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\\n  </span>\\n</div>\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$.get('/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}')\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n   \\\"answers\\\":[\\n      {\\n         \\\"field\\\":{\\n            \\\"id\\\":1618805539,\\n            \\\"survey\\\":{\\n               \\\"id\\\":1618805536,\\n               \\\"type\\\":\\\"product_survey\\\"\\n            },\\n            \\\"survey_id\\\":1618805536,\\n            \\\"type\\\":\\\"product_survey_field\\\"\\n         },\\n         \\\"field_id\\\":1618805539,\\n         \\\"id\\\":1663879030,\\n         \\\"value\\\":\\\"I like turtles!\\\"\\n      },\\n      {\\n         \\\"field\\\":{\\n            \\\"id\\\":1618805540,\\n            \\\"survey\\\":{\\n               \\\"id\\\":1618805536,\\n               \\\"type\\\":\\\"product_survey\\\"\\n            },\\n            \\\"survey_id\\\":1618805536,\\n            \\\"type\\\":\\\"product_survey_field\\\"\\n         },\\n         \\\"field_id\\\":1618805540,\\n         \\\"id\\\":1663879029,\\n         \\\"value\\\":\\\"2014-07-22\\\"\\n\\n      }\\n   ],\\n   \\\"created_at\\\":\\\"Mon, 23 Jul 2018 10:09:33 GMT\\\",\\n   \\\"id\\\":1663879024,\\n   \\\"subscription_id\\\":1663878876,\\n   \\\"type\\\":\\\"product_survey_result\\\",\\n   \\\"updated_at\\\":\\\"Mon, 23 Jul 2018 10:09:33 GMT\\\"\\n\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n# Update a Survey Response\n[block:html]\n{\n  \"html\": \"<div class=\\\"endpoint list\\\">\\n  <span class=\\\"method get\\\">PUT</span>\\n  <span class=\\\"uri\\\">\\n\\t\\t/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\\n  </span>\\n</div>\"\n}\n[/block]\nSurvey responses are immutable. When you make a PUT request to update survey responses, note that the response ID will have changed, as we perform a delete-and-add update rather than an edit in-place update.\nThe entire survey result needs to be sent. You can't update an individual answer of a multiple-question survey; the entire existing result will be deleted and replaced, so you have to send the full set of field/answers pairs you want.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$.ajax({\\n\\turl: '/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}',\\n\\tcontentType: 'application/json',\\n\\tdata: JSON.stringify(\\n\\t\\t{\\n\\t\\t  \\\"answers\\\":\\n\\t\\t\\t{\\n\\t\\t\\t\\t\\\"{field_id}\\\": \\\"Turtles carry salmonella? Gross!\\\",\\n\\t\\t\\t\\t\\\"{field_id\\\": \\\"2014-07-01\\\"\\n\\t\\t\\t}\\n\\t\\t}\\n\\t),\\n\\tdataType: 'json',\\n\\ttype: 'PUT',\\n})\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n   \\\"answers\\\":[\\n      {\\n         \\\"field\\\":{\\n            \\\"id\\\":1618805539,\\n            \\\"survey\\\":{\\n               \\\"id\\\":1618805536,\\n               \\\"type\\\":\\\"product_survey\\\"\\n            },\\n            \\\"survey_id\\\":1618805536,\\n            \\\"type\\\":\\\"product_survey_field\\\"\\n         },\\n         \\\"field_id\\\":1618805539,\\n         \\\"id\\\":1663936001,\\n         \\\"value\\\":\\\"Turtles carry salmonella? Gross!\\\"\\n      },\\n      {\\n         \\\"field\\\":{\\n            \\\"id\\\":1618805540,\\n            \\\"survey\\\":{\\n               \\\"id\\\":1618805536,\\n               \\\"type\\\":\\\"product_survey\\\"\\n            },\\n            \\\"survey_id\\\":1618805536,\\n            \\\"type\\\":\\\"product_survey_field\\\"\\n         },\\n         \\\"field_id\\\":1618805540,\\n         \\\"id\\\":1663936000,\\n         \\\"value\\\":\\\"2014-07-01\\\"\\n      }\\n   ],\\n   \\\"created_at\\\":\\\"Mon, 23 Jul 2018 10:09:33 GMT\\\",\\n   \\\"id\\\":1663879024,\\n   \\\"subscription_id\\\":1663878876,\\n   \\\"type\\\":\\\"product_survey_result\\\",\\n   \\\"updated_at\\\":\\\"Mon, 23 Jul 2018 10:09:33 GMT\\\"\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"survey-methods","type":"basic","title":"Survey Methods"}
_Methods for getting and updating survey answer data for a subscription from the Store API._ [block:html] { "html": "<div class=\"endpoint list\">\n <span class=\"method get\">GET</span>\n <span class=\"uri\">\n \t\t/v1/store/api/subscriptions/{subscription_id}/surveys/\n </span>\n</div>" } [/block] [block:html] { "html": "<div class=\"endpoint list\">\n <span class=\"method get\">GET</span>\n <span class=\"uri\">\n /v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\n </span>\n</div>" } [/block] [block:html] { "html": "<div class=\"endpoint list\">\n <span class=\"method put\">PUT</span>\n <span class=\"uri\">\n /v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\n </span>\n</div>" } [/block] # Get all subscription survey results [block:code] { "codes": [ { "code": "$.get('/v1/store/api/subscriptions/{subscription_id}/surveys/');", "language": "javascript", "name": "List" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"count\":2,\n \"next\":null,\n \"prev\":null,\n \"results\":[\n {\n \"answers\":[\n {\n \"field\":{\n \"id\":1618805539,\n \"survey\":{\n \"id\":1618805536,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805536,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805539,\n \"id\":1663879030,\n \"value\":\"I like turtles!\"\n },\n {\n \"field\":{\n \"id\":1618805540,\n \"survey\":{\n \"id\":1618805536,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805536,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805540,\n \"id\":1663879029,\n \"value\":\"2014-07-22\"\n }\n ],\n \"created_at\":\"Mon, 23 Jul 2018 10:09:33 GMT\",\n \"id\":1663879024,\n \"subscription_id\":1663878876,\n \"type\":\"product_survey_result\",\n \"updated_at\":\"Mon, 23 Jul 2018 10:09:33 GMT\",\n \"url\":\"/v1/store/api/subscriptions/<int:subscription_id>/surveys/1663879024/\"\n },\n {\n \"answers\":[\n {\n \"field\":{\n \"id\":1618805541,\n \"survey\":{\n \"id\":1618805537,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805537,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805541,\n \"id\":1663879019,\n \"value\":\"I am a zombie!\"\n }\n ],\n \"created_at\":\"Mon, 23 Jul 2018 10:09:32 GMT\",\n \"id\":1663879016,\n \"subscription_id\":1663878876,\n \"type\":\"product_survey_result\",\n \"updated_at\":\"Mon, 23 Jul 2018 10:09:32 GMT\",\n \"url\":\"/v1/store/api/subscriptions/<int:subscription_id>/surveys/1663879016/\"\n }\n ]\n}", "language": "javascript", "name": "200 OK" } ] } [/block] # Get results for an individual survey: [block:html] { "html": "<div class=\"endpoint list\">\n <span class=\"method get\">GET</span>\n <span class=\"uri\">\n\t\t/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\n </span>\n</div>" } [/block] [block:code] { "codes": [ { "code": "$.get('/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}')", "language": "javascript" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"answers\":[\n {\n \"field\":{\n \"id\":1618805539,\n \"survey\":{\n \"id\":1618805536,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805536,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805539,\n \"id\":1663879030,\n \"value\":\"I like turtles!\"\n },\n {\n \"field\":{\n \"id\":1618805540,\n \"survey\":{\n \"id\":1618805536,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805536,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805540,\n \"id\":1663879029,\n \"value\":\"2014-07-22\"\n\n }\n ],\n \"created_at\":\"Mon, 23 Jul 2018 10:09:33 GMT\",\n \"id\":1663879024,\n \"subscription_id\":1663878876,\n \"type\":\"product_survey_result\",\n \"updated_at\":\"Mon, 23 Jul 2018 10:09:33 GMT\"\n\n}", "language": "javascript" } ] } [/block] # Update a Survey Response [block:html] { "html": "<div class=\"endpoint list\">\n <span class=\"method get\">PUT</span>\n <span class=\"uri\">\n\t\t/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}\n </span>\n</div>" } [/block] Survey responses are immutable. When you make a PUT request to update survey responses, note that the response ID will have changed, as we perform a delete-and-add update rather than an edit in-place update. The entire survey result needs to be sent. You can't update an individual answer of a multiple-question survey; the entire existing result will be deleted and replaced, so you have to send the full set of field/answers pairs you want. [block:code] { "codes": [ { "code": "$.ajax({\n\turl: '/v1/store/api/subscriptions/{subscription_id}/surveys/{product_survey_result_id}',\n\tcontentType: 'application/json',\n\tdata: JSON.stringify(\n\t\t{\n\t\t \"answers\":\n\t\t\t{\n\t\t\t\t\"{field_id}\": \"Turtles carry salmonella? Gross!\",\n\t\t\t\t\"{field_id\": \"2014-07-01\"\n\t\t\t}\n\t\t}\n\t),\n\tdataType: 'json',\n\ttype: 'PUT',\n})", "language": "javascript" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"answers\":[\n {\n \"field\":{\n \"id\":1618805539,\n \"survey\":{\n \"id\":1618805536,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805536,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805539,\n \"id\":1663936001,\n \"value\":\"Turtles carry salmonella? Gross!\"\n },\n {\n \"field\":{\n \"id\":1618805540,\n \"survey\":{\n \"id\":1618805536,\n \"type\":\"product_survey\"\n },\n \"survey_id\":1618805536,\n \"type\":\"product_survey_field\"\n },\n \"field_id\":1618805540,\n \"id\":1663936000,\n \"value\":\"2014-07-01\"\n }\n ],\n \"created_at\":\"Mon, 23 Jul 2018 10:09:33 GMT\",\n \"id\":1663879024,\n \"subscription_id\":1663878876,\n \"type\":\"product_survey_result\",\n \"updated_at\":\"Mon, 23 Jul 2018 10:09:33 GMT\"\n}", "language": "javascript" } ] } [/block]