POST /surveys/responses
Submit panelist votes for survey questions.
Request
POST /public/surveys/
Headers
| Header | Required | Description |
|---|---|---|
| Authorization | Yes | Compound token from Tenant API |
| Content-Type | Yes | application/json |
Request Body
{
"responses": {
"question-id-1": { "optionIds": ["3"] },
"question-id-2": { "optionIds": ["yes"] }
},
"isFinal": true
}
Options Object
For single-choice questions:
{ "optionId": "3" }
or
{ "optionIds": ["3"] }
For multiple-choice questions:
{ "optionIds": ["1", "3", "5"] }
Body Fields
| Field | Type | Description |
|---|---|---|
| responses | object | Map of questionId to response |
| isFinal | boolean | Whether this is the final submission for the survey (answer to the final question) |
Note: You can submit partial responses to questions in a survey, with isFinal equal to false. YOU MUST submit the final batch of answers with isFinal equal to true.
Response
{
"count": 2
}
Response Fields
| Field | Type | Description |
|---|---|---|
| count | integer | Number of responses recorded |
Examples
JavaScript
const submitVotes = async (publicKey, responses, isFinal = true) => {
const response = await fetch('https://api.votito.com/public/surveys/', {
method: 'POST',
headers: {
'Authorization': publicKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({ responses, isFinal })
});
if (!response.ok) {
throw new Error(`Failed to submit: ${response.status}`);
}
return response.json();
};
// Usage
const result = await submitVotes(publicKey, {
'q1': { optionId: '4' },
'q2': { optionId: 'yes' }
});
console.log(`Submitted ${result.count} responses`);
React Form Handler
const handleSubmit = async (event) => {
event.preventDefault();
const formData = new FormData(event.target);
const responses = {};
survey.questions.forEach(q => {
const value = formData.get(q.questionId);
if (value) {
responses[q.questionId] = { optionId: value };
}
});
try {
await submitVotes(publicKey, responses);
setSubmitted(true);
} catch (error) {
setError('Failed to submit survey');
}
};
Python
import requests
def submit_votes(public_key, responses, is_final=True):
response = requests.post(
"https://api.votito.com/public/surveys/",
headers={
"Authorization": public_key,
"Content-Type": "application/json"
},
json={
"responses": responses,
"isFinal": is_final
}
)
response.raise_for_status()
return response.json()
# Usage
result = submit_votes(public_key, {
"q1": {"optionId": "4"},
"q2": {"optionId": "yes"}
})
print(f"Submitted {result['count']} responses")
Incremental Submissions
Set isFinal: false to save partial responses:
// Save progress without finalizing
await submitVotes(publicKey, { 'q1': { optionId: '3' } }, false);
// Later, finalize the submission
await submitVotes(publicKey, { 'q2': { optionId: 'yes' } }, true);
Error Responses
400 Bad Request
{
"error": "invalid_response",
"details": "Missing required question: q1"
}
401 Unauthorized
Invalid or missing authorization token.
403 Forbidden
- Survey is closed
- Panelist has already submitted a final response (when multiple responses disabled)