| 1 |
|
| 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.forbidden_error import ForbiddenError |
| 17 |
from ...errors.not_found_error import NotFoundError |
| 18 |
from ...errors.too_many_requests_error import TooManyRequestsError |
| 19 |
from ...errors.unauthorized_error import UnauthorizedError |
| 20 |
from ...types.app_metadata import AppMetadata |
| 21 |
from ...types.create_organization_invitation_response_content import CreateOrganizationInvitationResponseContent |
| 22 |
from ...types.get_organization_invitation_response_content import GetOrganizationInvitationResponseContent |
| 23 |
from ...types.list_organization_invitations_offset_paginated_response_content import ( |
| 24 |
ListOrganizationInvitationsOffsetPaginatedResponseContent, |
| 25 |
) |
| 26 |
from ...types.organization_invitation import OrganizationInvitation |
| 27 |
from ...types.organization_invitation_invitee import OrganizationInvitationInvitee |
| 28 |
from ...types.organization_invitation_inviter import OrganizationInvitationInviter |
| 29 |
from ...types.user_metadata import UserMetadata |
| 30 |
from pydantic import ValidationError |
| 31 |
|
| 32 |
|
| 33 |
OMIT = typing.cast(typing.Any, ...) |
| 34 |
|
| 35 |
|
| 36 |
class RawInvitationsClient: |
| 37 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 38 |
self._client_wrapper = client_wrapper |
| 39 |
|
| 40 |
def list( |
| 41 |
self, |
| 42 |
id: str, |
| 43 |
*, |
| 44 |
page: typing.Optional[int] = 0, |
| 45 |
per_page: typing.Optional[int] = 50, |
| 46 |
include_totals: typing.Optional[bool] = True, |
| 47 |
fields: typing.Optional[str] = None, |
| 48 |
include_fields: typing.Optional[bool] = None, |
| 49 |
sort: typing.Optional[str] = None, |
| 50 |
request_options: typing.Optional[RequestOptions] = None, |
| 51 |
) -> SyncPager[OrganizationInvitation, ListOrganizationInvitationsOffsetPaginatedResponseContent]: |
| 52 |
""" |
| 53 |
Retrieve a detailed list of invitations sent to users for a specific Organization. The list includes details such as inviter and invitee information, invitation URLs, and dates of creation and expiration. To learn more about Organization invitations, review [Invite Organization Members](https://auth0.com/docs/manage-users/organizations/configure-organizations/invite-members). |
| 54 |
|
| 55 |
Parameters |
| 56 |
---------- |
| 57 |
id : str |
| 58 |
Organization identifier. |
| 59 |
|
| 60 |
page : typing.Optional[int] |
| 61 |
Page index of the results to return. First page is 0. |
| 62 |
|
| 63 |
per_page : typing.Optional[int] |
| 64 |
Number of results per page. Defaults to 50. |
| 65 |
|
| 66 |
include_totals : typing.Optional[bool] |
| 67 |
When true, return results inside an object that also contains the start and limit. When false (default), a direct array of results is returned. We do not yet support returning the total invitations count. |
| 68 |
|
| 69 |
fields : typing.Optional[str] |
| 70 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 71 |
|
| 72 |
include_fields : typing.Optional[bool] |
| 73 |
Whether specified fields are to be included (true) or excluded (false). Defaults to true. |
| 74 |
|
| 75 |
sort : typing.Optional[str] |
| 76 |
Field to sort by. Use field:order where order is 1 for ascending and -1 for descending Defaults to created_at:-1. |
| 77 |
|
| 78 |
request_options : typing.Optional[RequestOptions] |
| 79 |
Request-specific configuration. |
| 80 |
|
| 81 |
Returns |
| 82 |
------- |
| 83 |
SyncPager[OrganizationInvitation, ListOrganizationInvitationsOffsetPaginatedResponseContent] |
| 84 |
Invitations successfully retrieved. |
| 85 |
""" |
| 86 |
page = page if page is not None else 0 |
| 87 |
|
| 88 |
_response = self._client_wrapper.httpx_client.request( |
| 89 |
f"organizations/{encode_path_param(id)}/invitations", |
| 90 |
method="GET", |
| 91 |
params={ |
| 92 |
"page": page, |
| 93 |
"per_page": per_page, |
| 94 |
"include_totals": include_totals, |
| 95 |
"fields": fields, |
| 96 |
"include_fields": include_fields, |
| 97 |
"sort": sort, |
| 98 |
}, |
| 99 |
request_options=request_options, |
| 100 |
) |
| 101 |
try: |
| 102 |
if 200 <= _response.status_code < 300: |
| 103 |
_parsed_response = typing.cast( |
| 104 |
ListOrganizationInvitationsOffsetPaginatedResponseContent, |
| 105 |
parse_obj_as( |
| 106 |
type_=ListOrganizationInvitationsOffsetPaginatedResponseContent, |
| 107 |
object_=_response.json(), |
| 108 |
), |
| 109 |
) |
| 110 |
_items = _parsed_response.invitations |
| 111 |
_has_next = len(_items or []) > 0 |
| 112 |
_get_next = lambda: self.list( |
| 113 |
id, |
| 114 |
page=page + 1, |
| 115 |
per_page=per_page, |
| 116 |
include_totals=include_totals, |
| 117 |
fields=fields, |
| 118 |
include_fields=include_fields, |
| 119 |
sort=sort, |
| 120 |
request_options=request_options, |
| 121 |
) |
| 122 |
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 123 |
if _response.status_code == 400: |
| 124 |
raise BadRequestError( |
| 125 |
headers=dict(_response.headers), |
| 126 |
body=typing.cast( |
| 127 |
typing.Any, |
| 128 |
parse_obj_as( |
| 129 |
type_=typing.Any, |
| 130 |
object_=_response.json(), |
| 131 |
), |
| 132 |
), |
| 133 |
) |
| 134 |
if _response.status_code == 401: |
| 135 |
raise UnauthorizedError( |
| 136 |
headers=dict(_response.headers), |
| 137 |
body=typing.cast( |
| 138 |
typing.Any, |
| 139 |
parse_obj_as( |
| 140 |
type_=typing.Any, |
| 141 |
object_=_response.json(), |
| 142 |
), |
| 143 |
), |
| 144 |
) |
| 145 |
if _response.status_code == 403: |
| 146 |
raise ForbiddenError( |
| 147 |
headers=dict(_response.headers), |
| 148 |
body=typing.cast( |
| 149 |
typing.Any, |
| 150 |
parse_obj_as( |
| 151 |
type_=typing.Any, |
| 152 |
object_=_response.json(), |
| 153 |
), |
| 154 |
), |
| 155 |
) |
| 156 |
if _response.status_code == 404: |
| 157 |
raise NotFoundError( |
| 158 |
headers=dict(_response.headers), |
| 159 |
body=typing.cast( |
| 160 |
typing.Any, |
| 161 |
parse_obj_as( |
| 162 |
type_=typing.Any, |
| 163 |
object_=_response.json(), |
| 164 |
), |
| 165 |
), |
| 166 |
) |
| 167 |
if _response.status_code == 429: |
| 168 |
raise TooManyRequestsError( |
| 169 |
headers=dict(_response.headers), |
| 170 |
body=typing.cast( |
| 171 |
typing.Any, |
| 172 |
parse_obj_as( |
| 173 |
type_=typing.Any, |
| 174 |
object_=_response.json(), |
| 175 |
), |
| 176 |
), |
| 177 |
) |
| 178 |
_response_json = _response.json() |
| 179 |
except JSONDecodeError: |
| 180 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 181 |
except ValidationError as e: |
| 182 |
raise ParsingError( |
| 183 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 184 |
) |
| 185 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 186 |
|
| 187 |
def create( |
| 188 |
self, |
| 189 |
id: str, |
| 190 |
*, |
| 191 |
inviter: OrganizationInvitationInviter, |
| 192 |
invitee: OrganizationInvitationInvitee, |
| 193 |
client_id: str, |
| 194 |
connection_id: typing.Optional[str] = OMIT, |
| 195 |
app_metadata: typing.Optional[AppMetadata] = OMIT, |
| 196 |
user_metadata: typing.Optional[UserMetadata] = OMIT, |
| 197 |
ttl_sec: typing.Optional[int] = OMIT, |
| 198 |
roles: typing.Optional[typing.Sequence[str]] = OMIT, |
| 199 |
send_invitation_email: typing.Optional[bool] = OMIT, |
| 200 |
request_options: typing.Optional[RequestOptions] = None, |
| 201 |
) -> HttpResponse[CreateOrganizationInvitationResponseContent]: |
| 202 |
""" |
| 203 |
Create a user invitation for a specific Organization. Upon creation, the listed user receives an email inviting them to join the Organization. To learn more about Organization invitations, review [Invite Organization Members](https://auth0.com/docs/manage-users/organizations/configure-organizations/invite-members). |
| 204 |
|
| 205 |
Parameters |
| 206 |
---------- |
| 207 |
id : str |
| 208 |
Organization identifier. |
| 209 |
|
| 210 |
inviter : OrganizationInvitationInviter |
| 211 |
|
| 212 |
invitee : OrganizationInvitationInvitee |
| 213 |
|
| 214 |
client_id : str |
| 215 |
Auth0 client ID. Used to resolve the application's login initiation endpoint. |
| 216 |
|
| 217 |
connection_id : typing.Optional[str] |
| 218 |
The id of the connection to force invitee to authenticate with. |
| 219 |
|
| 220 |
app_metadata : typing.Optional[AppMetadata] |
| 221 |
|
| 222 |
user_metadata : typing.Optional[UserMetadata] |
| 223 |
|
| 224 |
ttl_sec : typing.Optional[int] |
| 225 |
Number of seconds for which the invitation is valid before expiration. If unspecified or set to 0, this value defaults to 604800 seconds (7 days). Max value: 2592000 seconds (30 days). |
| 226 |
|
| 227 |
roles : typing.Optional[typing.Sequence[str]] |
| 228 |
List of roles IDs to associated with the user. |
| 229 |
|
| 230 |
send_invitation_email : typing.Optional[bool] |
| 231 |
Whether the user will receive an invitation email (true) or no email (false), true by default |
| 232 |
|
| 233 |
request_options : typing.Optional[RequestOptions] |
| 234 |
Request-specific configuration. |
| 235 |
|
| 236 |
Returns |
| 237 |
------- |
| 238 |
HttpResponse[CreateOrganizationInvitationResponseContent] |
| 239 |
Invitation successfully created. |
| 240 |
""" |
| 241 |
_response = self._client_wrapper.httpx_client.request( |
| 242 |
f"organizations/{encode_path_param(id)}/invitations", |
| 243 |
method="POST", |
| 244 |
json={ |
| 245 |
"inviter": convert_and_respect_annotation_metadata( |
| 246 |
object_=inviter, annotation=OrganizationInvitationInviter, direction="write" |
| 247 |
), |
| 248 |
"invitee": convert_and_respect_annotation_metadata( |
| 249 |
object_=invitee, annotation=OrganizationInvitationInvitee, direction="write" |
| 250 |
), |
| 251 |
"client_id": client_id, |
| 252 |
"connection_id": connection_id, |
| 253 |
"app_metadata": app_metadata, |
| 254 |
"user_metadata": user_metadata, |
| 255 |
"ttl_sec": ttl_sec, |
| 256 |
"roles": roles, |
| 257 |
"send_invitation_email": send_invitation_email, |
| 258 |
}, |
| 259 |
headers={ |
| 260 |
"content-type": "application/json", |
| 261 |
}, |
| 262 |
request_options=request_options, |
| 263 |
omit=OMIT, |
| 264 |
) |
| 265 |
try: |
| 266 |
if 200 <= _response.status_code < 300: |
| 267 |
_data = typing.cast( |
| 268 |
CreateOrganizationInvitationResponseContent, |
| 269 |
parse_obj_as( |
| 270 |
type_=CreateOrganizationInvitationResponseContent, |
| 271 |
object_=_response.json(), |
| 272 |
), |
| 273 |
) |
| 274 |
return HttpResponse(response=_response, data=_data) |
| 275 |
if _response.status_code == 400: |
| 276 |
raise BadRequestError( |
| 277 |
headers=dict(_response.headers), |
| 278 |
body=typing.cast( |
| 279 |
typing.Any, |
| 280 |
parse_obj_as( |
| 281 |
type_=typing.Any, |
| 282 |
object_=_response.json(), |
| 283 |
), |
| 284 |
), |
| 285 |
) |
| 286 |
if _response.status_code == 401: |
| 287 |
raise UnauthorizedError( |
| 288 |
headers=dict(_response.headers), |
| 289 |
body=typing.cast( |
| 290 |
typing.Any, |
| 291 |
parse_obj_as( |
| 292 |
type_=typing.Any, |
| 293 |
object_=_response.json(), |
| 294 |
), |
| 295 |
), |
| 296 |
) |
| 297 |
if _response.status_code == 403: |
| 298 |
raise ForbiddenError( |
| 299 |
headers=dict(_response.headers), |
| 300 |
body=typing.cast( |
| 301 |
typing.Any, |
| 302 |
parse_obj_as( |
| 303 |
type_=typing.Any, |
| 304 |
object_=_response.json(), |
| 305 |
), |
| 306 |
), |
| 307 |
) |
| 308 |
if _response.status_code == 404: |
| 309 |
raise NotFoundError( |
| 310 |
headers=dict(_response.headers), |
| 311 |
body=typing.cast( |
| 312 |
typing.Any, |
| 313 |
parse_obj_as( |
| 314 |
type_=typing.Any, |
| 315 |
object_=_response.json(), |
| 316 |
), |
| 317 |
), |
| 318 |
) |
| 319 |
if _response.status_code == 429: |
| 320 |
raise TooManyRequestsError( |
| 321 |
headers=dict(_response.headers), |
| 322 |
body=typing.cast( |
| 323 |
typing.Any, |
| 324 |
parse_obj_as( |
| 325 |
type_=typing.Any, |
| 326 |
object_=_response.json(), |
| 327 |
), |
| 328 |
), |
| 329 |
) |
| 330 |
_response_json = _response.json() |
| 331 |
except JSONDecodeError: |
| 332 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 333 |
except ValidationError as e: |
| 334 |
raise ParsingError( |
| 335 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 336 |
) |
| 337 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 338 |
|
| 339 |
def get( |
| 340 |
self, |
| 341 |
id: str, |
| 342 |
invitation_id: str, |
| 343 |
*, |
| 344 |
fields: typing.Optional[str] = None, |
| 345 |
include_fields: typing.Optional[bool] = None, |
| 346 |
request_options: typing.Optional[RequestOptions] = None, |
| 347 |
) -> HttpResponse[GetOrganizationInvitationResponseContent]: |
| 348 |
""" |
| 349 |
Parameters |
| 350 |
---------- |
| 351 |
id : str |
| 352 |
Organization identifier. |
| 353 |
|
| 354 |
invitation_id : str |
| 355 |
The id of the user invitation. |
| 356 |
|
| 357 |
fields : typing.Optional[str] |
| 358 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 359 |
|
| 360 |
include_fields : typing.Optional[bool] |
| 361 |
Whether specified fields are to be included (true) or excluded (false). Defaults to true. |
| 362 |
|
| 363 |
request_options : typing.Optional[RequestOptions] |
| 364 |
Request-specific configuration. |
| 365 |
|
| 366 |
Returns |
| 367 |
------- |
| 368 |
HttpResponse[GetOrganizationInvitationResponseContent] |
| 369 |
Invitation successfully retrieved. |
| 370 |
""" |
| 371 |
_response = self._client_wrapper.httpx_client.request( |
| 372 |
f"organizations/{encode_path_param(id)}/invitations/{encode_path_param(invitation_id)}", |
| 373 |
method="GET", |
| 374 |
params={ |
| 375 |
"fields": fields, |
| 376 |
"include_fields": include_fields, |
| 377 |
}, |
| 378 |
request_options=request_options, |
| 379 |
) |
| 380 |
try: |
| 381 |
if 200 <= _response.status_code < 300: |
| 382 |
_data = typing.cast( |
| 383 |
GetOrganizationInvitationResponseContent, |
| 384 |
parse_obj_as( |
| 385 |
type_=GetOrganizationInvitationResponseContent, |
| 386 |
object_=_response.json(), |
| 387 |
), |
| 388 |
) |
| 389 |
return HttpResponse(response=_response, data=_data) |
| 390 |
if _response.status_code == 400: |
| 391 |
raise BadRequestError( |
| 392 |
headers=dict(_response.headers), |
| 393 |
body=typing.cast( |
| 394 |
typing.Any, |
| 395 |
parse_obj_as( |
| 396 |
type_=typing.Any, |
| 397 |
object_=_response.json(), |
| 398 |
), |
| 399 |
), |
| 400 |
) |
| 401 |
if _response.status_code == 401: |
| 402 |
raise UnauthorizedError( |
| 403 |
headers=dict(_response.headers), |
| 404 |
body=typing.cast( |
| 405 |
typing.Any, |
| 406 |
parse_obj_as( |
| 407 |
type_=typing.Any, |
| 408 |
object_=_response.json(), |
| 409 |
), |
| 410 |
), |
| 411 |
) |
| 412 |
if _response.status_code == 403: |
| 413 |
raise ForbiddenError( |
| 414 |
headers=dict(_response.headers), |
| 415 |
body=typing.cast( |
| 416 |
typing.Any, |
| 417 |
parse_obj_as( |
| 418 |
type_=typing.Any, |
| 419 |
object_=_response.json(), |
| 420 |
), |
| 421 |
), |
| 422 |
) |
| 423 |
if _response.status_code == 404: |
| 424 |
raise NotFoundError( |
| 425 |
headers=dict(_response.headers), |
| 426 |
body=typing.cast( |
| 427 |
typing.Any, |
| 428 |
parse_obj_as( |
| 429 |
type_=typing.Any, |
| 430 |
object_=_response.json(), |
| 431 |
), |
| 432 |
), |
| 433 |
) |
| 434 |
if _response.status_code == 429: |
| 435 |
raise TooManyRequestsError( |
| 436 |
headers=dict(_response.headers), |
| 437 |
body=typing.cast( |
| 438 |
typing.Any, |
| 439 |
parse_obj_as( |
| 440 |
type_=typing.Any, |
| 441 |
object_=_response.json(), |
| 442 |
), |
| 443 |
), |
| 444 |
) |
| 445 |
_response_json = _response.json() |
| 446 |
except JSONDecodeError: |
| 447 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 448 |
except ValidationError as e: |
| 449 |
raise ParsingError( |
| 450 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 451 |
) |
| 452 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 453 |
|
| 454 |
def delete( |
| 455 |
self, id: str, invitation_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 456 |
) -> HttpResponse[None]: |
| 457 |
""" |
| 458 |
Parameters |
| 459 |
---------- |
| 460 |
id : str |
| 461 |
Organization identifier. |
| 462 |
|
| 463 |
invitation_id : str |
| 464 |
The id of the user invitation. |
| 465 |
|
| 466 |
request_options : typing.Optional[RequestOptions] |
| 467 |
Request-specific configuration. |
| 468 |
|
| 469 |
Returns |
| 470 |
------- |
| 471 |
HttpResponse[None] |
| 472 |
""" |
| 473 |
_response = self._client_wrapper.httpx_client.request( |
| 474 |
f"organizations/{encode_path_param(id)}/invitations/{encode_path_param(invitation_id)}", |
| 475 |
method="DELETE", |
| 476 |
request_options=request_options, |
| 477 |
) |
| 478 |
try: |
| 479 |
if 200 <= _response.status_code < 300: |
| 480 |
return HttpResponse(response=_response, data=None) |
| 481 |
if _response.status_code == 401: |
| 482 |
raise UnauthorizedError( |
| 483 |
headers=dict(_response.headers), |
| 484 |
body=typing.cast( |
| 485 |
typing.Any, |
| 486 |
parse_obj_as( |
| 487 |
type_=typing.Any, |
| 488 |
object_=_response.json(), |
| 489 |
), |
| 490 |
), |
| 491 |
) |
| 492 |
if _response.status_code == 403: |
| 493 |
raise ForbiddenError( |
| 494 |
headers=dict(_response.headers), |
| 495 |
body=typing.cast( |
| 496 |
typing.Any, |
| 497 |
parse_obj_as( |
| 498 |
type_=typing.Any, |
| 499 |
object_=_response.json(), |
| 500 |
), |
| 501 |
), |
| 502 |
) |
| 503 |
if _response.status_code == 404: |
| 504 |
raise NotFoundError( |
| 505 |
headers=dict(_response.headers), |
| 506 |
body=typing.cast( |
| 507 |
typing.Any, |
| 508 |
parse_obj_as( |
| 509 |
type_=typing.Any, |
| 510 |
object_=_response.json(), |
| 511 |
), |
| 512 |
), |
| 513 |
) |
| 514 |
if _response.status_code == 429: |
| 515 |
raise TooManyRequestsError( |
| 516 |
headers=dict(_response.headers), |
| 517 |
body=typing.cast( |
| 518 |
typing.Any, |
| 519 |
parse_obj_as( |
| 520 |
type_=typing.Any, |
| 521 |
object_=_response.json(), |
| 522 |
), |
| 523 |
), |
| 524 |
) |
| 525 |
_response_json = _response.json() |
| 526 |
except JSONDecodeError: |
| 527 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 528 |
except ValidationError as e: |
| 529 |
raise ParsingError( |
| 530 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 531 |
) |
| 532 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 533 |
|
| 534 |
|
| 535 |
class AsyncRawInvitationsClient: |
| 536 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 537 |
self._client_wrapper = client_wrapper |
| 538 |
|
| 539 |
async def list( |
| 540 |
self, |
| 541 |
id: str, |
| 542 |
*, |
| 543 |
page: typing.Optional[int] = 0, |
| 544 |
per_page: typing.Optional[int] = 50, |
| 545 |
include_totals: typing.Optional[bool] = True, |
| 546 |
fields: typing.Optional[str] = None, |
| 547 |
include_fields: typing.Optional[bool] = None, |
| 548 |
sort: typing.Optional[str] = None, |
| 549 |
request_options: typing.Optional[RequestOptions] = None, |
| 550 |
) -> AsyncPager[OrganizationInvitation, ListOrganizationInvitationsOffsetPaginatedResponseContent]: |
| 551 |
""" |
| 552 |
Retrieve a detailed list of invitations sent to users for a specific Organization. The list includes details such as inviter and invitee information, invitation URLs, and dates of creation and expiration. To learn more about Organization invitations, review [Invite Organization Members](https://auth0.com/docs/manage-users/organizations/configure-organizations/invite-members). |
| 553 |
|
| 554 |
Parameters |
| 555 |
---------- |
| 556 |
id : str |
| 557 |
Organization identifier. |
| 558 |
|
| 559 |
page : typing.Optional[int] |
| 560 |
Page index of the results to return. First page is 0. |
| 561 |
|
| 562 |
per_page : typing.Optional[int] |
| 563 |
Number of results per page. Defaults to 50. |
| 564 |
|
| 565 |
include_totals : typing.Optional[bool] |
| 566 |
When true, return results inside an object that also contains the start and limit. When false (default), a direct array of results is returned. We do not yet support returning the total invitations count. |
| 567 |
|
| 568 |
fields : typing.Optional[str] |
| 569 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 570 |
|
| 571 |
include_fields : typing.Optional[bool] |
| 572 |
Whether specified fields are to be included (true) or excluded (false). Defaults to true. |
| 573 |
|
| 574 |
sort : typing.Optional[str] |
| 575 |
Field to sort by. Use field:order where order is 1 for ascending and -1 for descending Defaults to created_at:-1. |
| 576 |
|
| 577 |
request_options : typing.Optional[RequestOptions] |
| 578 |
Request-specific configuration. |
| 579 |
|
| 580 |
Returns |
| 581 |
------- |
| 582 |
AsyncPager[OrganizationInvitation, ListOrganizationInvitationsOffsetPaginatedResponseContent] |
| 583 |
Invitations successfully retrieved. |
| 584 |
""" |
| 585 |
page = page if page is not None else 0 |
| 586 |
|
| 587 |
_response = await self._client_wrapper.httpx_client.request( |
| 588 |
f"organizations/{encode_path_param(id)}/invitations", |
| 589 |
method="GET", |
| 590 |
params={ |
| 591 |
"page": page, |
| 592 |
"per_page": per_page, |
| 593 |
"include_totals": include_totals, |
| 594 |
"fields": fields, |
| 595 |
"include_fields": include_fields, |
| 596 |
"sort": sort, |
| 597 |
}, |
| 598 |
request_options=request_options, |
| 599 |
) |
| 600 |
try: |
| 601 |
if 200 <= _response.status_code < 300: |
| 602 |
_parsed_response = typing.cast( |
| 603 |
ListOrganizationInvitationsOffsetPaginatedResponseContent, |
| 604 |
parse_obj_as( |
| 605 |
type_=ListOrganizationInvitationsOffsetPaginatedResponseContent, |
| 606 |
object_=_response.json(), |
| 607 |
), |
| 608 |
) |
| 609 |
_items = _parsed_response.invitations |
| 610 |
_has_next = len(_items or []) > 0 |
| 611 |
|
| 612 |
async def _get_next(): |
| 613 |
return await self.list( |
| 614 |
id, |
| 615 |
page=page + 1, |
| 616 |
per_page=per_page, |
| 617 |
include_totals=include_totals, |
| 618 |
fields=fields, |
| 619 |
include_fields=include_fields, |
| 620 |
sort=sort, |
| 621 |
request_options=request_options, |
| 622 |
) |
| 623 |
|
| 624 |
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 625 |
if _response.status_code == 400: |
| 626 |
raise BadRequestError( |
| 627 |
headers=dict(_response.headers), |
| 628 |
body=typing.cast( |
| 629 |
typing.Any, |
| 630 |
parse_obj_as( |
| 631 |
type_=typing.Any, |
| 632 |
object_=_response.json(), |
| 633 |
), |
| 634 |
), |
| 635 |
) |
| 636 |
if _response.status_code == 401: |
| 637 |
raise UnauthorizedError( |
| 638 |
headers=dict(_response.headers), |
| 639 |
body=typing.cast( |
| 640 |
typing.Any, |
| 641 |
parse_obj_as( |
| 642 |
type_=typing.Any, |
| 643 |
object_=_response.json(), |
| 644 |
), |
| 645 |
), |
| 646 |
) |
| 647 |
if _response.status_code == 403: |
| 648 |
raise ForbiddenError( |
| 649 |
headers=dict(_response.headers), |
| 650 |
body=typing.cast( |
| 651 |
typing.Any, |
| 652 |
parse_obj_as( |
| 653 |
type_=typing.Any, |
| 654 |
object_=_response.json(), |
| 655 |
), |
| 656 |
), |
| 657 |
) |
| 658 |
if _response.status_code == 404: |
| 659 |
raise NotFoundError( |
| 660 |
headers=dict(_response.headers), |
| 661 |
body=typing.cast( |
| 662 |
typing.Any, |
| 663 |
parse_obj_as( |
| 664 |
type_=typing.Any, |
| 665 |
object_=_response.json(), |
| 666 |
), |
| 667 |
), |
| 668 |
) |
| 669 |
if _response.status_code == 429: |
| 670 |
raise TooManyRequestsError( |
| 671 |
headers=dict(_response.headers), |
| 672 |
body=typing.cast( |
| 673 |
typing.Any, |
| 674 |
parse_obj_as( |
| 675 |
type_=typing.Any, |
| 676 |
object_=_response.json(), |
| 677 |
), |
| 678 |
), |
| 679 |
) |
| 680 |
_response_json = _response.json() |
| 681 |
except JSONDecodeError: |
| 682 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 683 |
except ValidationError as e: |
| 684 |
raise ParsingError( |
| 685 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 686 |
) |
| 687 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 688 |
|
| 689 |
async def create( |
| 690 |
self, |
| 691 |
id: str, |
| 692 |
*, |
| 693 |
inviter: OrganizationInvitationInviter, |
| 694 |
invitee: OrganizationInvitationInvitee, |
| 695 |
client_id: str, |
| 696 |
connection_id: typing.Optional[str] = OMIT, |
| 697 |
app_metadata: typing.Optional[AppMetadata] = OMIT, |
| 698 |
user_metadata: typing.Optional[UserMetadata] = OMIT, |
| 699 |
ttl_sec: typing.Optional[int] = OMIT, |
| 700 |
roles: typing.Optional[typing.Sequence[str]] = OMIT, |
| 701 |
send_invitation_email: typing.Optional[bool] = OMIT, |
| 702 |
request_options: typing.Optional[RequestOptions] = None, |
| 703 |
) -> AsyncHttpResponse[CreateOrganizationInvitationResponseContent]: |
| 704 |
""" |
| 705 |
Create a user invitation for a specific Organization. Upon creation, the listed user receives an email inviting them to join the Organization. To learn more about Organization invitations, review [Invite Organization Members](https://auth0.com/docs/manage-users/organizations/configure-organizations/invite-members). |
| 706 |
|
| 707 |
Parameters |
| 708 |
---------- |
| 709 |
id : str |
| 710 |
Organization identifier. |
| 711 |
|
| 712 |
inviter : OrganizationInvitationInviter |
| 713 |
|
| 714 |
invitee : OrganizationInvitationInvitee |
| 715 |
|
| 716 |
client_id : str |
| 717 |
Auth0 client ID. Used to resolve the application's login initiation endpoint. |
| 718 |
|
| 719 |
connection_id : typing.Optional[str] |
| 720 |
The id of the connection to force invitee to authenticate with. |
| 721 |
|
| 722 |
app_metadata : typing.Optional[AppMetadata] |
| 723 |
|
| 724 |
user_metadata : typing.Optional[UserMetadata] |
| 725 |
|
| 726 |
ttl_sec : typing.Optional[int] |
| 727 |
Number of seconds for which the invitation is valid before expiration. If unspecified or set to 0, this value defaults to 604800 seconds (7 days). Max value: 2592000 seconds (30 days). |
| 728 |
|
| 729 |
roles : typing.Optional[typing.Sequence[str]] |
| 730 |
List of roles IDs to associated with the user. |
| 731 |
|
| 732 |
send_invitation_email : typing.Optional[bool] |
| 733 |
Whether the user will receive an invitation email (true) or no email (false), true by default |
| 734 |
|
| 735 |
request_options : typing.Optional[RequestOptions] |
| 736 |
Request-specific configuration. |
| 737 |
|
| 738 |
Returns |
| 739 |
------- |
| 740 |
AsyncHttpResponse[CreateOrganizationInvitationResponseContent] |
| 741 |
Invitation successfully created. |
| 742 |
""" |
| 743 |
_response = await self._client_wrapper.httpx_client.request( |
| 744 |
f"organizations/{encode_path_param(id)}/invitations", |
| 745 |
method="POST", |
| 746 |
json={ |
| 747 |
"inviter": convert_and_respect_annotation_metadata( |
| 748 |
object_=inviter, annotation=OrganizationInvitationInviter, direction="write" |
| 749 |
), |
| 750 |
"invitee": convert_and_respect_annotation_metadata( |
| 751 |
object_=invitee, annotation=OrganizationInvitationInvitee, direction="write" |
| 752 |
), |
| 753 |
"client_id": client_id, |
| 754 |
"connection_id": connection_id, |
| 755 |
"app_metadata": app_metadata, |
| 756 |
"user_metadata": user_metadata, |
| 757 |
"ttl_sec": ttl_sec, |
| 758 |
"roles": roles, |
| 759 |
"send_invitation_email": send_invitation_email, |
| 760 |
}, |
| 761 |
headers={ |
| 762 |
"content-type": "application/json", |
| 763 |
}, |
| 764 |
request_options=request_options, |
| 765 |
omit=OMIT, |
| 766 |
) |
| 767 |
try: |
| 768 |
if 200 <= _response.status_code < 300: |
| 769 |
_data = typing.cast( |
| 770 |
CreateOrganizationInvitationResponseContent, |
| 771 |
parse_obj_as( |
| 772 |
type_=CreateOrganizationInvitationResponseContent, |
| 773 |
object_=_response.json(), |
| 774 |
), |
| 775 |
) |
| 776 |
return AsyncHttpResponse(response=_response, data=_data) |
| 777 |
if _response.status_code == 400: |
| 778 |
raise BadRequestError( |
| 779 |
headers=dict(_response.headers), |
| 780 |
body=typing.cast( |
| 781 |
typing.Any, |
| 782 |
parse_obj_as( |
| 783 |
type_=typing.Any, |
| 784 |
object_=_response.json(), |
| 785 |
), |
| 786 |
), |
| 787 |
) |
| 788 |
if _response.status_code == 401: |
| 789 |
raise UnauthorizedError( |
| 790 |
headers=dict(_response.headers), |
| 791 |
body=typing.cast( |
| 792 |
typing.Any, |
| 793 |
parse_obj_as( |
| 794 |
type_=typing.Any, |
| 795 |
object_=_response.json(), |
| 796 |
), |
| 797 |
), |
| 798 |
) |
| 799 |
if _response.status_code == 403: |
| 800 |
raise ForbiddenError( |
| 801 |
headers=dict(_response.headers), |
| 802 |
body=typing.cast( |
| 803 |
typing.Any, |
| 804 |
parse_obj_as( |
| 805 |
type_=typing.Any, |
| 806 |
object_=_response.json(), |
| 807 |
), |
| 808 |
), |
| 809 |
) |
| 810 |
if _response.status_code == 404: |
| 811 |
raise NotFoundError( |
| 812 |
headers=dict(_response.headers), |
| 813 |
body=typing.cast( |
| 814 |
typing.Any, |
| 815 |
parse_obj_as( |
| 816 |
type_=typing.Any, |
| 817 |
object_=_response.json(), |
| 818 |
), |
| 819 |
), |
| 820 |
) |
| 821 |
if _response.status_code == 429: |
| 822 |
raise TooManyRequestsError( |
| 823 |
headers=dict(_response.headers), |
| 824 |
body=typing.cast( |
| 825 |
typing.Any, |
| 826 |
parse_obj_as( |
| 827 |
type_=typing.Any, |
| 828 |
object_=_response.json(), |
| 829 |
), |
| 830 |
), |
| 831 |
) |
| 832 |
_response_json = _response.json() |
| 833 |
except JSONDecodeError: |
| 834 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 835 |
except ValidationError as e: |
| 836 |
raise ParsingError( |
| 837 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 838 |
) |
| 839 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 840 |
|
| 841 |
async def get( |
| 842 |
self, |
| 843 |
id: str, |
| 844 |
invitation_id: str, |
| 845 |
*, |
| 846 |
fields: typing.Optional[str] = None, |
| 847 |
include_fields: typing.Optional[bool] = None, |
| 848 |
request_options: typing.Optional[RequestOptions] = None, |
| 849 |
) -> AsyncHttpResponse[GetOrganizationInvitationResponseContent]: |
| 850 |
""" |
| 851 |
Parameters |
| 852 |
---------- |
| 853 |
id : str |
| 854 |
Organization identifier. |
| 855 |
|
| 856 |
invitation_id : str |
| 857 |
The id of the user invitation. |
| 858 |
|
| 859 |
fields : typing.Optional[str] |
| 860 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 861 |
|
| 862 |
include_fields : typing.Optional[bool] |
| 863 |
Whether specified fields are to be included (true) or excluded (false). Defaults to true. |
| 864 |
|
| 865 |
request_options : typing.Optional[RequestOptions] |
| 866 |
Request-specific configuration. |
| 867 |
|
| 868 |
Returns |
| 869 |
------- |
| 870 |
AsyncHttpResponse[GetOrganizationInvitationResponseContent] |
| 871 |
Invitation successfully retrieved. |
| 872 |
""" |
| 873 |
_response = await self._client_wrapper.httpx_client.request( |
| 874 |
f"organizations/{encode_path_param(id)}/invitations/{encode_path_param(invitation_id)}", |
| 875 |
method="GET", |
| 876 |
params={ |
| 877 |
"fields": fields, |
| 878 |
"include_fields": include_fields, |
| 879 |
}, |
| 880 |
request_options=request_options, |
| 881 |
) |
| 882 |
try: |
| 883 |
if 200 <= _response.status_code < 300: |
| 884 |
_data = typing.cast( |
| 885 |
GetOrganizationInvitationResponseContent, |
| 886 |
parse_obj_as( |
| 887 |
type_=GetOrganizationInvitationResponseContent, |
| 888 |
object_=_response.json(), |
| 889 |
), |
| 890 |
) |
| 891 |
return AsyncHttpResponse(response=_response, data=_data) |
| 892 |
if _response.status_code == 400: |
| 893 |
raise BadRequestError( |
| 894 |
headers=dict(_response.headers), |
| 895 |
body=typing.cast( |
| 896 |
typing.Any, |
| 897 |
parse_obj_as( |
| 898 |
type_=typing.Any, |
| 899 |
object_=_response.json(), |
| 900 |
), |
| 901 |
), |
| 902 |
) |
| 903 |
if _response.status_code == 401: |
| 904 |
raise UnauthorizedError( |
| 905 |
headers=dict(_response.headers), |
| 906 |
body=typing.cast( |
| 907 |
typing.Any, |
| 908 |
parse_obj_as( |
| 909 |
type_=typing.Any, |
| 910 |
object_=_response.json(), |
| 911 |
), |
| 912 |
), |
| 913 |
) |
| 914 |
if _response.status_code == 403: |
| 915 |
raise ForbiddenError( |
| 916 |
headers=dict(_response.headers), |
| 917 |
body=typing.cast( |
| 918 |
typing.Any, |
| 919 |
parse_obj_as( |
| 920 |
type_=typing.Any, |
| 921 |
object_=_response.json(), |
| 922 |
), |
| 923 |
), |
| 924 |
) |
| 925 |
if _response.status_code == 404: |
| 926 |
raise NotFoundError( |
| 927 |
headers=dict(_response.headers), |
| 928 |
body=typing.cast( |
| 929 |
typing.Any, |
| 930 |
parse_obj_as( |
| 931 |
type_=typing.Any, |
| 932 |
object_=_response.json(), |
| 933 |
), |
| 934 |
), |
| 935 |
) |
| 936 |
if _response.status_code == 429: |
| 937 |
raise TooManyRequestsError( |
| 938 |
headers=dict(_response.headers), |
| 939 |
body=typing.cast( |
| 940 |
typing.Any, |
| 941 |
parse_obj_as( |
| 942 |
type_=typing.Any, |
| 943 |
object_=_response.json(), |
| 944 |
), |
| 945 |
), |
| 946 |
) |
| 947 |
_response_json = _response.json() |
| 948 |
except JSONDecodeError: |
| 949 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 950 |
except ValidationError as e: |
| 951 |
raise ParsingError( |
| 952 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 953 |
) |
| 954 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 955 |
|
| 956 |
async def delete( |
| 957 |
self, id: str, invitation_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 958 |
) -> AsyncHttpResponse[None]: |
| 959 |
""" |
| 960 |
Parameters |
| 961 |
---------- |
| 962 |
id : str |
| 963 |
Organization identifier. |
| 964 |
|
| 965 |
invitation_id : str |
| 966 |
The id of the user invitation. |
| 967 |
|
| 968 |
request_options : typing.Optional[RequestOptions] |
| 969 |
Request-specific configuration. |
| 970 |
|
| 971 |
Returns |
| 972 |
------- |
| 973 |
AsyncHttpResponse[None] |
| 974 |
""" |
| 975 |
_response = await self._client_wrapper.httpx_client.request( |
| 976 |
f"organizations/{encode_path_param(id)}/invitations/{encode_path_param(invitation_id)}", |
| 977 |
method="DELETE", |
| 978 |
request_options=request_options, |
| 979 |
) |
| 980 |
try: |
| 981 |
if 200 <= _response.status_code < 300: |
| 982 |
return AsyncHttpResponse(response=_response, data=None) |
| 983 |
if _response.status_code == 401: |
| 984 |
raise UnauthorizedError( |
| 985 |
headers=dict(_response.headers), |
| 986 |
body=typing.cast( |
| 987 |
typing.Any, |
| 988 |
parse_obj_as( |
| 989 |
type_=typing.Any, |
| 990 |
object_=_response.json(), |
| 991 |
), |
| 992 |
), |
| 993 |
) |
| 994 |
if _response.status_code == 403: |
| 995 |
raise ForbiddenError( |
| 996 |
headers=dict(_response.headers), |
| 997 |
body=typing.cast( |
| 998 |
typing.Any, |
| 999 |
parse_obj_as( |
| 1000 |
type_=typing.Any, |
| 1001 |
object_=_response.json(), |
| 1002 |
), |
| 1003 |
), |
| 1004 |
) |
| 1005 |
if _response.status_code == 404: |
| 1006 |
raise NotFoundError( |
| 1007 |
headers=dict(_response.headers), |
| 1008 |
body=typing.cast( |
| 1009 |
typing.Any, |
| 1010 |
parse_obj_as( |
| 1011 |
type_=typing.Any, |
| 1012 |
object_=_response.json(), |
| 1013 |
), |
| 1014 |
), |
| 1015 |
) |
| 1016 |
if _response.status_code == 429: |
| 1017 |
raise TooManyRequestsError( |
| 1018 |
headers=dict(_response.headers), |
| 1019 |
body=typing.cast( |
| 1020 |
typing.Any, |
| 1021 |
parse_obj_as( |
| 1022 |
type_=typing.Any, |
| 1023 |
object_=_response.json(), |
| 1024 |
), |
| 1025 |
), |
| 1026 |
) |
| 1027 |
_response_json = _response.json() |
| 1028 |
except JSONDecodeError: |
| 1029 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1030 |
except ValidationError as e: |
| 1031 |
raise ParsingError( |
| 1032 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1033 |
) |
| 1034 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |