Answers

Get an answer

Back to top

Retrieves a single answers by id.

GET
/v1/answer/:id

Parameters - Parameter

NameTypeDescription
idString

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

Back to top

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.

POST
/v1/results/question

Request Body

NameTypeDescription
questionString

The ID of the question to retrieve results for.

filtersObject[]optional

A list of filters to apply to the summary.

filter.keyString

The answer property to filter on e.g.: values, values.label, values.0, created, participant.

filter.valueMixed

The value to filter answers by.

filter.operatorStringoptional

The comparison operator. Options: eq: filter value equals, ne: filter value does not equal, gt: filter value is greater than, lt: filter value is less than, in: filter value is in array, or elemMatch: filter value matches both property and value (good for form questions where you might need to match both label and input value),

Default value: eq
filter.dataTypeStringoptional

The data type of value. Options: string, number, boolean, date, regex, or objectid

Default value: string
matchAnyBooleanoptional

Match any filter using ‘or’ instead of the default ‘and’.

Default value: false
limitNumberoptional

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

Back to top

Retrieves all answers for a survey participant or question.

GET
/v1/answers

Query Parameters

NameTypeDescription
participantString

Unique id of the participant to retrieve answers for. Either participant or question id is required.

questionString

Unique id of the question to retrieve answers for. Either participant or question id is required.

reverseBooleanoptional

Sort list in reverse chronological order

afterStringoptional

The unique id which defines a cursor for paginating. When defined only retrieve list after this id.

beforeStringoptional

The unique id which defines a cursor for paginating. When defined only retrieve list before this id.

selectStringoptional

A URL encoded string of properties to include. If not specified all fields are returned. Use a - to exclude a specific field e.g:-title.

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."
}