highlevel_api/apis/webhooks/
client.rs1use super::types::*;
2use crate::{error::Result, http::HttpClient};
3use std::sync::Arc;
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
21 .get_with_query("/webhooks", &Q { location_id })
22 .await
23 }
24
25 pub async fn get(&self, webhook_id: &str) -> Result<GetWebhookResponse> {
26 self.http.get(&format!("/webhooks/{webhook_id}")).await
27 }
28
29 pub async fn create(
30 &self,
31 location_id: &str,
32 params: &CreateWebhookParams,
33 ) -> Result<GetWebhookResponse> {
34 #[derive(serde::Serialize)]
35 struct Body<'a> {
36 #[serde(rename = "locationId")]
37 location_id: &'a str,
38 name: &'a str,
39 url: &'a str,
40 events: &'a Vec<String>,
41 }
42 self.http
43 .post(
44 "/webhooks",
45 &Body {
46 location_id,
47 name: ¶ms.name,
48 url: ¶ms.url,
49 events: ¶ms.events,
50 },
51 )
52 .await
53 }
54
55 pub async fn update(
56 &self,
57 webhook_id: &str,
58 params: &UpdateWebhookParams,
59 ) -> Result<GetWebhookResponse> {
60 self.http
61 .put(&format!("/webhooks/{webhook_id}"), params)
62 .await
63 }
64
65 pub async fn delete(&self, webhook_id: &str) -> Result<DeleteWebhookResponse> {
66 self.http.delete(&format!("/webhooks/{webhook_id}")).await
67 }
68}