Answers
Get an answer
Retrieves a single answers by id.
/v1/answer/:idParameters - Parameter
| Name | Type | Description |
|---|---|---|
| id | String | The unique id of the answer to retrieve. |
Examples
curl https://api.surveyplanet.com/v1/answer/62b9db151489dd913aeaa22f
--header "Authorization: Bearer <ACCESS_TOKEN>"// For Node.js considering using the 'node-fetch' library: npm info node-fetch
fetch(`https://api.surveyplanet.com/v1/answer/62b9db151489dd913aeaa22f`, {
headers: { Authorization: 'Bearer <ACCESS_TOKEN>' },
})
.then((response) => response.json())
.then((res) => console.log(res.data))
.catch((err) => console.error(err));# This code sample uses the 'requests' library: pip show requests
import requests
response = requests.get(
"https://api.surveyplanet.com/v1/answer/62b9db151489dd913aeaa22f",
headers={"Authorization": "Bearer <ACCESS_TOKEN>"}
)
print(response.text)Success response example
Success response example - Response
{
"status": 200,
"type": "ok",
"message": "Request worked as expected."
"data": {
{
"_id": "62b9db151489dd913aeaa22f",
"index": 0,
"participant": {
"_id": "62bb20e8afac21b873847d7f",
"index": 42
},
"question": {
"_id": "62bb2c99afac21b873847d80",
"title": "Multiple Choice",
"type": "multiple_choice",
"properties": {
"multi": false,
"random": true,
"labels": [
"Apples",
"Oranges",
"Peaches",
"Grapes"
]
}
},
"user": "62bb2ca2afac21b873847d81",
"values": [
{
"label": "Peaches",
"value": true
}
],
"created": "2022-03-30T19:04:55.611Z",
"comments": "",
"updated": "2022-03-30T19:04:56.630Z",
"type": "multiple_choice"
}
}
} Get answer summary
Retrieves results summary for a survey question. Note: This is a POST rather than a GET request since using filters in the query could result in a 414—Request-URI Too Long client error.
/v1/results/questionRequest Body
| Name | Type | Description |
|---|---|---|
| question | String | The ID of the question to retrieve results for. |
| filters | Object[] | optional A list of filters to apply to the summary. |
| filter.key | String | The answer property to filter on e.g.: |
| filter.value | Mixed | The value to filter answers by. |
| filter.operator | String | optional The comparison operator. Options: |
| filter.dataType | String | optional The data type of value. Options: |
| matchAny | Boolean | optional Match any filter using ‘or’ instead of the default ‘and’. Default value: false |
| limit | Number | optional Limit open ended responses. Default value: 10 |
Examples
curl https://api.surveyplanet.com/v1/results/question
--request POST
--header "Content-Type: application/json"
--header "Authorization: Bearer <ACCESS_TOKEN>"
--data '{"question":"62b9db151489dd913aeaa22f"}'// For Node.js considering using the 'node-fetch' library: npm info node-fetch
fetch(`https://api.surveyplanet.com/v1/results/question`, {
method: "POST"
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <ACCESS_TOKEN>",
}
body: JSON.stringify({"question":"62b9db151489dd913aeaa22f"})
})
.then( response => response.json() )
.then( res => console.log(res.data) )
.catch( err => console.error(err) );# This code sample uses the 'requests' library: pip show requests
import requests
response = requests.post(
'https://api.surveyplanet.com/v1/results/question',
headers = {
"Content-Type": "application/json"
"Authorization": "Bearer <ACCESS_TOKEN>"
}
data = {"question":"62b9db151489dd913aeaa22f"}
)
print(response.text)Success response example
Success response example - Response
{
"status": 200,
"type": "ok",
"message": "Request worked as expected."
"data": {
"_id": "62b9db151489dd913aeaa22f",
"index": 0,
"question": {
"_id": "62b9db151489dd913aeaa22f",
"title": "What is your favorite kind of fruit?",
"subtitle": "Select one or more.",
"required": false,
"comments": null,
"type": "multiple_choice",
"properties": {
"multi": false,
"random": true,
"labels": [
"Apples",
"Oranges",
"Peaches",
"Grapes"
]
},
"updated": "2021-07-27T13:48:37.877Z",
"created": "2018-11-13T19:46:22.564Z",
"user": "5bede5cde8dd7e5d5df79aa9"
},
"survey": "62bb20e8afac21b873847d7f",
"comments": 0,
"firstResponse": "2018-12-10T22:42:58.133Z",
"lastResponse": "2022-05-27T20:08:35.738Z",
"responses": 46,
"answered": 38,
"unanswered": 8,
"summary": [
{
"label": "Apples",
"total": 5
},
{
"label": "Oranges",
"total": 15
},
{
"label": "Peaches",
"total": 13
},
{
"label": "Grapes",
"total": 5
},
{
"label": "__archived__",
"total": 0
}
]
}
} List all answers
Retrieves all answers for a survey participant or question.
/v1/answersQuery Parameters
| Name | Type | Description |
|---|---|---|
| participant | String | Unique id of the participant to retrieve answers for. Either participant or question id is required. |
| question | String | Unique id of the question to retrieve answers for. Either participant or question id is required. |
| reverse | Boolean | optional Sort list in reverse chronological order |
| after | String | optional The unique id which defines a cursor for paginating. When defined only retrieve list after this id. |
| before | String | optional The unique id which defines a cursor for paginating. When defined only retrieve list before this id. |
| select | String | optional A URL encoded string of properties to include. If not specified all fields are returned. Use a |
Examples
curl https://api.surveyplanet.com/v1/answers?participant=62b9db151489dd913aeaa22f
--header "Authorization: Bearer <ACCESS_TOKEN>"// For Node.js considering using the 'node-fetch' library: npm info node-fetch
const urlSearchParams = new URLSearchParams({ participant: '62b9db151489dd913aeaa22f' });
fetch(`https://api.surveyplanet.com/v1/answers?urlSearchParams`, {
headers: { Authorization: 'Bearer <ACCESS_TOKEN>' },
})
.then((response) => response.json())
.then((res) => console.log(res.data))
.catch((err) => console.error(err));# This code sample uses the 'requests' library: pip show requests
import requests
query = {"participant":"62b9db151489dd913aeaa22f"}
response = requests.get(
"https://api.surveyplanet.com/v1/answers",
headers={"Authorization": "Bearer <ACCESS_TOKEN>"}
params=query
)
print(response.text)Success response example
Success response example - Response
{
"status": 200,
"data": [
{ "_id": "62b9e7467854aef07faa746a",...},
{ "_id": "55d8aa7f2c5105f22fea7cbf",...},
[...],
],
"more": true,
"type": "ok",
"message": "Request worked as expected."
}