# Update a subscription PATCH https://api.prolific.com/api/v1/hooks/subscriptions/{subscription_id}/ Content-Type: application/json This allows you to update a subscription. For example you can temporarily disable or enable a subscription if you wish. Reference: https://beta-docs.prolific.com/api-reference/webhooks/update-subscription ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Update a subscription version: endpoint_webhooks.UpdateSubscription paths: /api/v1/hooks/subscriptions/{subscription_id}/: patch: operationId: update-subscription summary: Update a subscription description: >- This allows you to update a subscription. For example you can temporarily disable or enable a subscription if you wish. tags: - - subpackage_webhooks parameters: - name: subscription_id in: path description: Subscription id required: true schema: type: string - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '200': description: Updated content: application/json: schema: $ref: '#/components/schemas/SubscriptionDetail' '400': description: Error content: {} requestBody: content: application/json: schema: $ref: '#/components/schemas/SubscriptionUpdateDetail' components: schemas: SubscriptionUpdateDetail: type: object properties: 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. 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 ``` ## SDK Code Examples ```python import requests url = "https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/" payload = { "event_type": "study.status.change", "target_url": "https://hooks.example.com/api/v1/notifications", "is_enabled": False } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.patch(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/'; const options = { method: 'PATCH', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"event_type":"study.status.change","target_url":"https://hooks.example.com/api/v1/notifications","is_enabled":false}' }; 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/subscription_id/" payload := strings.NewReader("{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\n}") req, _ := http.NewRequest("PATCH", 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/subscription_id/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Patch.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.patch("https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\n}") .asString(); ``` ```php request('PATCH', 'https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/', [ 'body' => '{ "event_type": "study.status.change", "target_url": "https://hooks.example.com/api/v1/notifications", "is_enabled": false }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/"); var request = new RestRequest(Method.PATCH); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\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://hooks.example.com/api/v1/notifications", "is_enabled": false ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PATCH" 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/hooks/subscriptions/subscription_id/" payload = { "event_type": "study.status.change", "target_url": "https://hooks.example.com/api/v1/notifications", "is_enabled": False } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.patch(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/'; const options = { method: 'PATCH', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"event_type":"study.status.change","target_url":"https://hooks.example.com/api/v1/notifications","is_enabled":false}' }; 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/subscription_id/" payload := strings.NewReader("{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\n}") req, _ := http.NewRequest("PATCH", 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/subscription_id/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Patch.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.patch("https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\n}") .asString(); ``` ```php request('PATCH', 'https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/', [ 'body' => '{ "event_type": "study.status.change", "target_url": "https://hooks.example.com/api/v1/notifications", "is_enabled": false }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/"); var request = new RestRequest(Method.PATCH); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"event_type\": \"study.status.change\",\n \"target_url\": \"https://hooks.example.com/api/v1/notifications\",\n \"is_enabled\": false\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://hooks.example.com/api/v1/notifications", "is_enabled": false ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.prolific.com/api/v1/hooks/subscriptions/subscription_id/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PATCH" 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() ```