1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
//!
//! Webhook subscriptions
#![allow(unused_imports, clippy::too_many_arguments)]
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::client::{Client, Request, NO_BODY, NO_QUERY};
use crate::error::Result;
use crate::generated::models;
use crate::multipart::{field_text, FilePart};
use crate::util::encode_path;
/// Query and header parameters for `sensorWebhook`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SensorWebhookParams {
/// Hex-encoded HMAC-SHA256 of the request body using the subscription's signing secret.
#[serde(skip)]
pub x_sensor_signature: String,
}
/// Query and header parameters for `shopifyWebhook`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ShopifyWebhookParams {
/// Base64-encoded HMAC-SHA256 of the request body using the shop's webhook secret.
#[serde(skip)]
pub x_shopify_hmac_sha256: String,
/// Event topic (e.g. `orders/create`).
#[serde(skip)]
pub x_shopify_topic: Option<String>,
#[serde(skip)]
pub x_shopify_shop_domain: Option<String>,
}
/// Webhook subscriptions
#[derive(Debug, Clone)]
pub struct WebhooksApi {
pub(crate) client: Client,
}
impl Client {
/// Webhook subscriptions
pub fn webhooks(&self) -> WebhooksApi {
WebhooksApi { client: self.clone() }
}
}
impl WebhooksApi {
/// Create a webhook subscription
///
/// `POST /api/v1/webhooks`
///
/// Required scopes: `webhooks:write`.
pub async fn create(&self, body: &models::CreateWebhookRequest) -> Result<models::WebhookSubscription> {
self.client
.request_json(Request {
method: Method::POST,
path: "/api/v1/webhooks".to_string(),
query: NO_QUERY,
body: Some(body),
headers: Vec::new(),
idempotent: true,
})
.await
}
/// Delete a webhook subscription
///
/// `DELETE /api/v1/webhooks/{webhookId}`
///
/// Required scopes: `webhooks:write`.
pub async fn delete(&self, webhook_id: &str) -> Result<serde_json::Value> {
self.client
.request_json(Request {
method: Method::DELETE,
path: format!("/api/v1/webhooks/{}", encode_path(webhook_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: true,
})
.await
}
/// Get a webhook subscription
///
/// `GET /api/v1/webhooks/{webhookId}`
///
/// Required scopes: `webhooks:read`.
pub async fn get(&self, webhook_id: &str) -> Result<serde_json::Value> {
self.client
.request_json(Request {
method: Method::GET,
path: format!("/api/v1/webhooks/{}", encode_path(webhook_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
/// List webhook subscriptions
///
/// `GET /api/v1/webhooks`
///
/// Required scopes: `webhooks:read`.
pub async fn list(&self) -> Result<models::ListWebhooksResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: "/api/v1/webhooks".to_string(),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
/// List webhook deliveries
///
/// `GET /api/v1/webhooks/{webhookId}/deliveries`
///
/// Required scopes: `webhooks:read`.
pub async fn list_webhook_deliveries(&self, webhook_id: &str) -> Result<models::ListWebhookDeliveriesResponse> {
self.client
.request_json(Request {
method: Method::GET,
path: format!("/api/v1/webhooks/{}/deliveries", encode_path(webhook_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: false,
})
.await
}
/// Sensor webhook (HMAC-authenticated, triggers an agent run)
///
/// External-system webhook. Bypasses normal auth — `X-Sensor-Signature` header is HMAC-verified
/// against the per-subscription secret. On valid signature, fires an agent run with the request
/// body as input.
///
/// `POST /api/v1/webhooks/sensor/{webhookId}`
pub async fn sensor_webhook(&self, webhook_id: &str, body: &serde_json::Map<String, serde_json::Value>, params: &SensorWebhookParams) -> Result<models::SensorWebhookResponse> {
let mut headers: Vec<(&'static str, String)> = Vec::new();
headers.push(("X-Sensor-Signature", params.x_sensor_signature.clone()));
self.client
.request_json(Request {
method: Method::POST,
path: format!("/api/v1/webhooks/sensor/{}", encode_path(webhook_id)),
query: NO_QUERY,
body: Some(body),
headers,
idempotent: true,
})
.await
}
/// Shopify webhook
///
/// Shopify webhook receiver. Bypasses normal auth — `X-Shopify-Hmac-Sha256` header is
/// HMAC-verified against the per-shop secret.
///
/// `POST /api/v1/webhooks/shopify`
pub async fn shopify_webhook(&self, params: &ShopifyWebhookParams) -> Result<serde_json::Value> {
let mut headers: Vec<(&'static str, String)> = Vec::new();
headers.push(("X-Shopify-Hmac-Sha256", params.x_shopify_hmac_sha256.clone()));
if let Some(value) = ¶ms.x_shopify_topic {
headers.push(("X-Shopify-Topic", value.clone()));
}
if let Some(value) = ¶ms.x_shopify_shop_domain {
headers.push(("X-Shopify-Shop-Domain", value.clone()));
}
self.client
.request_json(Request {
method: Method::POST,
path: "/api/v1/webhooks/shopify".to_string(),
query: NO_QUERY,
body: NO_BODY,
headers,
idempotent: true,
})
.await
}
/// Send test delivery
///
/// `POST /api/v1/webhooks/{webhookId}/test`
///
/// Required scopes: `webhooks:write`.
pub async fn test_webhook(&self, webhook_id: &str) -> Result<serde_json::Value> {
self.client
.request_json(Request {
method: Method::POST,
path: format!("/api/v1/webhooks/{}/test", encode_path(webhook_id)),
query: NO_QUERY,
body: NO_BODY,
headers: Vec::new(),
idempotent: true,
})
.await
}
}