jira_api_v2/apis/
webhooks_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`delete_webhook_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteWebhookByIdError {
22    Status400(models::ErrorCollection),
23    Status403(models::ErrorCollection),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_dynamic_webhooks_for_app`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetDynamicWebhooksForAppError {
31    Status400(models::ErrorCollection),
32    Status403(models::ErrorCollection),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`get_failed_webhooks`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetFailedWebhooksError {
40    Status400(models::ErrorCollection),
41    Status403(models::ErrorCollection),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`refresh_webhooks`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum RefreshWebhooksError {
49    Status400(models::ErrorCollection),
50    Status403(models::ErrorCollection),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`register_dynamic_webhooks`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum RegisterDynamicWebhooksError {
58    Status400(models::ErrorCollection),
59    Status403(models::ErrorCollection),
60    UnknownValue(serde_json::Value),
61}
62
63
64/// Removes webhooks by ID. Only webhooks registered by the calling Connect app are removed. If webhooks created by other apps are specified, they are ignored.  **[Permissions](#permissions) required:** Only [Connect apps](https://developer.atlassian.com/cloud/jira/platform/integrating-with-jira-cloud/#atlassian-connect) can use this operation.
65pub async fn delete_webhook_by_id(configuration: &configuration::Configuration, container_for_webhook_ids: models::ContainerForWebhookIds) -> Result<(), Error<DeleteWebhookByIdError>> {
66    // add a prefix to parameters to efficiently prevent name collisions
67    let p_container_for_webhook_ids = container_for_webhook_ids;
68
69    let uri_str = format!("{}/rest/api/2/webhook", configuration.base_path);
70    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
71
72    if let Some(ref user_agent) = configuration.user_agent {
73        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
74    }
75    if let Some(ref token) = configuration.oauth_access_token {
76        req_builder = req_builder.bearer_auth(token.to_owned());
77    };
78    if let Some(ref auth_conf) = configuration.basic_auth {
79        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
80    };
81    req_builder = req_builder.json(&p_container_for_webhook_ids);
82
83    let req = req_builder.build()?;
84    let resp = configuration.client.execute(req).await?;
85
86    let status = resp.status();
87
88    if !status.is_client_error() && !status.is_server_error() {
89        Ok(())
90    } else {
91        let content = resp.text().await?;
92        let entity: Option<DeleteWebhookByIdError> = serde_json::from_str(&content).ok();
93        Err(Error::ResponseError(ResponseContent { status, content, entity }))
94    }
95}
96
97/// Returns a [paginated](#pagination) list of the webhooks registered by the calling app.  **[Permissions](#permissions) required:** Only [Connect apps](https://developer.atlassian.com/cloud/jira/platform/integrating-with-jira-cloud/#atlassian-connect) can use this operation.
98pub async fn get_dynamic_webhooks_for_app(configuration: &configuration::Configuration, start_at: Option<i64>, max_results: Option<i32>) -> Result<models::PageBeanWebhook, Error<GetDynamicWebhooksForAppError>> {
99    // add a prefix to parameters to efficiently prevent name collisions
100    let p_start_at = start_at;
101    let p_max_results = max_results;
102
103    let uri_str = format!("{}/rest/api/2/webhook", configuration.base_path);
104    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
105
106    if let Some(ref param_value) = p_start_at {
107        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
108    }
109    if let Some(ref param_value) = p_max_results {
110        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
111    }
112    if let Some(ref user_agent) = configuration.user_agent {
113        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114    }
115    if let Some(ref token) = configuration.oauth_access_token {
116        req_builder = req_builder.bearer_auth(token.to_owned());
117    };
118    if let Some(ref auth_conf) = configuration.basic_auth {
119        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
120    };
121
122    let req = req_builder.build()?;
123    let resp = configuration.client.execute(req).await?;
124
125    let status = resp.status();
126
127    if !status.is_client_error() && !status.is_server_error() {
128        let content = resp.text().await?;
129        serde_json::from_str(&content).map_err(Error::from)
130    } else {
131        let content = resp.text().await?;
132        let entity: Option<GetDynamicWebhooksForAppError> = serde_json::from_str(&content).ok();
133        Err(Error::ResponseError(ResponseContent { status, content, entity }))
134    }
135}
136
137/// Returns webhooks that have recently failed to be delivered to the requesting app after the maximum number of retries.  After 72 hours the failure may no longer be returned by this operation.  The oldest failure is returned first.  This method uses a cursor-based pagination. To request the next page use the failure time of the last webhook on the list as the `failedAfter` value or use the URL provided in `next`.  **[Permissions](#permissions) required:** Only [Connect apps](https://developer.atlassian.com/cloud/jira/platform/integrating-with-jira-cloud/#atlassian-connect) can use this operation.
138pub async fn get_failed_webhooks(configuration: &configuration::Configuration, max_results: Option<i32>, after: Option<i64>) -> Result<models::FailedWebhooks, Error<GetFailedWebhooksError>> {
139    // add a prefix to parameters to efficiently prevent name collisions
140    let p_max_results = max_results;
141    let p_after = after;
142
143    let uri_str = format!("{}/rest/api/2/webhook/failed", configuration.base_path);
144    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
145
146    if let Some(ref param_value) = p_max_results {
147        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
148    }
149    if let Some(ref param_value) = p_after {
150        req_builder = req_builder.query(&[("after", &param_value.to_string())]);
151    }
152    if let Some(ref user_agent) = configuration.user_agent {
153        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154    }
155    if let Some(ref token) = configuration.oauth_access_token {
156        req_builder = req_builder.bearer_auth(token.to_owned());
157    };
158    if let Some(ref auth_conf) = configuration.basic_auth {
159        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
160    };
161
162    let req = req_builder.build()?;
163    let resp = configuration.client.execute(req).await?;
164
165    let status = resp.status();
166
167    if !status.is_client_error() && !status.is_server_error() {
168        let content = resp.text().await?;
169        serde_json::from_str(&content).map_err(Error::from)
170    } else {
171        let content = resp.text().await?;
172        let entity: Option<GetFailedWebhooksError> = serde_json::from_str(&content).ok();
173        Err(Error::ResponseError(ResponseContent { status, content, entity }))
174    }
175}
176
177/// Webhooks registered through the REST API expire after 30 days. Call this resource periodically to keep them alive.  Unrecognized webhook IDs (nonexistent or belonging to other apps) are ignored.  **[Permissions](#permissions) required:** Only [Connect apps](https://developer.atlassian.com/cloud/jira/platform/integrating-with-jira-cloud/#atlassian-connect) can use this operation.
178pub async fn refresh_webhooks(configuration: &configuration::Configuration, container_for_webhook_ids: models::ContainerForWebhookIds) -> Result<models::WebhooksExpirationDate, Error<RefreshWebhooksError>> {
179    // add a prefix to parameters to efficiently prevent name collisions
180    let p_container_for_webhook_ids = container_for_webhook_ids;
181
182    let uri_str = format!("{}/rest/api/2/webhook/refresh", configuration.base_path);
183    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
184
185    if let Some(ref user_agent) = configuration.user_agent {
186        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187    }
188    if let Some(ref token) = configuration.oauth_access_token {
189        req_builder = req_builder.bearer_auth(token.to_owned());
190    };
191    if let Some(ref auth_conf) = configuration.basic_auth {
192        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
193    };
194    req_builder = req_builder.json(&p_container_for_webhook_ids);
195
196    let req = req_builder.build()?;
197    let resp = configuration.client.execute(req).await?;
198
199    let status = resp.status();
200
201    if !status.is_client_error() && !status.is_server_error() {
202        let content = resp.text().await?;
203        serde_json::from_str(&content).map_err(Error::from)
204    } else {
205        let content = resp.text().await?;
206        let entity: Option<RefreshWebhooksError> = serde_json::from_str(&content).ok();
207        Err(Error::ResponseError(ResponseContent { status, content, entity }))
208    }
209}
210
211/// Registers webhooks.  **[Permissions](#permissions) required:** Only [Connect apps](https://developer.atlassian.com/cloud/jira/platform/integrating-with-jira-cloud/#atlassian-connect) can use this operation.
212pub async fn register_dynamic_webhooks(configuration: &configuration::Configuration, webhook_registration_details: models::WebhookRegistrationDetails) -> Result<models::ContainerForRegisteredWebhooks, Error<RegisterDynamicWebhooksError>> {
213    // add a prefix to parameters to efficiently prevent name collisions
214    let p_webhook_registration_details = webhook_registration_details;
215
216    let uri_str = format!("{}/rest/api/2/webhook", configuration.base_path);
217    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
218
219    if let Some(ref user_agent) = configuration.user_agent {
220        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221    }
222    if let Some(ref token) = configuration.oauth_access_token {
223        req_builder = req_builder.bearer_auth(token.to_owned());
224    };
225    if let Some(ref auth_conf) = configuration.basic_auth {
226        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
227    };
228    req_builder = req_builder.json(&p_webhook_registration_details);
229
230    let req = req_builder.build()?;
231    let resp = configuration.client.execute(req).await?;
232
233    let status = resp.status();
234
235    if !status.is_client_error() && !status.is_server_error() {
236        let content = resp.text().await?;
237        serde_json::from_str(&content).map_err(Error::from)
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<RegisterDynamicWebhooksError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244