Skip to main content

fireblocks_sdk/apis/
webhooks_api.rs

1// Fireblocks API
2//
3// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
10    super::{Error, configuration},
11    crate::{
12        apis::{ContentType, ResponseContent},
13        models,
14    },
15    async_trait::async_trait,
16    reqwest,
17    serde::{Deserialize, Serialize, de::Error as _},
18    std::sync::Arc,
19};
20
21#[async_trait]
22pub trait WebhooksApi: Send + Sync {
23    /// POST /webhooks/resend/{txId}
24    ///
25    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
26    /// Please use the Developer Center in the Fireblocks Console to upgrade to
27    /// Webhooks v2, which offers improved reliability, performance, and
28    /// observability.  Resends webhook notifications for a transaction by its
29    /// unique identifier.  **Endpoint Permissions:** Admin, Non-Signing Admin,
30    /// Signer, Approver, Editor.
31    async fn resend_transaction_webhooks(
32        &self,
33        params: ResendTransactionWebhooksParams,
34    ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>;
35
36    /// POST /webhooks/resend
37    ///
38    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
39    /// Please use the Developer Center in the Fireblocks Console to upgrade to
40    /// Webhooks v2, which offers improved reliability, performance, and
41    /// observability.  Resends all failed webhook notifications.  </br>Endpoint
42    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
43    async fn resend_webhooks(
44        &self,
45        params: ResendWebhooksParams,
46    ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>>;
47}
48
49pub struct WebhooksApiClient {
50    configuration: Arc<configuration::Configuration>,
51}
52
53impl WebhooksApiClient {
54    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
55        Self { configuration }
56    }
57}
58
59/// struct for passing parameters to the method
60/// [`WebhooksApi::resend_transaction_webhooks`]
61#[derive(Clone, Debug)]
62#[cfg_attr(feature = "bon", derive(::bon::Builder))]
63pub struct ResendTransactionWebhooksParams {
64    /// The ID of the transaction for webhooks
65    pub tx_id: String,
66    pub resend_transaction_webhooks_request: models::ResendTransactionWebhooksRequest,
67    /// A unique identifier for the request. If the request is sent multiple
68    /// times with the same idempotency key, the server will return the same
69    /// response as the first request. The idempotency key is valid for 24
70    /// hours.
71    pub idempotency_key: Option<String>,
72}
73
74/// struct for passing parameters to the method [`WebhooksApi::resend_webhooks`]
75#[derive(Clone, Debug)]
76#[cfg_attr(feature = "bon", derive(::bon::Builder))]
77pub struct ResendWebhooksParams {
78    /// A unique identifier for the request. If the request is sent multiple
79    /// times with the same idempotency key, the server will return the same
80    /// response as the first request. The idempotency key is valid for 24
81    /// hours.
82    pub idempotency_key: Option<String>,
83}
84
85#[async_trait]
86impl WebhooksApi for WebhooksApiClient {
87    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
88    /// Please use the Developer Center in the Fireblocks Console to upgrade to
89    /// Webhooks v2, which offers improved reliability, performance, and
90    /// observability.  Resends webhook notifications for a transaction by its
91    /// unique identifier.  **Endpoint Permissions:** Admin, Non-Signing Admin,
92    /// Signer, Approver, Editor.
93    async fn resend_transaction_webhooks(
94        &self,
95        params: ResendTransactionWebhooksParams,
96    ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>
97    {
98        let ResendTransactionWebhooksParams {
99            tx_id,
100            resend_transaction_webhooks_request,
101            idempotency_key,
102        } = params;
103
104        let local_var_configuration = &self.configuration;
105
106        let local_var_client = &local_var_configuration.client;
107
108        let local_var_uri_str = format!(
109            "{}/webhooks/resend/{txId}",
110            local_var_configuration.base_path,
111            txId = crate::apis::urlencode(tx_id)
112        );
113        let mut local_var_req_builder =
114            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
115
116        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
117            local_var_req_builder = local_var_req_builder
118                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
119        }
120        if let Some(local_var_param_value) = idempotency_key {
121            local_var_req_builder =
122                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
123        }
124        local_var_req_builder = local_var_req_builder.json(&resend_transaction_webhooks_request);
125
126        let local_var_req = local_var_req_builder.build()?;
127        let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129        let local_var_status = local_var_resp.status();
130        let local_var_content_type = local_var_resp
131            .headers()
132            .get("content-type")
133            .and_then(|v| v.to_str().ok())
134            .unwrap_or("application/octet-stream");
135        let local_var_content_type = super::ContentType::from(local_var_content_type);
136        let local_var_content = local_var_resp.text().await?;
137
138        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139            match local_var_content_type {
140                ContentType::Json => {
141                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
142                }
143                ContentType::Text => {
144                    return Err(Error::from(serde_json::Error::custom(
145                        "Received `text/plain` content type response that cannot be converted to \
146                         `models::ResendWebhooksByTransactionIdResponse`",
147                    )));
148                }
149                ContentType::Unsupported(local_var_unknown_type) => {
150                    return Err(Error::from(serde_json::Error::custom(format!(
151                        "Received `{local_var_unknown_type}` content type response that cannot be \
152                         converted to `models::ResendWebhooksByTransactionIdResponse`"
153                    ))));
154                }
155            }
156        } else {
157            let local_var_entity: Option<ResendTransactionWebhooksError> =
158                serde_json::from_str(&local_var_content).ok();
159            let local_var_error = ResponseContent {
160                status: local_var_status,
161                content: local_var_content,
162                entity: local_var_entity,
163            };
164            Err(Error::ResponseError(local_var_error))
165        }
166    }
167
168    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
169    /// Please use the Developer Center in the Fireblocks Console to upgrade to
170    /// Webhooks v2, which offers improved reliability, performance, and
171    /// observability.  Resends all failed webhook notifications.  </br>Endpoint
172    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
173    async fn resend_webhooks(
174        &self,
175        params: ResendWebhooksParams,
176    ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>> {
177        let ResendWebhooksParams { idempotency_key } = params;
178
179        let local_var_configuration = &self.configuration;
180
181        let local_var_client = &local_var_configuration.client;
182
183        let local_var_uri_str = format!("{}/webhooks/resend", local_var_configuration.base_path);
184        let mut local_var_req_builder =
185            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
186
187        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
188            local_var_req_builder = local_var_req_builder
189                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
190        }
191        if let Some(local_var_param_value) = idempotency_key {
192            local_var_req_builder =
193                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
194        }
195
196        let local_var_req = local_var_req_builder.build()?;
197        let local_var_resp = local_var_client.execute(local_var_req).await?;
198
199        let local_var_status = local_var_resp.status();
200        let local_var_content_type = local_var_resp
201            .headers()
202            .get("content-type")
203            .and_then(|v| v.to_str().ok())
204            .unwrap_or("application/octet-stream");
205        let local_var_content_type = super::ContentType::from(local_var_content_type);
206        let local_var_content = local_var_resp.text().await?;
207
208        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
209            match local_var_content_type {
210                ContentType::Json => {
211                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
212                }
213                ContentType::Text => {
214                    return Err(Error::from(serde_json::Error::custom(
215                        "Received `text/plain` content type response that cannot be converted to \
216                         `models::ResendWebhooksResponse`",
217                    )));
218                }
219                ContentType::Unsupported(local_var_unknown_type) => {
220                    return Err(Error::from(serde_json::Error::custom(format!(
221                        "Received `{local_var_unknown_type}` content type response that cannot be \
222                         converted to `models::ResendWebhooksResponse`"
223                    ))));
224                }
225            }
226        } else {
227            let local_var_entity: Option<ResendWebhooksError> =
228                serde_json::from_str(&local_var_content).ok();
229            let local_var_error = ResponseContent {
230                status: local_var_status,
231                content: local_var_content,
232                entity: local_var_entity,
233            };
234            Err(Error::ResponseError(local_var_error))
235        }
236    }
237}
238
239/// struct for typed errors of method
240/// [`WebhooksApi::resend_transaction_webhooks`]
241#[derive(Debug, Clone, Serialize, Deserialize)]
242#[serde(untagged)]
243pub enum ResendTransactionWebhooksError {
244    DefaultResponse(models::ErrorSchema),
245    UnknownValue(serde_json::Value),
246}
247
248/// struct for typed errors of method [`WebhooksApi::resend_webhooks`]
249#[derive(Debug, Clone, Serialize, Deserialize)]
250#[serde(untagged)]
251pub enum ResendWebhooksError {
252    DefaultResponse(models::ErrorSchema),
253    UnknownValue(serde_json::Value),
254}