Create a Question
Creates a Question, with its options, nested under the given Study.
curl --request POST \
--url https://api.sprig.com/v2/studies/{studyId}/questions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--header 'If-Match: <if-match>' \
--data '
{
"title": {
"html": "<string>",
"variables": {}
},
"type": "OPEN_TEXT",
"name": "<string>",
"required": false,
"randomizePosition": true,
"blockId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"responsePlaceholder": "<string>"
}
'import requests
url = "https://api.sprig.com/v2/studies/{studyId}/questions"
payload = {
"title": {
"html": "<string>",
"variables": {}
},
"type": "OPEN_TEXT",
"name": "<string>",
"required": False,
"randomizePosition": True,
"blockId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"responsePlaceholder": "<string>"
}
headers = {
"If-Match": "<if-match>",
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'If-Match': '<if-match>',
Authorization: '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: {html: '<string>', variables: {}},
type: 'OPEN_TEXT',
name: '<string>',
required: false,
randomizePosition: true,
blockId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
responsePlaceholder: '<string>'
})
};
fetch('https://api.sprig.com/v2/studies/{studyId}/questions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sprig.com/v2/studies/{studyId}/questions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'title' => [
'html' => '<string>',
'variables' => [
]
],
'type' => 'OPEN_TEXT',
'name' => '<string>',
'required' => false,
'randomizePosition' => true,
'blockId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'responsePlaceholder' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json",
"If-Match: <if-match>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sprig.com/v2/studies/{studyId}/questions"
payload := strings.NewReader("{\n \"title\": {\n \"html\": \"<string>\",\n \"variables\": {}\n },\n \"type\": \"OPEN_TEXT\",\n \"name\": \"<string>\",\n \"required\": false,\n \"randomizePosition\": true,\n \"blockId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"responsePlaceholder\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("If-Match", "<if-match>")
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sprig.com/v2/studies/{studyId}/questions")
.header("If-Match", "<if-match>")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"title\": {\n \"html\": \"<string>\",\n \"variables\": {}\n },\n \"type\": \"OPEN_TEXT\",\n \"name\": \"<string>\",\n \"required\": false,\n \"randomizePosition\": true,\n \"blockId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"responsePlaceholder\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sprig.com/v2/studies/{studyId}/questions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["If-Match"] = '<if-match>'
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"title\": {\n \"html\": \"<string>\",\n \"variables\": {}\n },\n \"type\": \"OPEN_TEXT\",\n \"name\": \"<string>\",\n \"required\": false,\n \"randomizePosition\": true,\n \"blockId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"responsePlaceholder\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"title": {
"html": "<string>",
"variables": {}
},
"required": true,
"displayLogic": {
"source": {
"type": "QUESTION_RESPONSE",
"question": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>"
}
},
"operator": "EQUALS",
"value": "<string>"
},
"skipLogic": [
{
"when": {
"source": {
"type": "QUESTION_RESPONSE",
"question": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>"
}
},
"operator": "EQUALS",
"value": "<string>"
},
"destination": {
"type": "END"
}
}
],
"aiFollowUp": {
"userPrompt": "<string>"
},
"randomizePosition": true,
"type": "OPEN_TEXT",
"name": "<string>",
"description": {
"html": "<string>",
"variables": {}
},
"image": {
"url": "<string>",
"altText": "<string>",
"displaySize": "FIT",
"alignment": "LEFT",
"width": 123,
"height": 123,
"mediaType": "image/gif",
"originalFilename": "<string>",
"assetId": "<string>"
},
"responsePlaceholder": "<string>"
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}Authorizations
Use API-Key YOUR_API_KEY. The key selects the Production or Development environment.
Headers
Quoted Study version last read from ETag or Study.version. Required on mutating Study writes.
"\"126300\""
Path Parameters
Body
- Open text
- Single select
- Multiple select
- Rating scale
- NPS
- Validated text
- Rank order
- Matrix
- MaxDiff
- Text / URL prompt
- Consent / legal
- AI dynamic
- Conjoint
Supported Question input for the Study creation API.
The authored title accepted when creating a Question.
Show child attributes
Show child attributes
OPEN_TEXT Optional stable caller-defined name, unique within the Study.
1 - 128Whether the respondent must answer the Question.
Whether this Question participates in layout-position randomization. Defaults to false.
Placement relative to a Question or Block in the Study. BEFORE a Block uses that Block's slot. AFTER a Block lands after its subtree.
Show child attributes
Show child attributes
Public UUID of the Block that will contain this Question.
Optional respondent-facing description shown with a Question.
Show child attributes
Show child attributes
Attaches a QUESTION_IMAGE recorded on this Study. A Consent / Legal question can have this and a consent document.
Show child attributes
Show child attributes
Placeholder shown in the response field.
Response
Created
- Open text
- AI dynamic
- Single select
- Multiple select
- Rating scale
- NPS
- Validated text
- Rank order
- Matrix
- MaxDiff
- Text / URL prompt
- Consent / legal
- Conjoint
- File upload
Canonical Question resource.
Canonical rich-text Question title.
Show child attributes
Show child attributes
A single typed condition. Operators that inspect answer state omit value; choice comparisons use immutable Option values.
- Condition
- All of
- Any of
Show child attributes
Show child attributes
Ordered skip rules, limited to 20. An empty array clears skip logic.
20Show child attributes
Show child attributes
Show child attributes
Show child attributes
OPEN_TEXT Canonical respondent-facing Question description.
Show child attributes
Show child attributes
The image shown with a Question. Omitted when the Question has no image.
Show child attributes
Show child attributes
Placeholder shown in the response field.
Was this page helpful?
curl --request POST \
--url https://api.sprig.com/v2/studies/{studyId}/questions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--header 'If-Match: <if-match>' \
--data '
{
"title": {
"html": "<string>",
"variables": {}
},
"type": "OPEN_TEXT",
"name": "<string>",
"required": false,
"randomizePosition": true,
"blockId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"responsePlaceholder": "<string>"
}
'import requests
url = "https://api.sprig.com/v2/studies/{studyId}/questions"
payload = {
"title": {
"html": "<string>",
"variables": {}
},
"type": "OPEN_TEXT",
"name": "<string>",
"required": False,
"randomizePosition": True,
"blockId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"responsePlaceholder": "<string>"
}
headers = {
"If-Match": "<if-match>",
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'If-Match': '<if-match>',
Authorization: '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: {html: '<string>', variables: {}},
type: 'OPEN_TEXT',
name: '<string>',
required: false,
randomizePosition: true,
blockId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
responsePlaceholder: '<string>'
})
};
fetch('https://api.sprig.com/v2/studies/{studyId}/questions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sprig.com/v2/studies/{studyId}/questions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'title' => [
'html' => '<string>',
'variables' => [
]
],
'type' => 'OPEN_TEXT',
'name' => '<string>',
'required' => false,
'randomizePosition' => true,
'blockId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'responsePlaceholder' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json",
"If-Match: <if-match>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sprig.com/v2/studies/{studyId}/questions"
payload := strings.NewReader("{\n \"title\": {\n \"html\": \"<string>\",\n \"variables\": {}\n },\n \"type\": \"OPEN_TEXT\",\n \"name\": \"<string>\",\n \"required\": false,\n \"randomizePosition\": true,\n \"blockId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"responsePlaceholder\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("If-Match", "<if-match>")
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sprig.com/v2/studies/{studyId}/questions")
.header("If-Match", "<if-match>")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"title\": {\n \"html\": \"<string>\",\n \"variables\": {}\n },\n \"type\": \"OPEN_TEXT\",\n \"name\": \"<string>\",\n \"required\": false,\n \"randomizePosition\": true,\n \"blockId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"responsePlaceholder\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sprig.com/v2/studies/{studyId}/questions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["If-Match"] = '<if-match>'
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"title\": {\n \"html\": \"<string>\",\n \"variables\": {}\n },\n \"type\": \"OPEN_TEXT\",\n \"name\": \"<string>\",\n \"required\": false,\n \"randomizePosition\": true,\n \"blockId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"responsePlaceholder\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"title": {
"html": "<string>",
"variables": {}
},
"required": true,
"displayLogic": {
"source": {
"type": "QUESTION_RESPONSE",
"question": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>"
}
},
"operator": "EQUALS",
"value": "<string>"
},
"skipLogic": [
{
"when": {
"source": {
"type": "QUESTION_RESPONSE",
"question": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>"
}
},
"operator": "EQUALS",
"value": "<string>"
},
"destination": {
"type": "END"
}
}
],
"aiFollowUp": {
"userPrompt": "<string>"
},
"randomizePosition": true,
"type": "OPEN_TEXT",
"name": "<string>",
"description": {
"html": "<string>",
"variables": {}
},
"image": {
"url": "<string>",
"altText": "<string>",
"displaySize": "FIT",
"alignment": "LEFT",
"width": 123,
"height": 123,
"mediaType": "image/gif",
"originalFilename": "<string>",
"assetId": "<string>"
},
"responsePlaceholder": "<string>"
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}{
"code": "<string>",
"message": "<string>",
"errors": [
{
"code": "<string>",
"message": "<string>",
"path": "<string>",
"resource": {
"type": "<string>",
"id": "<string>"
}
}
]
}