Debian Codegraph @

src/auth0/management/organizations/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4 from json.decoder import JSONDecodeError
5
6 from ..core.api_error import ApiError
7 from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8 from ..core.http_response import AsyncHttpResponse, HttpResponse
9 from ..core.jsonable_encoder import encode_path_param
10 from ..core.pagination import AsyncPager, SyncPager
11 from ..core.parse_error import ParsingError
12 from ..core.pydantic_utilities import parse_obj_as
13 from ..core.request_options import RequestOptions
14 from ..core.serialization import convert_and_respect_annotation_metadata
15 from ..errors.bad_request_error import BadRequestError
16 from ..errors.conflict_error import ConflictError
17 from ..errors.forbidden_error import ForbiddenError
18 from ..errors.not_found_error import NotFoundError
19 from ..errors.too_many_requests_error import TooManyRequestsError
20 from ..errors.unauthorized_error import UnauthorizedError
21 from ..types.connection_for_organization import ConnectionForOrganization
22 from ..types.create_organization_response_content import CreateOrganizationResponseContent
23 from ..types.create_token_quota import CreateTokenQuota
24 from ..types.get_organization_by_name_response_content import GetOrganizationByNameResponseContent
25 from ..types.get_organization_response_content import GetOrganizationResponseContent
26 from ..types.list_organizations_paginated_response_content import ListOrganizationsPaginatedResponseContent
27 from ..types.organization import Organization
28 from ..types.organization_branding import OrganizationBranding
29 from ..types.organization_metadata import OrganizationMetadata
30 from ..types.organization_third_party_client_access_enum import OrganizationThirdPartyClientAccessEnum
31 from ..types.update_organization_response_content import UpdateOrganizationResponseContent
32 from ..types.update_token_quota import UpdateTokenQuota
33 from pydantic import ValidationError
34
35 # this is used as the default value for optional parameters
36 OMIT = typing.cast(typing.Any, ...)
37
38
39 class RawOrganizationsClient:
40 def __init__(self, *, client_wrapper: SyncClientWrapper):
41 self._client_wrapper = client_wrapper
42
43 def list(
44 self,
45 *,
46 from_: typing.Optional[str] = None,
47 take: typing.Optional[int] = 50,
48 sort: typing.Optional[str] = None,
49 request_options: typing.Optional[RequestOptions] = None,
50 ) -> SyncPager[Organization, ListOrganizationsPaginatedResponseContent]:
51 """
52 Retrieve detailed list of all Organizations available in your tenant. For more information, see Auth0 Organizations.
53
54 This endpoint supports two types of pagination:
55
56 - Offset pagination
57 - Checkpoint pagination
58
59 Checkpoint pagination must be used if you need to retrieve more than 1000 organizations.
60
61 **Checkpoint Pagination**
62
63 To search by checkpoint, use the following parameters:
64
65 - `from`: Optional id from which to start selection.
66 - `take`: The total number of entries to retrieve when using the `from` parameter. Defaults to 50.
67
68 **Note**: The first time you call this endpoint using checkpoint pagination, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no pages are remaining.
69
70 Parameters
71 ----------
72 from_ : typing.Optional[str]
73 Optional Id from which to start selection.
74
75 take : typing.Optional[int]
76 Number of results per page. Defaults to 50.
77
78 sort : typing.Optional[str]
79 Field to sort by. Use <code>field:order</code> where order is <code>1</code> for ascending and <code>-1</code> for descending. e.g. <code>created_at:1</code>. We currently support sorting by the following fields: <code>name</code>, <code>display_name</code> and <code>created_at</code>.
80
81 request_options : typing.Optional[RequestOptions]
82 Request-specific configuration.
83
84 Returns
85 -------
86 SyncPager[Organization, ListOrganizationsPaginatedResponseContent]
87 Organizations successfully retrieved.
88 """
89 _response = self._client_wrapper.httpx_client.request(
90 "organizations",
91 method="GET",
92 params={
93 "from": from_,
94 "take": take,
95 "sort": sort,
96 },
97 request_options=request_options,
98 )
99 try:
100 if 200 <= _response.status_code < 300:
101 _parsed_response = typing.cast(
102 ListOrganizationsPaginatedResponseContent,
103 parse_obj_as(
104 type_=ListOrganizationsPaginatedResponseContent, # type: ignore
105 object_=_response.json(),
106 ),
107 )
108 _items = _parsed_response.organizations
109 _parsed_next = _parsed_response.next
110 _has_next = _parsed_next is not None and _parsed_next != ""
111 _get_next = lambda: self.list(
112 from_=_parsed_next,
113 take=take,
114 sort=sort,
115 request_options=request_options,
116 )
117 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
118 if _response.status_code == 400:
119 raise BadRequestError(
120 headers=dict(_response.headers),
121 body=typing.cast(
122 typing.Any,
123 parse_obj_as(
124 type_=typing.Any, # type: ignore
125 object_=_response.json(),
126 ),
127 ),
128 )
129 if _response.status_code == 401:
130 raise UnauthorizedError(
131 headers=dict(_response.headers),
132 body=typing.cast(
133 typing.Any,
134 parse_obj_as(
135 type_=typing.Any, # type: ignore
136 object_=_response.json(),
137 ),
138 ),
139 )
140 if _response.status_code == 403:
141 raise ForbiddenError(
142 headers=dict(_response.headers),
143 body=typing.cast(
144 typing.Any,
145 parse_obj_as(
146 type_=typing.Any, # type: ignore
147 object_=_response.json(),
148 ),
149 ),
150 )
151 if _response.status_code == 429:
152 raise TooManyRequestsError(
153 headers=dict(_response.headers),
154 body=typing.cast(
155 typing.Any,
156 parse_obj_as(
157 type_=typing.Any, # type: ignore
158 object_=_response.json(),
159 ),
160 ),
161 )
162 _response_json = _response.json()
163 except JSONDecodeError:
164 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
165 except ValidationError as e:
166 raise ParsingError(
167 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
168 )
169 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
170
171 def create(
172 self,
173 *,
174 name: str,
175 display_name: typing.Optional[str] = OMIT,
176 branding: typing.Optional[OrganizationBranding] = OMIT,
177 metadata: typing.Optional[OrganizationMetadata] = OMIT,
178 enabled_connections: typing.Optional[typing.Sequence[ConnectionForOrganization]] = OMIT,
179 token_quota: typing.Optional[CreateTokenQuota] = OMIT,
180 third_party_client_access: typing.Optional[OrganizationThirdPartyClientAccessEnum] = OMIT,
181 request_options: typing.Optional[RequestOptions] = None,
182 ) -> HttpResponse[CreateOrganizationResponseContent]:
183 """
184 Create a new Organization within your tenant. To learn more about Organization settings, behavior, and configuration options, review [Create Your First Organization](https://auth0.com/docs/manage-users/organizations/create-first-organization).
185
186 Parameters
187 ----------
188 name : str
189 The name of this organization.
190
191 display_name : typing.Optional[str]
192 Friendly name of this organization.
193
194 branding : typing.Optional[OrganizationBranding]
195
196 metadata : typing.Optional[OrganizationMetadata]
197
198 enabled_connections : typing.Optional[typing.Sequence[ConnectionForOrganization]]
199 Connections that will be enabled for this organization. See POST enabled_connections endpoint for the object format. (Max of 10 connections allowed)
200
201 token_quota : typing.Optional[CreateTokenQuota]
202
203 third_party_client_access : typing.Optional[OrganizationThirdPartyClientAccessEnum]
204
205 request_options : typing.Optional[RequestOptions]
206 Request-specific configuration.
207
208 Returns
209 -------
210 HttpResponse[CreateOrganizationResponseContent]
211 Organization successfully created.
212 """
213 _response = self._client_wrapper.httpx_client.request(
214 "organizations",
215 method="POST",
216 json={
217 "name": name,
218 "display_name": display_name,
219 "branding": convert_and_respect_annotation_metadata(
220 object_=branding, annotation=OrganizationBranding, direction="write"
221 ),
222 "metadata": metadata,
223 "enabled_connections": convert_and_respect_annotation_metadata(
224 object_=enabled_connections,
225 annotation=typing.Sequence[ConnectionForOrganization],
226 direction="write",
227 ),
228 "token_quota": convert_and_respect_annotation_metadata(
229 object_=token_quota, annotation=CreateTokenQuota, direction="write"
230 ),
231 "third_party_client_access": third_party_client_access,
232 },
233 headers={
234 "content-type": "application/json",
235 },
236 request_options=request_options,
237 omit=OMIT,
238 )
239 try:
240 if 200 <= _response.status_code < 300:
241 _data = typing.cast(
242 CreateOrganizationResponseContent,
243 parse_obj_as(
244 type_=CreateOrganizationResponseContent, # type: ignore
245 object_=_response.json(),
246 ),
247 )
248 return HttpResponse(response=_response, data=_data)
249 if _response.status_code == 400:
250 raise BadRequestError(
251 headers=dict(_response.headers),
252 body=typing.cast(
253 typing.Any,
254 parse_obj_as(
255 type_=typing.Any, # type: ignore
256 object_=_response.json(),
257 ),
258 ),
259 )
260 if _response.status_code == 401:
261 raise UnauthorizedError(
262 headers=dict(_response.headers),
263 body=typing.cast(
264 typing.Any,
265 parse_obj_as(
266 type_=typing.Any, # type: ignore
267 object_=_response.json(),
268 ),
269 ),
270 )
271 if _response.status_code == 403:
272 raise ForbiddenError(
273 headers=dict(_response.headers),
274 body=typing.cast(
275 typing.Any,
276 parse_obj_as(
277 type_=typing.Any, # type: ignore
278 object_=_response.json(),
279 ),
280 ),
281 )
282 if _response.status_code == 409:
283 raise ConflictError(
284 headers=dict(_response.headers),
285 body=typing.cast(
286 typing.Any,
287 parse_obj_as(
288 type_=typing.Any, # type: ignore
289 object_=_response.json(),
290 ),
291 ),
292 )
293 if _response.status_code == 429:
294 raise TooManyRequestsError(
295 headers=dict(_response.headers),
296 body=typing.cast(
297 typing.Any,
298 parse_obj_as(
299 type_=typing.Any, # type: ignore
300 object_=_response.json(),
301 ),
302 ),
303 )
304 _response_json = _response.json()
305 except JSONDecodeError:
306 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
307 except ValidationError as e:
308 raise ParsingError(
309 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
310 )
311 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
312
313 def get_by_name(
314 self, name: str, *, request_options: typing.Optional[RequestOptions] = None
315 ) -> HttpResponse[GetOrganizationByNameResponseContent]:
316 """
317 Retrieve details about a single Organization specified by name.
318
319 Parameters
320 ----------
321 name : str
322 name of the organization to retrieve.
323
324 request_options : typing.Optional[RequestOptions]
325 Request-specific configuration.
326
327 Returns
328 -------
329 HttpResponse[GetOrganizationByNameResponseContent]
330 Organization successfully retrieved.
331 """
332 _response = self._client_wrapper.httpx_client.request(
333 f"organizations/name/{encode_path_param(name)}",
334 method="GET",
335 request_options=request_options,
336 )
337 try:
338 if 200 <= _response.status_code < 300:
339 _data = typing.cast(
340 GetOrganizationByNameResponseContent,
341 parse_obj_as(
342 type_=GetOrganizationByNameResponseContent, # type: ignore
343 object_=_response.json(),
344 ),
345 )
346 return HttpResponse(response=_response, data=_data)
347 if _response.status_code == 400:
348 raise BadRequestError(
349 headers=dict(_response.headers),
350 body=typing.cast(
351 typing.Any,
352 parse_obj_as(
353 type_=typing.Any, # type: ignore
354 object_=_response.json(),
355 ),
356 ),
357 )
358 if _response.status_code == 401:
359 raise UnauthorizedError(
360 headers=dict(_response.headers),
361 body=typing.cast(
362 typing.Any,
363 parse_obj_as(
364 type_=typing.Any, # type: ignore
365 object_=_response.json(),
366 ),
367 ),
368 )
369 if _response.status_code == 403:
370 raise ForbiddenError(
371 headers=dict(_response.headers),
372 body=typing.cast(
373 typing.Any,
374 parse_obj_as(
375 type_=typing.Any, # type: ignore
376 object_=_response.json(),
377 ),
378 ),
379 )
380 if _response.status_code == 404:
381 raise NotFoundError(
382 headers=dict(_response.headers),
383 body=typing.cast(
384 typing.Any,
385 parse_obj_as(
386 type_=typing.Any, # type: ignore
387 object_=_response.json(),
388 ),
389 ),
390 )
391 if _response.status_code == 429:
392 raise TooManyRequestsError(
393 headers=dict(_response.headers),
394 body=typing.cast(
395 typing.Any,
396 parse_obj_as(
397 type_=typing.Any, # type: ignore
398 object_=_response.json(),
399 ),
400 ),
401 )
402 _response_json = _response.json()
403 except JSONDecodeError:
404 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
405 except ValidationError as e:
406 raise ParsingError(
407 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
408 )
409 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
410
411 def get(
412 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
413 ) -> HttpResponse[GetOrganizationResponseContent]:
414 """
415 Retrieve details about a single Organization specified by ID.
416
417 Parameters
418 ----------
419 id : str
420 ID of the organization to retrieve.
421
422 request_options : typing.Optional[RequestOptions]
423 Request-specific configuration.
424
425 Returns
426 -------
427 HttpResponse[GetOrganizationResponseContent]
428 Organization successfully retrieved.
429 """
430 _response = self._client_wrapper.httpx_client.request(
431 f"organizations/{encode_path_param(id)}",
432 method="GET",
433 request_options=request_options,
434 )
435 try:
436 if 200 <= _response.status_code < 300:
437 _data = typing.cast(
438 GetOrganizationResponseContent,
439 parse_obj_as(
440 type_=GetOrganizationResponseContent, # type: ignore
441 object_=_response.json(),
442 ),
443 )
444 return HttpResponse(response=_response, data=_data)
445 if _response.status_code == 400:
446 raise BadRequestError(
447 headers=dict(_response.headers),
448 body=typing.cast(
449 typing.Any,
450 parse_obj_as(
451 type_=typing.Any, # type: ignore
452 object_=_response.json(),
453 ),
454 ),
455 )
456 if _response.status_code == 401:
457 raise UnauthorizedError(
458 headers=dict(_response.headers),
459 body=typing.cast(
460 typing.Any,
461 parse_obj_as(
462 type_=typing.Any, # type: ignore
463 object_=_response.json(),
464 ),
465 ),
466 )
467 if _response.status_code == 403:
468 raise ForbiddenError(
469 headers=dict(_response.headers),
470 body=typing.cast(
471 typing.Any,
472 parse_obj_as(
473 type_=typing.Any, # type: ignore
474 object_=_response.json(),
475 ),
476 ),
477 )
478 if _response.status_code == 404:
479 raise NotFoundError(
480 headers=dict(_response.headers),
481 body=typing.cast(
482 typing.Any,
483 parse_obj_as(
484 type_=typing.Any, # type: ignore
485 object_=_response.json(),
486 ),
487 ),
488 )
489 if _response.status_code == 429:
490 raise TooManyRequestsError(
491 headers=dict(_response.headers),
492 body=typing.cast(
493 typing.Any,
494 parse_obj_as(
495 type_=typing.Any, # type: ignore
496 object_=_response.json(),
497 ),
498 ),
499 )
500 _response_json = _response.json()
501 except JSONDecodeError:
502 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
503 except ValidationError as e:
504 raise ParsingError(
505 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
506 )
507 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
508
509 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
510 """
511 Remove an Organization from your tenant. This action cannot be undone.
512
513 **Note**: Members are automatically disassociated from an Organization when it is deleted. However, this action does **not** delete these users from your tenant.
514
515 Parameters
516 ----------
517 id : str
518 Organization identifier.
519
520 request_options : typing.Optional[RequestOptions]
521 Request-specific configuration.
522
523 Returns
524 -------
525 HttpResponse[None]
526 """
527 _response = self._client_wrapper.httpx_client.request(
528 f"organizations/{encode_path_param(id)}",
529 method="DELETE",
530 request_options=request_options,
531 )
532 try:
533 if 200 <= _response.status_code < 300:
534 return HttpResponse(response=_response, data=None)
535 if _response.status_code == 400:
536 raise BadRequestError(
537 headers=dict(_response.headers),
538 body=typing.cast(
539 typing.Any,
540 parse_obj_as(
541 type_=typing.Any, # type: ignore
542 object_=_response.json(),
543 ),
544 ),
545 )
546 if _response.status_code == 401:
547 raise UnauthorizedError(
548 headers=dict(_response.headers),
549 body=typing.cast(
550 typing.Any,
551 parse_obj_as(
552 type_=typing.Any, # type: ignore
553 object_=_response.json(),
554 ),
555 ),
556 )
557 if _response.status_code == 403:
558 raise ForbiddenError(
559 headers=dict(_response.headers),
560 body=typing.cast(
561 typing.Any,
562 parse_obj_as(
563 type_=typing.Any, # type: ignore
564 object_=_response.json(),
565 ),
566 ),
567 )
568 if _response.status_code == 404:
569 raise NotFoundError(
570 headers=dict(_response.headers),
571 body=typing.cast(
572 typing.Any,
573 parse_obj_as(
574 type_=typing.Any, # type: ignore
575 object_=_response.json(),
576 ),
577 ),
578 )
579 if _response.status_code == 429:
580 raise TooManyRequestsError(
581 headers=dict(_response.headers),
582 body=typing.cast(
583 typing.Any,
584 parse_obj_as(
585 type_=typing.Any, # type: ignore
586 object_=_response.json(),
587 ),
588 ),
589 )
590 _response_json = _response.json()
591 except JSONDecodeError:
592 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
593 except ValidationError as e:
594 raise ParsingError(
595 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
596 )
597 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
598
599 def update(
600 self,
601 id: str,
602 *,
603 display_name: typing.Optional[str] = OMIT,
604 name: typing.Optional[str] = OMIT,
605 branding: typing.Optional[OrganizationBranding] = OMIT,
606 metadata: typing.Optional[OrganizationMetadata] = OMIT,
607 token_quota: typing.Optional[UpdateTokenQuota] = OMIT,
608 third_party_client_access: typing.Optional[OrganizationThirdPartyClientAccessEnum] = OMIT,
609 request_options: typing.Optional[RequestOptions] = None,
610 ) -> HttpResponse[UpdateOrganizationResponseContent]:
611 """
612 Update the details of a specific [Organization](https://auth0.com/docs/manage-users/organizations/configure-organizations/create-organizations), such as name and display name, branding options, and metadata.
613
614 Parameters
615 ----------
616 id : str
617 ID of the organization to update.
618
619 display_name : typing.Optional[str]
620 Friendly name of this organization.
621
622 name : typing.Optional[str]
623 The name of this organization.
624
625 branding : typing.Optional[OrganizationBranding]
626
627 metadata : typing.Optional[OrganizationMetadata]
628
629 token_quota : typing.Optional[UpdateTokenQuota]
630
631 third_party_client_access : typing.Optional[OrganizationThirdPartyClientAccessEnum]
632
633 request_options : typing.Optional[RequestOptions]
634 Request-specific configuration.
635
636 Returns
637 -------
638 HttpResponse[UpdateOrganizationResponseContent]
639 Organization successfully updated.
640 """
641 _response = self._client_wrapper.httpx_client.request(
642 f"organizations/{encode_path_param(id)}",
643 method="PATCH",
644 json={
645 "display_name": display_name,
646 "name": name,
647 "branding": convert_and_respect_annotation_metadata(
648 object_=branding, annotation=OrganizationBranding, direction="write"
649 ),
650 "metadata": metadata,
651 "token_quota": convert_and_respect_annotation_metadata(
652 object_=token_quota, annotation=typing.Optional[UpdateTokenQuota], direction="write"
653 ),
654 "third_party_client_access": third_party_client_access,
655 },
656 headers={
657 "content-type": "application/json",
658 },
659 request_options=request_options,
660 omit=OMIT,
661 )
662 try:
663 if 200 <= _response.status_code < 300:
664 _data = typing.cast(
665 UpdateOrganizationResponseContent,
666 parse_obj_as(
667 type_=UpdateOrganizationResponseContent, # type: ignore
668 object_=_response.json(),
669 ),
670 )
671 return HttpResponse(response=_response, data=_data)
672 if _response.status_code == 400:
673 raise BadRequestError(
674 headers=dict(_response.headers),
675 body=typing.cast(
676 typing.Any,
677 parse_obj_as(
678 type_=typing.Any, # type: ignore
679 object_=_response.json(),
680 ),
681 ),
682 )
683 if _response.status_code == 401:
684 raise UnauthorizedError(
685 headers=dict(_response.headers),
686 body=typing.cast(
687 typing.Any,
688 parse_obj_as(
689 type_=typing.Any, # type: ignore
690 object_=_response.json(),
691 ),
692 ),
693 )
694 if _response.status_code == 403:
695 raise ForbiddenError(
696 headers=dict(_response.headers),
697 body=typing.cast(
698 typing.Any,
699 parse_obj_as(
700 type_=typing.Any, # type: ignore
701 object_=_response.json(),
702 ),
703 ),
704 )
705 if _response.status_code == 429:
706 raise TooManyRequestsError(
707 headers=dict(_response.headers),
708 body=typing.cast(
709 typing.Any,
710 parse_obj_as(
711 type_=typing.Any, # type: ignore
712 object_=_response.json(),
713 ),
714 ),
715 )
716 _response_json = _response.json()
717 except JSONDecodeError:
718 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
719 except ValidationError as e:
720 raise ParsingError(
721 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
722 )
723 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
724
725
726 class AsyncRawOrganizationsClient:
727 def __init__(self, *, client_wrapper: AsyncClientWrapper):
728 self._client_wrapper = client_wrapper
729
730 async def list(
731 self,
732 *,
733 from_: typing.Optional[str] = None,
734 take: typing.Optional[int] = 50,
735 sort: typing.Optional[str] = None,
736 request_options: typing.Optional[RequestOptions] = None,
737 ) -> AsyncPager[Organization, ListOrganizationsPaginatedResponseContent]:
738 """
739 Retrieve detailed list of all Organizations available in your tenant. For more information, see Auth0 Organizations.
740
741 This endpoint supports two types of pagination:
742
743 - Offset pagination
744 - Checkpoint pagination
745
746 Checkpoint pagination must be used if you need to retrieve more than 1000 organizations.
747
748 **Checkpoint Pagination**
749
750 To search by checkpoint, use the following parameters:
751
752 - `from`: Optional id from which to start selection.
753 - `take`: The total number of entries to retrieve when using the `from` parameter. Defaults to 50.
754
755 **Note**: The first time you call this endpoint using checkpoint pagination, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no pages are remaining.
756
757 Parameters
758 ----------
759 from_ : typing.Optional[str]
760 Optional Id from which to start selection.
761
762 take : typing.Optional[int]
763 Number of results per page. Defaults to 50.
764
765 sort : typing.Optional[str]
766 Field to sort by. Use <code>field:order</code> where order is <code>1</code> for ascending and <code>-1</code> for descending. e.g. <code>created_at:1</code>. We currently support sorting by the following fields: <code>name</code>, <code>display_name</code> and <code>created_at</code>.
767
768 request_options : typing.Optional[RequestOptions]
769 Request-specific configuration.
770
771 Returns
772 -------
773 AsyncPager[Organization, ListOrganizationsPaginatedResponseContent]
774 Organizations successfully retrieved.
775 """
776 _response = await self._client_wrapper.httpx_client.request(
777 "organizations",
778 method="GET",
779 params={
780 "from": from_,
781 "take": take,
782 "sort": sort,
783 },
784 request_options=request_options,
785 )
786 try:
787 if 200 <= _response.status_code < 300:
788 _parsed_response = typing.cast(
789 ListOrganizationsPaginatedResponseContent,
790 parse_obj_as(
791 type_=ListOrganizationsPaginatedResponseContent, # type: ignore
792 object_=_response.json(),
793 ),
794 )
795 _items = _parsed_response.organizations
796 _parsed_next = _parsed_response.next
797 _has_next = _parsed_next is not None and _parsed_next != ""
798
799 async def _get_next():
800 return await self.list(
801 from_=_parsed_next,
802 take=take,
803 sort=sort,
804 request_options=request_options,
805 )
806
807 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
808 if _response.status_code == 400:
809 raise BadRequestError(
810 headers=dict(_response.headers),
811 body=typing.cast(
812 typing.Any,
813 parse_obj_as(
814 type_=typing.Any, # type: ignore
815 object_=_response.json(),
816 ),
817 ),
818 )
819 if _response.status_code == 401:
820 raise UnauthorizedError(
821 headers=dict(_response.headers),
822 body=typing.cast(
823 typing.Any,
824 parse_obj_as(
825 type_=typing.Any, # type: ignore
826 object_=_response.json(),
827 ),
828 ),
829 )
830 if _response.status_code == 403:
831 raise ForbiddenError(
832 headers=dict(_response.headers),
833 body=typing.cast(
834 typing.Any,
835 parse_obj_as(
836 type_=typing.Any, # type: ignore
837 object_=_response.json(),
838 ),
839 ),
840 )
841 if _response.status_code == 429:
842 raise TooManyRequestsError(
843 headers=dict(_response.headers),
844 body=typing.cast(
845 typing.Any,
846 parse_obj_as(
847 type_=typing.Any, # type: ignore
848 object_=_response.json(),
849 ),
850 ),
851 )
852 _response_json = _response.json()
853 except JSONDecodeError:
854 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
855 except ValidationError as e:
856 raise ParsingError(
857 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
858 )
859 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
860
861 async def create(
862 self,
863 *,
864 name: str,
865 display_name: typing.Optional[str] = OMIT,
866 branding: typing.Optional[OrganizationBranding] = OMIT,
867 metadata: typing.Optional[OrganizationMetadata] = OMIT,
868 enabled_connections: typing.Optional[typing.Sequence[ConnectionForOrganization]] = OMIT,
869 token_quota: typing.Optional[CreateTokenQuota] = OMIT,
870 third_party_client_access: typing.Optional[OrganizationThirdPartyClientAccessEnum] = OMIT,
871 request_options: typing.Optional[RequestOptions] = None,
872 ) -> AsyncHttpResponse[CreateOrganizationResponseContent]:
873 """
874 Create a new Organization within your tenant. To learn more about Organization settings, behavior, and configuration options, review [Create Your First Organization](https://auth0.com/docs/manage-users/organizations/create-first-organization).
875
876 Parameters
877 ----------
878 name : str
879 The name of this organization.
880
881 display_name : typing.Optional[str]
882 Friendly name of this organization.
883
884 branding : typing.Optional[OrganizationBranding]
885
886 metadata : typing.Optional[OrganizationMetadata]
887
888 enabled_connections : typing.Optional[typing.Sequence[ConnectionForOrganization]]
889 Connections that will be enabled for this organization. See POST enabled_connections endpoint for the object format. (Max of 10 connections allowed)
890
891 token_quota : typing.Optional[CreateTokenQuota]
892
893 third_party_client_access : typing.Optional[OrganizationThirdPartyClientAccessEnum]
894
895 request_options : typing.Optional[RequestOptions]
896 Request-specific configuration.
897
898 Returns
899 -------
900 AsyncHttpResponse[CreateOrganizationResponseContent]
901 Organization successfully created.
902 """
903 _response = await self._client_wrapper.httpx_client.request(
904 "organizations",
905 method="POST",
906 json={
907 "name": name,
908 "display_name": display_name,
909 "branding": convert_and_respect_annotation_metadata(
910 object_=branding, annotation=OrganizationBranding, direction="write"
911 ),
912 "metadata": metadata,
913 "enabled_connections": convert_and_respect_annotation_metadata(
914 object_=enabled_connections,
915 annotation=typing.Sequence[ConnectionForOrganization],
916 direction="write",
917 ),
918 "token_quota": convert_and_respect_annotation_metadata(
919 object_=token_quota, annotation=CreateTokenQuota, direction="write"
920 ),
921 "third_party_client_access": third_party_client_access,
922 },
923 headers={
924 "content-type": "application/json",
925 },
926 request_options=request_options,
927 omit=OMIT,
928 )
929 try:
930 if 200 <= _response.status_code < 300:
931 _data = typing.cast(
932 CreateOrganizationResponseContent,
933 parse_obj_as(
934 type_=CreateOrganizationResponseContent, # type: ignore
935 object_=_response.json(),
936 ),
937 )
938 return AsyncHttpResponse(response=_response, data=_data)
939 if _response.status_code == 400:
940 raise BadRequestError(
941 headers=dict(_response.headers),
942 body=typing.cast(
943 typing.Any,
944 parse_obj_as(
945 type_=typing.Any, # type: ignore
946 object_=_response.json(),
947 ),
948 ),
949 )
950 if _response.status_code == 401:
951 raise UnauthorizedError(
952 headers=dict(_response.headers),
953 body=typing.cast(
954 typing.Any,
955 parse_obj_as(
956 type_=typing.Any, # type: ignore
957 object_=_response.json(),
958 ),
959 ),
960 )
961 if _response.status_code == 403:
962 raise ForbiddenError(
963 headers=dict(_response.headers),
964 body=typing.cast(
965 typing.Any,
966 parse_obj_as(
967 type_=typing.Any, # type: ignore
968 object_=_response.json(),
969 ),
970 ),
971 )
972 if _response.status_code == 409:
973 raise ConflictError(
974 headers=dict(_response.headers),
975 body=typing.cast(
976 typing.Any,
977 parse_obj_as(
978 type_=typing.Any, # type: ignore
979 object_=_response.json(),
980 ),
981 ),
982 )
983 if _response.status_code == 429:
984 raise TooManyRequestsError(
985 headers=dict(_response.headers),
986 body=typing.cast(
987 typing.Any,
988 parse_obj_as(
989 type_=typing.Any, # type: ignore
990 object_=_response.json(),
991 ),
992 ),
993 )
994 _response_json = _response.json()
995 except JSONDecodeError:
996 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
997 except ValidationError as e:
998 raise ParsingError(
999 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1000 )
1001 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1002
1003 async def get_by_name(
1004 self, name: str, *, request_options: typing.Optional[RequestOptions] = None
1005 ) -> AsyncHttpResponse[GetOrganizationByNameResponseContent]:
1006 """
1007 Retrieve details about a single Organization specified by name.
1008
1009 Parameters
1010 ----------
1011 name : str
1012 name of the organization to retrieve.
1013
1014 request_options : typing.Optional[RequestOptions]
1015 Request-specific configuration.
1016
1017 Returns
1018 -------
1019 AsyncHttpResponse[GetOrganizationByNameResponseContent]
1020 Organization successfully retrieved.
1021 """
1022 _response = await self._client_wrapper.httpx_client.request(
1023 f"organizations/name/{encode_path_param(name)}",
1024 method="GET",
1025 request_options=request_options,
1026 )
1027 try:
1028 if 200 <= _response.status_code < 300:
1029 _data = typing.cast(
1030 GetOrganizationByNameResponseContent,
1031 parse_obj_as(
1032 type_=GetOrganizationByNameResponseContent, # type: ignore
1033 object_=_response.json(),
1034 ),
1035 )
1036 return AsyncHttpResponse(response=_response, data=_data)
1037 if _response.status_code == 400:
1038 raise BadRequestError(
1039 headers=dict(_response.headers),
1040 body=typing.cast(
1041 typing.Any,
1042 parse_obj_as(
1043 type_=typing.Any, # type: ignore
1044 object_=_response.json(),
1045 ),
1046 ),
1047 )
1048 if _response.status_code == 401:
1049 raise UnauthorizedError(
1050 headers=dict(_response.headers),
1051 body=typing.cast(
1052 typing.Any,
1053 parse_obj_as(
1054 type_=typing.Any, # type: ignore
1055 object_=_response.json(),
1056 ),
1057 ),
1058 )
1059 if _response.status_code == 403:
1060 raise ForbiddenError(
1061 headers=dict(_response.headers),
1062 body=typing.cast(
1063 typing.Any,
1064 parse_obj_as(
1065 type_=typing.Any, # type: ignore
1066 object_=_response.json(),
1067 ),
1068 ),
1069 )
1070 if _response.status_code == 404:
1071 raise NotFoundError(
1072 headers=dict(_response.headers),
1073 body=typing.cast(
1074 typing.Any,
1075 parse_obj_as(
1076 type_=typing.Any, # type: ignore
1077 object_=_response.json(),
1078 ),
1079 ),
1080 )
1081 if _response.status_code == 429:
1082 raise TooManyRequestsError(
1083 headers=dict(_response.headers),
1084 body=typing.cast(
1085 typing.Any,
1086 parse_obj_as(
1087 type_=typing.Any, # type: ignore
1088 object_=_response.json(),
1089 ),
1090 ),
1091 )
1092 _response_json = _response.json()
1093 except JSONDecodeError:
1094 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1095 except ValidationError as e:
1096 raise ParsingError(
1097 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1098 )
1099 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1100
1101 async def get(
1102 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
1103 ) -> AsyncHttpResponse[GetOrganizationResponseContent]:
1104 """
1105 Retrieve details about a single Organization specified by ID.
1106
1107 Parameters
1108 ----------
1109 id : str
1110 ID of the organization to retrieve.
1111
1112 request_options : typing.Optional[RequestOptions]
1113 Request-specific configuration.
1114
1115 Returns
1116 -------
1117 AsyncHttpResponse[GetOrganizationResponseContent]
1118 Organization successfully retrieved.
1119 """
1120 _response = await self._client_wrapper.httpx_client.request(
1121 f"organizations/{encode_path_param(id)}",
1122 method="GET",
1123 request_options=request_options,
1124 )
1125 try:
1126 if 200 <= _response.status_code < 300:
1127 _data = typing.cast(
1128 GetOrganizationResponseContent,
1129 parse_obj_as(
1130 type_=GetOrganizationResponseContent, # type: ignore
1131 object_=_response.json(),
1132 ),
1133 )
1134 return AsyncHttpResponse(response=_response, data=_data)
1135 if _response.status_code == 400:
1136 raise BadRequestError(
1137 headers=dict(_response.headers),
1138 body=typing.cast(
1139 typing.Any,
1140 parse_obj_as(
1141 type_=typing.Any, # type: ignore
1142 object_=_response.json(),
1143 ),
1144 ),
1145 )
1146 if _response.status_code == 401:
1147 raise UnauthorizedError(
1148 headers=dict(_response.headers),
1149 body=typing.cast(
1150 typing.Any,
1151 parse_obj_as(
1152 type_=typing.Any, # type: ignore
1153 object_=_response.json(),
1154 ),
1155 ),
1156 )
1157 if _response.status_code == 403:
1158 raise ForbiddenError(
1159 headers=dict(_response.headers),
1160 body=typing.cast(
1161 typing.Any,
1162 parse_obj_as(
1163 type_=typing.Any, # type: ignore
1164 object_=_response.json(),
1165 ),
1166 ),
1167 )
1168 if _response.status_code == 404:
1169 raise NotFoundError(
1170 headers=dict(_response.headers),
1171 body=typing.cast(
1172 typing.Any,
1173 parse_obj_as(
1174 type_=typing.Any, # type: ignore
1175 object_=_response.json(),
1176 ),
1177 ),
1178 )
1179 if _response.status_code == 429:
1180 raise TooManyRequestsError(
1181 headers=dict(_response.headers),
1182 body=typing.cast(
1183 typing.Any,
1184 parse_obj_as(
1185 type_=typing.Any, # type: ignore
1186 object_=_response.json(),
1187 ),
1188 ),
1189 )
1190 _response_json = _response.json()
1191 except JSONDecodeError:
1192 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1193 except ValidationError as e:
1194 raise ParsingError(
1195 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1196 )
1197 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1198
1199 async def delete(
1200 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
1201 ) -> AsyncHttpResponse[None]:
1202 """
1203 Remove an Organization from your tenant. This action cannot be undone.
1204
1205 **Note**: Members are automatically disassociated from an Organization when it is deleted. However, this action does **not** delete these users from your tenant.
1206
1207 Parameters
1208 ----------
1209 id : str
1210 Organization identifier.
1211
1212 request_options : typing.Optional[RequestOptions]
1213 Request-specific configuration.
1214
1215 Returns
1216 -------
1217 AsyncHttpResponse[None]
1218 """
1219 _response = await self._client_wrapper.httpx_client.request(
1220 f"organizations/{encode_path_param(id)}",
1221 method="DELETE",
1222 request_options=request_options,
1223 )
1224 try:
1225 if 200 <= _response.status_code < 300:
1226 return AsyncHttpResponse(response=_response, data=None)
1227 if _response.status_code == 400:
1228 raise BadRequestError(
1229 headers=dict(_response.headers),
1230 body=typing.cast(
1231 typing.Any,
1232 parse_obj_as(
1233 type_=typing.Any, # type: ignore
1234 object_=_response.json(),
1235 ),
1236 ),
1237 )
1238 if _response.status_code == 401:
1239 raise UnauthorizedError(
1240 headers=dict(_response.headers),
1241 body=typing.cast(
1242 typing.Any,
1243 parse_obj_as(
1244 type_=typing.Any, # type: ignore
1245 object_=_response.json(),
1246 ),
1247 ),
1248 )
1249 if _response.status_code == 403:
1250 raise ForbiddenError(
1251 headers=dict(_response.headers),
1252 body=typing.cast(
1253 typing.Any,
1254 parse_obj_as(
1255 type_=typing.Any, # type: ignore
1256 object_=_response.json(),
1257 ),
1258 ),
1259 )
1260 if _response.status_code == 404:
1261 raise NotFoundError(
1262 headers=dict(_response.headers),
1263 body=typing.cast(
1264 typing.Any,
1265 parse_obj_as(
1266 type_=typing.Any, # type: ignore
1267 object_=_response.json(),
1268 ),
1269 ),
1270 )
1271 if _response.status_code == 429:
1272 raise TooManyRequestsError(
1273 headers=dict(_response.headers),
1274 body=typing.cast(
1275 typing.Any,
1276 parse_obj_as(
1277 type_=typing.Any, # type: ignore
1278 object_=_response.json(),
1279 ),
1280 ),
1281 )
1282 _response_json = _response.json()
1283 except JSONDecodeError:
1284 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1285 except ValidationError as e:
1286 raise ParsingError(
1287 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1288 )
1289 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1290
1291 async def update(
1292 self,
1293 id: str,
1294 *,
1295 display_name: typing.Optional[str] = OMIT,
1296 name: typing.Optional[str] = OMIT,
1297 branding: typing.Optional[OrganizationBranding] = OMIT,
1298 metadata: typing.Optional[OrganizationMetadata] = OMIT,
1299 token_quota: typing.Optional[UpdateTokenQuota] = OMIT,
1300 third_party_client_access: typing.Optional[OrganizationThirdPartyClientAccessEnum] = OMIT,
1301 request_options: typing.Optional[RequestOptions] = None,
1302 ) -> AsyncHttpResponse[UpdateOrganizationResponseContent]:
1303 """
1304 Update the details of a specific [Organization](https://auth0.com/docs/manage-users/organizations/configure-organizations/create-organizations), such as name and display name, branding options, and metadata.
1305
1306 Parameters
1307 ----------
1308 id : str
1309 ID of the organization to update.
1310
1311 display_name : typing.Optional[str]
1312 Friendly name of this organization.
1313
1314 name : typing.Optional[str]
1315 The name of this organization.
1316
1317 branding : typing.Optional[OrganizationBranding]
1318
1319 metadata : typing.Optional[OrganizationMetadata]
1320
1321 token_quota : typing.Optional[UpdateTokenQuota]
1322
1323 third_party_client_access : typing.Optional[OrganizationThirdPartyClientAccessEnum]
1324
1325 request_options : typing.Optional[RequestOptions]
1326 Request-specific configuration.
1327
1328 Returns
1329 -------
1330 AsyncHttpResponse[UpdateOrganizationResponseContent]
1331 Organization successfully updated.
1332 """
1333 _response = await self._client_wrapper.httpx_client.request(
1334 f"organizations/{encode_path_param(id)}",
1335 method="PATCH",
1336 json={
1337 "display_name": display_name,
1338 "name": name,
1339 "branding": convert_and_respect_annotation_metadata(
1340 object_=branding, annotation=OrganizationBranding, direction="write"
1341 ),
1342 "metadata": metadata,
1343 "token_quota": convert_and_respect_annotation_metadata(
1344 object_=token_quota, annotation=typing.Optional[UpdateTokenQuota], direction="write"
1345 ),
1346 "third_party_client_access": third_party_client_access,
1347 },
1348 headers={
1349 "content-type": "application/json",
1350 },
1351 request_options=request_options,
1352 omit=OMIT,
1353 )
1354 try:
1355 if 200 <= _response.status_code < 300:
1356 _data = typing.cast(
1357 UpdateOrganizationResponseContent,
1358 parse_obj_as(
1359 type_=UpdateOrganizationResponseContent, # type: ignore
1360 object_=_response.json(),
1361 ),
1362 )
1363 return AsyncHttpResponse(response=_response, data=_data)
1364 if _response.status_code == 400:
1365 raise BadRequestError(
1366 headers=dict(_response.headers),
1367 body=typing.cast(
1368 typing.Any,
1369 parse_obj_as(
1370 type_=typing.Any, # type: ignore
1371 object_=_response.json(),
1372 ),
1373 ),
1374 )
1375 if _response.status_code == 401:
1376 raise UnauthorizedError(
1377 headers=dict(_response.headers),
1378 body=typing.cast(
1379 typing.Any,
1380 parse_obj_as(
1381 type_=typing.Any, # type: ignore
1382 object_=_response.json(),
1383 ),
1384 ),
1385 )
1386 if _response.status_code == 403:
1387 raise ForbiddenError(
1388 headers=dict(_response.headers),
1389 body=typing.cast(
1390 typing.Any,
1391 parse_obj_as(
1392 type_=typing.Any, # type: ignore
1393 object_=_response.json(),
1394 ),
1395 ),
1396 )
1397 if _response.status_code == 429:
1398 raise TooManyRequestsError(
1399 headers=dict(_response.headers),
1400 body=typing.cast(
1401 typing.Any,
1402 parse_obj_as(
1403 type_=typing.Any, # type: ignore
1404 object_=_response.json(),
1405 ),
1406 ),
1407 )
1408 _response_json = _response.json()
1409 except JSONDecodeError:
1410 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1411 except ValidationError as e:
1412 raise ParsingError(
1413 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1414 )
1415 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)