screenshotfreeapi 1.0.0

Official Rust client for ScreenshotFreeAPI — Screenshot-as-a-Service
Documentation
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
use serde::{Deserialize, Serialize};

// ---------------------------------------------------------------------------
// Shared / primitives
// ---------------------------------------------------------------------------

/// Viewport dimensions in pixels.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Dimensions {
    pub width: u32,
    pub height: u32,
}

// ---------------------------------------------------------------------------
// Auth
// ---------------------------------------------------------------------------

/// Request body for `POST /auth/register`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegisterRequest {
    pub email: String,
    pub password: String,
    pub name: String,
}

/// Response from `POST /auth/register`.
///
/// > **Security note:** `api_key` is returned **once only**. Store it immediately.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegisterResponse {
    pub user_id: String,
    pub email: String,
    pub api_key: String,
}

/// Request body for `POST /auth/token` (password grant).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TokenRequest {
    pub email: String,
    pub password: String,
}

/// Response from `POST /auth/token`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenResponse {
    pub access_token: String,
    pub refresh_token: String,
    /// ISO-8601 expiry timestamp for `access_token`.
    pub expires_at: String,
    /// ISO-8601 expiry timestamp for `refresh_token`.
    pub refresh_expires_at: String,
}

/// Request body for `POST /auth/refresh`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RefreshRequest {
    pub refresh_token: String,
}

/// Response from `POST /auth/refresh`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RefreshResponse {
    pub access_token: String,
    pub refresh_token: String,
    /// ISO-8601 expiry timestamp for `access_token`.
    pub expires_at: String,
    /// ISO-8601 expiry timestamp for `refresh_token`.
    pub refresh_expires_at: String,
}

// ---------------------------------------------------------------------------
// Screenshot requests
// ---------------------------------------------------------------------------

/// Options for `POST /screenshots/web`.
///
/// All fields except `url` are optional.
///
/// ```rust
/// use screenshotfreeapi::WebScreenshotOptions;
///
/// let opts = WebScreenshotOptions {
///     url: "https://stripe.com/pricing".into(),
///     description: Some("the pricing comparison table".into()),
///     format: Some("png".into()),
///     ..Default::default()
/// };
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct WebScreenshotOptions {
    /// Target URL to capture. Must be a publicly reachable HTTPS/HTTP URL.
    pub url: String,

    /// Plain-English description of what to capture. Triggers AI element targeting.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// CSS selector to crop the screenshot to a specific element.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub element: Option<String>,

    /// Viewport width and height in pixels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dimensions: Option<Dimensions>,

    /// Capture the full scrollable page height (requires STARTER plan or above).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub full_page: Option<bool>,

    /// Output format: `"png"`, `"jpeg"`, `"webp"`, or `"pdf"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub format: Option<String>,

    /// Paper size for PDF output, e.g. `"A4"`, `"Letter"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paper_size: Option<String>,

    /// Block advertisements and trackers before capturing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_ads: Option<bool>,

    /// Attempt to dismiss cookie consent banners before capturing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accept_cookies: Option<bool>,

    /// Skip the response cache and force a fresh capture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bypass_cache: Option<bool>,

    /// Enable stealth mode to reduce bot-detection signals (requires BUSINESS plan).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stealth: Option<bool>,

    /// Proxy exit location, e.g. `"us-east"`, `"eu-west"` (requires BUSINESS plan).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proxy_location: Option<String>,

    /// URL to POST a webhook event to when the job completes or fails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
}

/// Options for `POST /screenshots/mobile`.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct MobileScreenshotOptions {
    /// Human-readable app name, e.g. `"Instagram"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub app_name: Option<String>,

    /// Bundle / package identifier, e.g. `"com.instagram.android"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bundle_id: Option<String>,

    /// Target platform: `"ios"`, `"android"`, or `"both"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub platform: Option<String>,

    /// Fetch the full store listing page in addition to screenshots.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_store_listing: Option<bool>,

    /// Playwright device descriptor to emulate, e.g. `"iPhone 12"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub device_emulation: Option<String>,

    /// URL to POST a webhook event to when the job completes or fails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
}

/// Options for `POST /screenshots/html`.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct HtmlScreenshotOptions {
    /// Raw HTML string to render and capture.
    pub html: String,

    /// Optional CSS to inject into the rendered page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub css: Option<String>,

    /// Output format: `"png"`, `"jpeg"`, or `"pdf"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub format: Option<String>,

    /// Paper size for PDF output, e.g. `"A4"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paper_size: Option<String>,
}

// ---------------------------------------------------------------------------
// Job lifecycle
// ---------------------------------------------------------------------------

/// Response from any `POST /screenshots/*` endpoint (HTTP 202).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EnqueueResponse {
    pub job_id: String,
    pub status: String,
    pub status_url: Option<String>,
    pub estimated_seconds: Option<u32>,
}

/// Response from `GET /jobs/:id/status`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JobStatusResponse {
    pub job_id: String,
    /// One of `"queued"`, `"processing"`, `"completed"`, `"failed"`.
    pub status: String,
    /// Integer 0–100 representing processing progress.
    pub progress: Option<u32>,
    /// Non-null when `status == "failed"`.
    pub error: Option<String>,
}

/// Full result returned by `GET /jobs/:id/result` once a job is completed.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JobResult {
    pub job_id: String,
    pub job_type: Option<String>,
    pub screenshots: Vec<Screenshot>,
    pub metadata: Metadata,
    pub completed_at: Option<String>,
}

/// A single captured screenshot within a [`JobResult`].
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Screenshot {
    /// Presigned S3 URL valid for 15 minutes.
    pub url: String,
    pub format: String,
    pub width: u32,
    pub height: u32,
    pub selector: Option<String>,
    pub captured_at: Option<String>,
}

/// Processing metadata attached to every [`JobResult`].
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Metadata {
    pub page_title: Option<String>,
    pub ai_selector_used: bool,
    pub raw_ai_selector: Option<String>,
    pub ai_confidence: Option<f64>,
    pub ai_model: Option<String>,
    pub ai_selector_failed: Option<bool>,
    pub ai_fallback_used: bool,
    pub processing_ms: u32,
    pub from_cache: bool,
}

// ---------------------------------------------------------------------------
// Billing
// ---------------------------------------------------------------------------

/// A subscription plan tier returned by `GET /billing/plans`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Plan {
    pub id: String,
    pub name: String,
    pub price_monthly: f64,
    pub screenshots_per_month: u64,
    pub requests_per_minute: u32,
    pub features: Vec<String>,
}

/// Current subscription and quota summary from `GET /billing/plan`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CurrentPlan {
    pub plan: Plan,
    pub screenshots_used: u64,
    pub screenshots_limit: u64,
    pub period_start: String,
    pub period_end: String,
    pub status: String,
}

/// Daily usage history from `GET /billing/usage`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BillingUsage {
    pub screenshots_used: u64,
    pub screenshots_limit: u64,
    pub period_start: String,
    pub period_end: String,
    pub daily: Vec<DailyUsage>,
}

/// Usage count for a single calendar day.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DailyUsage {
    pub date: String,
    pub count: u64,
}

/// Request body for `POST /billing/upgrade`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpgradeRequest {
    pub plan_id: String,
}

/// Response from `POST /billing/upgrade`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpgradeResponse {
    pub success: bool,
    /// Flutterwave checkout redirect URL.
    pub redirect_url: Option<String>,
}

/// Response from `POST /billing/verify`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VerifyResponse {
    pub success: bool,
    pub plan: Option<Plan>,
    pub message: Option<String>,
}

/// Response from `DELETE /billing/cancel`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelResponse {
    pub success: bool,
    pub message: Option<String>,
}

// ---------------------------------------------------------------------------
// Workspaces
// ---------------------------------------------------------------------------

/// A team workspace.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Workspace {
    pub id: String,
    pub name: String,
    pub owner_id: String,
    pub member_count: u32,
    pub created_at: String,
}

/// Response listing workspaces with their members.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceDetail {
    pub id: String,
    pub name: String,
    pub owner_id: String,
    pub members: Vec<WorkspaceMember>,
    pub created_at: String,
}

/// A member of a workspace.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceMember {
    pub user_id: String,
    pub email: String,
    pub name: Option<String>,
    pub role: String,
    pub joined_at: String,
}

/// Request body for `POST /workspaces`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateWorkspaceRequest {
    pub name: String,
}

/// Request body for `POST /workspaces/:id/invite`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InviteRequest {
    pub email: String,
    /// Role to assign: `"admin"`, `"member"`, or `"viewer"`.
    pub role: String,
}

/// Request body for `PUT /workspaces/:id/members/:userId`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateRoleRequest {
    pub role: String,
}

/// Generic success/message response for workspace mutations.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceActionResponse {
    pub success: bool,
    pub message: Option<String>,
}

// ---------------------------------------------------------------------------
// App Monitors
// ---------------------------------------------------------------------------

/// A scheduled app-capture monitor.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AppMonitor {
    pub id: String,
    /// Package name (Android) or App Store ID (iOS).
    pub app_id: String,
    /// `"ios"` or `"android"`.
    pub platform: String,
    pub label: String,
    /// Cron expression for the capture schedule.
    pub schedule: String,
    /// % pixel change required to trigger a change alert.
    pub diff_threshold: f64,
    pub webhook_url: Option<String>,
    pub active: bool,
    pub last_version: Option<String>,
    pub last_checked_at: Option<String>,
    pub created_at: String,
}

/// Request body for `POST /monitors/app`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateMonitorRequest {
    /// Package name (Android) or App Store ID (iOS).
    pub app_id: String,
    /// `"ios"` or `"android"`.
    pub platform: String,
    /// Cron expression, e.g. `"0 9 * * *"` (daily at 09:00 UTC).
    pub schedule: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
    /// % pixel change required to trigger a change alert. Defaults to 1.0 server-side.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diff_threshold: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
}

/// An individual run entry in a monitor's history.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MonitorHistory {
    pub id: String,
    pub job_id: String,
    pub status: String,
    pub screenshots: Option<Vec<Screenshot>>,
    pub captured_at: String,
}

// ---------------------------------------------------------------------------
// Zapier / Integrations
// ---------------------------------------------------------------------------

/// Request body for `POST /integrations/zapier/subscribe`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ZapierSubscribeRequest {
    /// Trigger event name: `"job.completed"` or `"job.failed"`.
    pub trigger_event: String,
    /// The Zapier hook URL to POST events to.
    pub target_url: String,
}

/// Response from `POST /integrations/zapier/subscribe`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ZapierSubscribeResponse {
    pub id: String,
    pub event: String,
    pub target_url: String,
    pub created_at: String,
}

/// Sample trigger payload returned by `GET /integrations/zapier/triggers/:event`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ZapierTriggerSample(pub serde_json::Value);

/// Response from `DELETE /integrations/zapier/unsubscribe/:id`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ZapierUnsubscribeResponse {
    pub success: bool,
}

// ---------------------------------------------------------------------------
// Health
// ---------------------------------------------------------------------------

/// Response from `GET /health`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthResponse {
    pub status: String,
    pub version: Option<String>,
    pub uptime: Option<f64>,
}