# Create a subscription POST https://api.prolific.com/api/v1/hooks/subscriptions/ Content-Type: application/json Create a subscription for an event type. When an event is triggered in the Prolific system, the hook will automatically notify the specified target URL. Before creating a subscription, you must ensure that you have created a secret for your workspace. Reference: https://beta-docs.prolific.com/api-reference/webhooks/create-subscription ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Create a subscription version: endpoint_webhooks.CreateSubscription paths: /api/v1/hooks/subscriptions/: post: operationId: create-subscription summary: Create a subscription description: >- Create a subscription for an event type. When an event is triggered in the Prolific system, the hook will automatically notify the specified target URL. Before creating a subscription, you must ensure that you have created a secret for your workspace. tags: - - subpackage_webhooks parameters: - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '201': description: Created content: application/json: schema: $ref: '#/components/schemas/SubscriptionList' '400': description: Error content: {} requestBody: content: application/json: schema: $ref: '#/components/schemas/SubscriptionDetail' components: schemas: SubscriptionDetail: type: object properties: id: type: string description: The ID of the subscription. event_type: type: string description: The name of the event type associated to the subscription. target_url: type: string description: >- The URL that the subscription will notify when your event type is triggered. is_enabled: type: boolean description: Whether the subscription is enabled or not. workspace_id: type: string description: The ID of the workspace we will create the subscription in. required: - event_type - target_url - workspace_id SubscriptionList: type: object properties: results: type: array items: $ref: '#/components/schemas/SubscriptionDetail' description: List of all subscriptions. required: - results ``` ## SDK Code Examples ```python import requests url = "https://api.prolific.com/api/v1/hooks/subscriptions/" payload = { "event_type": "study.status.change", "target_url": "https://webhook.prolific.co/api/v1/notifications/study-status", "workspace_id": "63722982f9cc073ecc730f6b" } 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/hooks/subscriptions/'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"event_type":"study.status.change","target_url":"https://webhook.prolific.co/api/v1/notifications/study-status","workspace_id":"63722982f9cc073ecc730f6b"}' }; 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/hooks/subscriptions/" payload := strings.NewReader("{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://webhook.prolific.co/api/v1/notifications/study-status\",\n \"workspace_id\": \"63722982f9cc073ecc730f6b\"\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/hooks/subscriptions/") 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 \"event_type\": \"study.status.change\",\n \"target_url\": \"https://webhook.prolific.co/api/v1/notifications/study-status\",\n \"workspace_id\": \"63722982f9cc073ecc730f6b\"\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.prolific.com/api/v1/hooks/subscriptions/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://webhook.prolific.co/api/v1/notifications/study-status\",\n \"workspace_id\": \"63722982f9cc073ecc730f6b\"\n}") .asString(); ``` ```php request('POST', 'https://api.prolific.com/api/v1/hooks/subscriptions/', [ 'body' => '{ "event_type": "study.status.change", "target_url": "https://webhook.prolific.co/api/v1/notifications/study-status", "workspace_id": "63722982f9cc073ecc730f6b" }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/hooks/subscriptions/"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://webhook.prolific.co/api/v1/notifications/study-status\",\n \"workspace_id\": \"63722982f9cc073ecc730f6b\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "event_type": "study.status.change", "target_url": "https://webhook.prolific.co/api/v1/notifications/study-status", "workspace_id": "63722982f9cc073ecc730f6b" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/hooks/subscriptions/")! 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() ```