# Add participants to a participant group POST https://api.prolific.com/api/v1/participant-groups/{id}/participants/ Content-Type: application/json Append participants to a participant group if they are not already members. If a participant is already a member of the group, they will be ignored. Reference: https://beta-docs.prolific.com/api-reference/participant-groups/add-to-participant-group ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Add participants to a participant group version: endpoint_participantGroups.AddToParticipantGroup paths: /api/v1/participant-groups/{id}/participants/: post: operationId: add-to-participant-group summary: Add participants to a participant group description: > Append participants to a participant group if they are not already members. If a participant is already a member of the group, they will be ignored. tags: - - subpackage_participantGroups parameters: - name: id in: path description: The id of the participant group to add the participant to required: true schema: type: string - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '200': description: All participant(s) now in participant group content: application/json: schema: $ref: '#/components/schemas/ParticipantGroupMembershipListResponse' '400': description: Error content: {} requestBody: content: application/json: schema: $ref: '#/components/schemas/ParticipantIDList' components: schemas: ParticipantIDList: type: object properties: participant_ids: type: array items: type: string ParticipantGroupMembership: type: object properties: participant_id: type: string description: The id of the participant datetime_created: type: string description: The date and time the participant was added to the Participant Group ParticipantGroupMembershipListResponse: type: object properties: results: type: array items: $ref: '#/components/schemas/ParticipantGroupMembership' ``` ## SDK Code Examples ```python import requests url = "https://api.prolific.com/api/v1/participant-groups/id/participants/" payload = { "participant_ids": ["5e9b9c9b0f9c9a0001b0b1f4", "5e9b9c9b0f9c9a0001b0b1f5", "5e9b9c9b0f9c9a0001b0b1f6"] } 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/participant-groups/id/participants/'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"participant_ids":["5e9b9c9b0f9c9a0001b0b1f4","5e9b9c9b0f9c9a0001b0b1f5","5e9b9c9b0f9c9a0001b0b1f6"]}' }; 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/participant-groups/id/participants/" payload := strings.NewReader("{\n \"participant_ids\": [\n \"5e9b9c9b0f9c9a0001b0b1f4\",\n \"5e9b9c9b0f9c9a0001b0b1f5\",\n \"5e9b9c9b0f9c9a0001b0b1f6\"\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/participant-groups/id/participants/") 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 \"participant_ids\": [\n \"5e9b9c9b0f9c9a0001b0b1f4\",\n \"5e9b9c9b0f9c9a0001b0b1f5\",\n \"5e9b9c9b0f9c9a0001b0b1f6\"\n ]\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.prolific.com/api/v1/participant-groups/id/participants/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"participant_ids\": [\n \"5e9b9c9b0f9c9a0001b0b1f4\",\n \"5e9b9c9b0f9c9a0001b0b1f5\",\n \"5e9b9c9b0f9c9a0001b0b1f6\"\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.prolific.com/api/v1/participant-groups/id/participants/', [ 'body' => '{ "participant_ids": [ "5e9b9c9b0f9c9a0001b0b1f4", "5e9b9c9b0f9c9a0001b0b1f5", "5e9b9c9b0f9c9a0001b0b1f6" ] }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/participant-groups/id/participants/"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"participant_ids\": [\n \"5e9b9c9b0f9c9a0001b0b1f4\",\n \"5e9b9c9b0f9c9a0001b0b1f5\",\n \"5e9b9c9b0f9c9a0001b0b1f6\"\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = ["participant_ids": ["5e9b9c9b0f9c9a0001b0b1f4", "5e9b9c9b0f9c9a0001b0b1f5", "5e9b9c9b0f9c9a0001b0b1f6"]] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/participant-groups/id/participants/")! 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() ```