# Create filter set POST https://api.prolific.com/api/v1/filter-sets/ Content-Type: application/json Create a filter set from a list of filters Reference: https://beta-docs.prolific.com/api-reference/filter-sets/create-filter-set ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Create filter set version: endpoint_filterSets.CreateFilterSet paths: /api/v1/filter-sets/: post: operationId: create-filter-set summary: Create filter set description: Create a filter set from a list of filters tags: - - subpackage_filterSets parameters: - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '201': description: Filter set created content: application/json: schema: $ref: '#/components/schemas/Filter Sets_CreateFilterSet_Response_201' '400': description: Error content: {} requestBody: content: application/json: schema: $ref: '#/components/schemas/CreateFilterSet' components: schemas: SelectFilter: type: object properties: filter_id: type: string description: ID of the "select" type filter. selected_values: type: array items: type: string description: >- This schema applies for filters of the `select` type, as defined in the [filter list response](\#tag/Filters/paths/~1api~1v1~1filters~1/get). Array of IDs matching the response IDs, from the `select` filter's `choices` (see response linked above). String format should match the `data_type` of the `select` filter's `choices` (see response linked above). weightings: type: object additionalProperties: type: number format: double description: >- Ratios to control the distribution of participants across the selected values. Integer percentages, floats, and exact quantities are valid inputs. required: - filter_id - selected_values RangeFilterSelectedRangeLower: oneOf: - type: integer - type: string - type: number format: double RangeFilterSelectedRangeUpper: oneOf: - type: integer - type: string - type: number format: double RangeFilterSelectedRange: type: object properties: lower: $ref: '#/components/schemas/RangeFilterSelectedRangeLower' description: Your selected lower bound for the range. upper: $ref: '#/components/schemas/RangeFilterSelectedRangeUpper' description: Your selected upper bound for the range. RangeFilterWeightingsSelectedRangeLower: oneOf: - type: integer - type: string - type: number format: double RangeFilterWeightingsSelectedRangeUpper: oneOf: - type: integer - type: string - type: number format: double RangeFilterWeightingsSelectedRange: type: object properties: lower: $ref: '#/components/schemas/RangeFilterWeightingsSelectedRangeLower' upper: $ref: '#/components/schemas/RangeFilterWeightingsSelectedRangeUpper' RangeFilterWeightings: type: object properties: selected_range: $ref: '#/components/schemas/RangeFilterWeightingsSelectedRange' weighting: type: number format: double required: - selected_range - weighting RangeFilter: type: object properties: filter_id: type: string description: ID of the "range" type filter. selected_range: $ref: '#/components/schemas/RangeFilterSelectedRange' description: >- This schema applies for filters of the `range` type, as defined in the [filter list response](\#tag/Filters/paths/~1api~1v1~1filters~1/get). A dictionary with two possible objects, 'lower' and 'upper'. At least one must be present and a non-null value. The expected data type for these values is defined by the `range` filter's `data_type` (see response linked above). If the data_type is a date, string format should be a parseable ISO8601 date string. Date values should be provided as a string in ISO 8601 format. Leaving a value as null will result in that bound being set to the lowest or highest possible value, depending on whether it is the upper or lower bound. weightings: $ref: '#/components/schemas/RangeFilterWeightings' description: >- Ratios to control the distribution of participants across the selected values. Integers and exact quantities are valid inputs. required: - filter_id - selected_range CreateFilterSetFiltersItems: oneOf: - $ref: '#/components/schemas/SelectFilter' - $ref: '#/components/schemas/RangeFilter' CreateFilterSet: type: object properties: workspace_id: type: string description: ID of the workspace where the filter set can be used. organisation_id: type: string description: ID of the organisation where the filter set can be used. name: type: string description: Name of the filter set. filters: type: array items: $ref: '#/components/schemas/CreateFilterSetFiltersItems' description: List of all filters contained in the filter set. FilterSetFiltersItems: oneOf: - $ref: '#/components/schemas/SelectFilter' - $ref: '#/components/schemas/RangeFilter' Filter Sets_CreateFilterSet_Response_201: type: object properties: id: type: string description: ID of the filter set. version: type: integer description: An incrementing integer indicating the version of the filter set. is_deleted: type: boolean description: Whether the filter set has been deleted. is_locked: type: boolean description: Whether the filter set has been locked. workspace_id: type: - string - 'null' description: ID of the workspace where the filter set can be used. organisation_id: type: - string - 'null' description: ID of the workspace where the filter set can be used. name: type: string description: Name of the filter set. filters: type: array items: $ref: '#/components/schemas/FilterSetFiltersItems' description: List of all filters contained in the filter set. eligible_participant_count: type: integer description: >- The number of participants who match the filter sets filters. Please note that if the number is lower than 25 the count will be obscured to prevent identification of participants. ``` ## SDK Code Examples ```python import requests url = "https://api.prolific.com/api/v1/filter-sets/" payload = { "workspace_id": "644aaabfaf6bbc363b9d47c6", "name": "Ambidextrous teenagers", "filters": [ { "filter_id": "handedness", "selected_values": ["ambidextrous"] }, { "filter_id": "age", "selected_values": ["19-22"] } ] } 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/filter-sets/'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"workspace_id":"644aaabfaf6bbc363b9d47c6","name":"Ambidextrous teenagers","filters":[{"filter_id":"handedness","selected_values":["ambidextrous"]},{"filter_id":"age","selected_values":["19-22"]}]}' }; 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/filter-sets/" payload := strings.NewReader("{\n \"workspace_id\": \"644aaabfaf6bbc363b9d47c6\",\n \"name\": \"Ambidextrous teenagers\",\n \"filters\": [\n {\n \"filter_id\": \"handedness\",\n \"selected_values\": [\n \"ambidextrous\"\n ]\n },\n {\n \"filter_id\": \"age\",\n \"selected_values\": [\n \"19-22\"\n ]\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/filter-sets/") 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 \"workspace_id\": \"644aaabfaf6bbc363b9d47c6\",\n \"name\": \"Ambidextrous teenagers\",\n \"filters\": [\n {\n \"filter_id\": \"handedness\",\n \"selected_values\": [\n \"ambidextrous\"\n ]\n },\n {\n \"filter_id\": \"age\",\n \"selected_values\": [\n \"19-22\"\n ]\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.prolific.com/api/v1/filter-sets/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"workspace_id\": \"644aaabfaf6bbc363b9d47c6\",\n \"name\": \"Ambidextrous teenagers\",\n \"filters\": [\n {\n \"filter_id\": \"handedness\",\n \"selected_values\": [\n \"ambidextrous\"\n ]\n },\n {\n \"filter_id\": \"age\",\n \"selected_values\": [\n \"19-22\"\n ]\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.prolific.com/api/v1/filter-sets/', [ 'body' => '{ "workspace_id": "644aaabfaf6bbc363b9d47c6", "name": "Ambidextrous teenagers", "filters": [ { "filter_id": "handedness", "selected_values": [ "ambidextrous" ] }, { "filter_id": "age", "selected_values": [ "19-22" ] } ] }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/filter-sets/"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"workspace_id\": \"644aaabfaf6bbc363b9d47c6\",\n \"name\": \"Ambidextrous teenagers\",\n \"filters\": [\n {\n \"filter_id\": \"handedness\",\n \"selected_values\": [\n \"ambidextrous\"\n ]\n },\n {\n \"filter_id\": \"age\",\n \"selected_values\": [\n \"19-22\"\n ]\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "workspace_id": "644aaabfaf6bbc363b9d47c6", "name": "Ambidextrous teenagers", "filters": [ [ "filter_id": "handedness", "selected_values": ["ambidextrous"] ], [ "filter_id": "age", "selected_values": ["19-22"] ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/filter-sets/")! 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() ```