# Create survey POST https://api.prolific.com/api/v1/surveys/ Content-Type: application/json You can create a survey with either `sections -> questions` or just `questions`. This allows you to decide how much flexibility you want in your survey design. However, if you want to render the survey in the Prolific Application, you must use `sections`. Reference: https://beta-docs.prolific.com/api-reference/surveys/create-survey ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Create survey version: endpoint_surveys.CreateSurvey paths: /api/v1/surveys/: post: operationId: create-survey summary: Create survey description: >- You can create a survey with either `sections -> questions` or just `questions`. This allows you to decide how much flexibility you want in your survey design. However, if you want to render the survey in the Prolific Application, you must use `sections`. tags: - - subpackage_surveys parameters: - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '201': description: Successful Response content: application/json: schema: $ref: '#/components/schemas/SurveyOut' '400': description: Error content: {} requestBody: content: application/json: schema: $ref: '#/components/schemas/SurveyIn' components: schemas: SurveyAnswerOption: type: object properties: id: type: string format: uuid value: type: string description: The answer option value that can be selected. required: - value SurveyQuestionType: type: string enum: - value: single - value: multiple SurveyQuestion: type: object properties: answers: type: array items: $ref: '#/components/schemas/SurveyAnswerOption' description: An array of answer options for a question. id: type: string format: uuid title: type: string description: The question title. type: $ref: '#/components/schemas/SurveyQuestionType' description: The type of question being asked. required: - answers - title - type SurveySection: type: object properties: id: type: string format: uuid description: Auto generated by the system. questions: type: array items: $ref: '#/components/schemas/SurveyQuestion' description: An array of questions a section within a Survey. title: type: string description: The section title. required: - questions - title SurveyIn: type: object properties: researcher_id: type: string description: The Prolific researcher ID. sections: type: array items: $ref: '#/components/schemas/SurveySection' description: An array of sections in the survey, or use `questions`. questions: type: array items: $ref: '#/components/schemas/SurveyQuestion' description: An array of questions in the survey, or use `sections`. title: type: string description: The survey title. required: - researcher_id - title SurveyOut: type: object properties: _id: type: string description: Auto generated by the system. date_created: type: string format: date-time description: The date/time the survey was created (UTC). date_modified: type: string format: date-time description: The date/time the survey was modified (UTC). researcher_id: type: string description: The Prolific researcher ID. sections: type: array items: $ref: '#/components/schemas/SurveySection' description: >- Optional: An array of sections in the survey, otherwise `questions` will be defined. questions: type: array items: $ref: '#/components/schemas/SurveyQuestion' description: >- Optional: An array of questions in the survey, otherwise `sections` will be defined. title: type: string description: The survey title. required: - researcher_id - title ``` ## SDK Code Examples ```python import requests url = "https://api.prolific.com/api/v1/surveys/" payload = { "researcher_id": "7172727272", "title": "A survey with questions", "questions": [ { "answers": [ { "value": "Potato", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ], "title": "What is your favourite root vegetable?", "type": "single", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ] } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.prolific.com/api/v1/surveys/'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"researcher_id":"7172727272","title":"A survey with questions","questions":[{"answers":[{"value":"Potato","id":"497f6eca-6276-4993-bfeb-53cbbbba6f08"}],"title":"What is your favourite root vegetable?","type":"single","id":"497f6eca-6276-4993-bfeb-53cbbbba6f08"}]}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.prolific.com/api/v1/surveys/" payload := strings.NewReader("{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with questions\",\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.prolific.com/api/v1/surveys/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with questions\",\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.prolific.com/api/v1/surveys/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with questions\",\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.prolific.com/api/v1/surveys/', [ 'body' => '{ "researcher_id": "7172727272", "title": "A survey with questions", "questions": [ { "answers": [ { "value": "Potato", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ], "title": "What is your favourite root vegetable?", "type": "single", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ] }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/surveys/"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with questions\",\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "researcher_id": "7172727272", "title": "A survey with questions", "questions": [ [ "answers": [ [ "value": "Potato", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" ] ], "title": "What is your favourite root vegetable?", "type": "single", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/surveys/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ```python import requests url = "https://api.prolific.com/api/v1/surveys/" payload = { "researcher_id": "7172727272", "title": "A survey with sections and questions", "sections": [ { "questions": [ { "answers": [ { "value": "Potato", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ], "title": "What is your favourite root vegetable?", "type": "single", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ], "title": "Root vegetables", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ] } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.prolific.com/api/v1/surveys/'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"researcher_id":"7172727272","title":"A survey with sections and questions","sections":[{"questions":[{"answers":[{"value":"Potato","id":"497f6eca-6276-4993-bfeb-53cbbbba6f08"}],"title":"What is your favourite root vegetable?","type":"single","id":"497f6eca-6276-4993-bfeb-53cbbbba6f08"}],"title":"Root vegetables","id":"497f6eca-6276-4993-bfeb-53cbbbba6f08"}]}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.prolific.com/api/v1/surveys/" payload := strings.NewReader("{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with sections and questions\",\n \"sections\": [\n {\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"Root vegetables\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.prolific.com/api/v1/surveys/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with sections and questions\",\n \"sections\": [\n {\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"Root vegetables\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.prolific.com/api/v1/surveys/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with sections and questions\",\n \"sections\": [\n {\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"Root vegetables\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.prolific.com/api/v1/surveys/', [ 'body' => '{ "researcher_id": "7172727272", "title": "A survey with sections and questions", "sections": [ { "questions": [ { "answers": [ { "value": "Potato", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ], "title": "What is your favourite root vegetable?", "type": "single", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ], "title": "Root vegetables", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" } ] }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/surveys/"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"researcher_id\": \"7172727272\",\n \"title\": \"A survey with sections and questions\",\n \"sections\": [\n {\n \"questions\": [\n {\n \"answers\": [\n {\n \"value\": \"Potato\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"What is your favourite root vegetable?\",\n \"type\": \"single\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ],\n \"title\": \"Root vegetables\",\n \"id\": \"497f6eca-6276-4993-bfeb-53cbbbba6f08\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "researcher_id": "7172727272", "title": "A survey with sections and questions", "sections": [ [ "questions": [ [ "answers": [ [ "value": "Potato", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" ] ], "title": "What is your favourite root vegetable?", "type": "single", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" ] ], "title": "Root vegetables", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/surveys/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```