Skip to main content

highlevel_api/apis/webhooks/
client.rs

1use std::sync::Arc;
2use crate::{error::Result, http::HttpClient};
3use super::types::*;
4
5pub struct WebhooksApi {
6    http: Arc<HttpClient>,
7}
8
9impl WebhooksApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    pub async fn list(&self, location_id: &str) -> Result<GetWebhooksResponse> {
15        #[derive(serde::Serialize)]
16        struct Q<'a> {
17            #[serde(rename = "locationId")]
18            location_id: &'a str,
19        }
20        self.http.get_with_query("/webhooks", &Q { location_id }).await
21    }
22
23    pub async fn get(&self, webhook_id: &str) -> Result<GetWebhookResponse> {
24        self.http.get(&format!("/webhooks/{webhook_id}")).await
25    }
26
27    pub async fn create(
28        &self,
29        location_id: &str,
30        params: &CreateWebhookParams,
31    ) -> Result<GetWebhookResponse> {
32        #[derive(serde::Serialize)]
33        struct Body<'a> {
34            #[serde(rename = "locationId")]
35            location_id: &'a str,
36            name: &'a str,
37            url: &'a str,
38            events: &'a Vec<String>,
39        }
40        self.http
41            .post(
42                "/webhooks",
43                &Body {
44                    location_id,
45                    name: &params.name,
46                    url: &params.url,
47                    events: &params.events,
48                },
49            )
50            .await
51    }
52
53    pub async fn update(
54        &self,
55        webhook_id: &str,
56        params: &UpdateWebhookParams,
57    ) -> Result<GetWebhookResponse> {
58        self.http.put(&format!("/webhooks/{webhook_id}"), params).await
59    }
60
61    pub async fn delete(&self, webhook_id: &str) -> Result<DeleteWebhookResponse> {
62        self.http.delete(&format!("/webhooks/{webhook_id}")).await
63    }
64}