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 InvoicesApi {
    http: Arc<HttpClient>,
}

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

    pub async fn list(&self, params: &ListInvoicesParams) -> Result<GetInvoicesResponse> {
        self.http.get_with_query("/invoices", params).await
    }

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

    pub async fn create(&self, params: &CreateInvoiceParams) -> Result<GetInvoiceResponse> {
        self.http.post("/invoices", params).await
    }

    pub async fn update(
        &self,
        invoice_id: &str,
        params: &CreateInvoiceParams,
    ) -> Result<GetInvoiceResponse> {
        self.http
            .put(&format!("/invoices/{invoice_id}"), params)
            .await
    }

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

    pub async fn send(
        &self,
        invoice_id: &str,
        params: &SendInvoiceParams,
    ) -> Result<GetInvoiceResponse> {
        self.http
            .post(&format!("/invoices/{invoice_id}/send"), params)
            .await
    }

    pub async fn record_payment(
        &self,
        invoice_id: &str,
        params: &RecordPaymentParams,
    ) -> Result<GetInvoiceResponse> {
        self.http
            .post(&format!("/invoices/{invoice_id}/record-payment"), params)
            .await
    }

    pub async fn generate_invoice_number(
        &self,
        location_id: &str,
    ) -> Result<GenerateInvoiceNumberResponse> {
        #[derive(serde::Serialize)]
        struct Body<'a> {
            #[serde(rename = "locationId")]
            location_id: &'a str,
        }
        self.http
            .post("/invoices/generate-invoice-number", &Body { location_id })
            .await
    }

    // ── Schedules (deposit/balance split) ─────────────────────────────────────

    pub async fn list_schedules(&self, invoice_id: &str) -> Result<ListSchedulesResponse> {
        self.http
            .get(&format!("/invoices/{invoice_id}/schedules"))
            .await
    }

    pub async fn create_schedule(
        &self,
        invoice_id: &str,
        params: &CreateScheduleParams,
    ) -> Result<GetScheduleResponse> {
        self.http
            .post(&format!("/invoices/{invoice_id}/schedules"), params)
            .await
    }
}