highlevel-api 0.2.0

Unofficial Rust SDK for the GoHighLevel (HighLevel) API
Documentation
use super::types::*;
use crate::{error::Result, http::HttpClient};
use std::sync::Arc;

pub struct WebhooksApi {
    http: Arc<HttpClient>,
}

impl WebhooksApi {
    pub fn new(http: Arc<HttpClient>) -> Self {
        Self { http }
    }

    pub async fn list(&self, location_id: &str) -> Result<GetWebhooksResponse> {
        #[derive(serde::Serialize)]
        struct Q<'a> {
            #[serde(rename = "locationId")]
            location_id: &'a str,
        }
        self.http
            .get_with_query("/webhooks", &Q { location_id })
            .await
    }

    pub async fn get(&self, webhook_id: &str) -> Result<GetWebhookResponse> {
        self.http.get(&format!("/webhooks/{webhook_id}")).await
    }

    pub async fn create(
        &self,
        location_id: &str,
        params: &CreateWebhookParams,
    ) -> Result<GetWebhookResponse> {
        #[derive(serde::Serialize)]
        struct Body<'a> {
            #[serde(rename = "locationId")]
            location_id: &'a str,
            name: &'a str,
            url: &'a str,
            events: &'a Vec<String>,
        }
        self.http
            .post(
                "/webhooks",
                &Body {
                    location_id,
                    name: &params.name,
                    url: &params.url,
                    events: &params.events,
                },
            )
            .await
    }

    pub async fn update(
        &self,
        webhook_id: &str,
        params: &UpdateWebhookParams,
    ) -> Result<GetWebhookResponse> {
        self.http
            .put(&format!("/webhooks/{webhook_id}"), params)
            .await
    }

    pub async fn delete(&self, webhook_id: &str) -> Result<DeleteWebhookResponse> {
        self.http.delete(&format!("/webhooks/{webhook_id}")).await
    }
}