workos 1.0.0

Official Rust SDK for the WorkOS API
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
// Code generated by oagen. DO NOT EDIT.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;

pub struct GroupsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListOrganizationGroupsParams {
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Upper limit on the number of objects to return, between `1` and `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<PaginationOrder>,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateOrganizationGroupParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: CreateGroup,
}

impl CreateOrganizationGroupParams {
    /// Construct a new `CreateOrganizationGroupParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: CreateGroup) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct UpdateOrganizationGroupParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: UpdateGroup,
}

impl UpdateOrganizationGroupParams {
    /// Construct a new `UpdateOrganizationGroupParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: UpdateGroup) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListGroupOrganizationMembershipsParams {
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Upper limit on the number of objects to return, between `1` and `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<PaginationOrder>,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateGroupOrganizationMembershipParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: CreateGroupMembership,
}

impl CreateGroupOrganizationMembershipParams {
    /// Construct a new `CreateGroupOrganizationMembershipParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: CreateGroupMembership) -> Self {
        Self { body }
    }
}

impl<'a> GroupsApi<'a> {
    /// List groups
    ///
    /// Get a paginated list of groups within an organization.
    pub async fn list_organization_groups(
        &self,
        organization_id: &str,
        params: ListOrganizationGroupsParams,
    ) -> Result<GroupList, Error> {
        self.list_organization_groups_with_options(organization_id, params, None)
            .await
    }

    /// Variant of [`Self::list_organization_groups`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_organization_groups_with_options(
        &self,
        organization_id: &str,
        params: ListOrganizationGroupsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<GroupList, Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let path = format!("/organizations/{organization_id}/groups");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// Returns an async [`futures_util::Stream`] that yields every `Group`
    /// across all pages, advancing the `after` cursor under the hood.
    ///
    /// ```ignore
    /// use futures_util::TryStreamExt;
    /// let all: Vec<Group> = self
    ///     .list_organization_groups_auto_paging(organization_id, params)
    ///     .try_collect()
    ///     .await?;
    /// ```
    pub fn list_organization_groups_auto_paging(
        &self,
        organization_id: impl Into<String>,
        params: ListOrganizationGroupsParams,
    ) -> impl futures_util::Stream<Item = Result<Group, Error>> + '_ {
        let organization_id: String = organization_id.into();
        crate::pagination::auto_paginate_pages(move |after| {
            let organization_id = organization_id.clone();
            let mut params = params.clone();
            params.after = after;
            async move {
                let page = self
                    .list_organization_groups(&organization_id, params)
                    .await?;
                Ok((page.data, page.list_metadata.after))
            }
        })
    }

    /// Create a group
    ///
    /// Create a new group within an organization.
    pub async fn create_organization_group(
        &self,
        organization_id: &str,
        params: CreateOrganizationGroupParams,
    ) -> Result<Group, Error> {
        self.create_organization_group_with_options(organization_id, params, None)
            .await
    }

    /// Variant of [`Self::create_organization_group`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_organization_group_with_options(
        &self,
        organization_id: &str,
        params: CreateOrganizationGroupParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Group, Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let path = format!("/organizations/{organization_id}/groups");
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get a group
    ///
    /// Retrieve a group by its ID within an organization.
    pub async fn get_organization_group(
        &self,
        organization_id: &str,
        group_id: &str,
    ) -> Result<Group, Error> {
        self.get_organization_group_with_options(organization_id, group_id, None)
            .await
    }

    /// Variant of [`Self::get_organization_group`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_organization_group_with_options(
        &self,
        organization_id: &str,
        group_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Group, Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let group_id = crate::client::path_segment(group_id);
        let path = format!("/organizations/{organization_id}/groups/{group_id}");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Update a group
    ///
    /// Update an existing group. Only the fields provided in the request body will be updated.
    pub async fn update_organization_group(
        &self,
        organization_id: &str,
        group_id: &str,
        params: UpdateOrganizationGroupParams,
    ) -> Result<Group, Error> {
        self.update_organization_group_with_options(organization_id, group_id, params, None)
            .await
    }

    /// Variant of [`Self::update_organization_group`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_organization_group_with_options(
        &self,
        organization_id: &str,
        group_id: &str,
        params: UpdateOrganizationGroupParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Group, Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let group_id = crate::client::path_segment(group_id);
        let path = format!("/organizations/{organization_id}/groups/{group_id}");
        let method = http::Method::PATCH;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Delete a group
    ///
    /// Delete a group from an organization.
    pub async fn delete_organization_group(
        &self,
        organization_id: &str,
        group_id: &str,
    ) -> Result<(), Error> {
        self.delete_organization_group_with_options(organization_id, group_id, None)
            .await
    }

    /// Variant of [`Self::delete_organization_group`] that accepts per-request [`crate::RequestOptions`].
    pub async fn delete_organization_group_with_options(
        &self,
        organization_id: &str,
        group_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<(), Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let group_id = crate::client::path_segment(group_id);
        let path = format!("/organizations/{organization_id}/groups/{group_id}");
        let method = http::Method::DELETE;
        self.client
            .request_with_query_opts_empty(method, &path, &(), options)
            .await
    }

    /// List Group members
    ///
    /// Get a list of organization memberships in a group.
    pub async fn list_group_organization_memberships(
        &self,
        organization_id: &str,
        group_id: &str,
        params: ListGroupOrganizationMembershipsParams,
    ) -> Result<UserOrganizationMembershipBaseList, Error> {
        self.list_group_organization_memberships_with_options(
            organization_id,
            group_id,
            params,
            None,
        )
        .await
    }

    /// Variant of [`Self::list_group_organization_memberships`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_group_organization_memberships_with_options(
        &self,
        organization_id: &str,
        group_id: &str,
        params: ListGroupOrganizationMembershipsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<UserOrganizationMembershipBaseList, Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let group_id = crate::client::path_segment(group_id);
        let path =
            format!("/organizations/{organization_id}/groups/{group_id}/organization-memberships");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// Returns an async [`futures_util::Stream`] that yields every `UserOrganizationMembershipBaseListData`
    /// across all pages, advancing the `after` cursor under the hood.
    ///
    /// ```ignore
    /// use futures_util::TryStreamExt;
    /// let all: Vec<UserOrganizationMembershipBaseListData> = self
    ///     .list_group_organization_memberships_auto_paging(organization_id, group_id, params)
    ///     .try_collect()
    ///     .await?;
    /// ```
    pub fn list_group_organization_memberships_auto_paging(
        &self,
        organization_id: impl Into<String>,
        group_id: impl Into<String>,
        params: ListGroupOrganizationMembershipsParams,
    ) -> impl futures_util::Stream<Item = Result<UserOrganizationMembershipBaseListData, Error>> + '_
    {
        let organization_id: String = organization_id.into();
        let group_id: String = group_id.into();
        crate::pagination::auto_paginate_pages(move |after| {
            let organization_id = organization_id.clone();
            let group_id = group_id.clone();
            let mut params = params.clone();
            params.after = after;
            async move {
                let page = self
                    .list_group_organization_memberships(&organization_id, &group_id, params)
                    .await?;
                Ok((page.data, page.list_metadata.after))
            }
        })
    }

    /// Add a member to a Group
    ///
    /// Add an organization membership to a group.
    pub async fn create_group_organization_membership(
        &self,
        organization_id: &str,
        group_id: &str,
        params: CreateGroupOrganizationMembershipParams,
    ) -> Result<Group, Error> {
        self.create_group_organization_membership_with_options(
            organization_id,
            group_id,
            params,
            None,
        )
        .await
    }

    /// Variant of [`Self::create_group_organization_membership`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_group_organization_membership_with_options(
        &self,
        organization_id: &str,
        group_id: &str,
        params: CreateGroupOrganizationMembershipParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Group, Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let group_id = crate::client::path_segment(group_id);
        let path =
            format!("/organizations/{organization_id}/groups/{group_id}/organization-memberships");
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Remove a member from a Group
    ///
    /// Remove an organization membership from a group.
    pub async fn delete_group_organization_membership(
        &self,
        organization_id: &str,
        group_id: &str,
        om_id: &str,
    ) -> Result<(), Error> {
        self.delete_group_organization_membership_with_options(
            organization_id,
            group_id,
            om_id,
            None,
        )
        .await
    }

    /// Variant of [`Self::delete_group_organization_membership`] that accepts per-request [`crate::RequestOptions`].
    pub async fn delete_group_organization_membership_with_options(
        &self,
        organization_id: &str,
        group_id: &str,
        om_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<(), Error> {
        let organization_id = crate::client::path_segment(organization_id);
        let group_id = crate::client::path_segment(group_id);
        let om_id = crate::client::path_segment(om_id);
        let path = format!(
            "/organizations/{organization_id}/groups/{group_id}/organization-memberships/{om_id}"
        );
        let method = http::Method::DELETE;
        self.client
            .request_with_query_opts_empty(method, &path, &(), options)
            .await
    }
}