| 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.parse_error import ParsingError |
| 11 |
from ..core.pydantic_utilities import parse_obj_as |
| 12 |
from ..core.request_options import RequestOptions |
| 13 |
from ..errors.bad_request_error import BadRequestError |
| 14 |
from ..errors.conflict_error import ConflictError |
| 15 |
from ..errors.forbidden_error import ForbiddenError |
| 16 |
from ..errors.not_found_error import NotFoundError |
| 17 |
from ..errors.too_many_requests_error import TooManyRequestsError |
| 18 |
from ..errors.unauthorized_error import UnauthorizedError |
| 19 |
from ..types.create_email_template_response_content import CreateEmailTemplateResponseContent |
| 20 |
from ..types.email_template_name_enum import EmailTemplateNameEnum |
| 21 |
from ..types.get_email_template_response_content import GetEmailTemplateResponseContent |
| 22 |
from ..types.set_email_template_response_content import SetEmailTemplateResponseContent |
| 23 |
from ..types.update_email_template_response_content import UpdateEmailTemplateResponseContent |
| 24 |
from pydantic import ValidationError |
| 25 |
|
| 26 |
|
| 27 |
OMIT = typing.cast(typing.Any, ...) |
| 28 |
|
| 29 |
|
| 30 |
class RawEmailTemplatesClient: |
| 31 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 32 |
self._client_wrapper = client_wrapper |
| 33 |
|
| 34 |
def create( |
| 35 |
self, |
| 36 |
*, |
| 37 |
template: EmailTemplateNameEnum, |
| 38 |
body: typing.Optional[str] = OMIT, |
| 39 |
from_: typing.Optional[str] = OMIT, |
| 40 |
result_url: typing.Optional[str] = OMIT, |
| 41 |
subject: typing.Optional[str] = OMIT, |
| 42 |
syntax: typing.Optional[str] = OMIT, |
| 43 |
url_lifetime_in_seconds: typing.Optional[float] = OMIT, |
| 44 |
include_email_in_redirect: typing.Optional[bool] = OMIT, |
| 45 |
enabled: typing.Optional[bool] = OMIT, |
| 46 |
request_options: typing.Optional[RequestOptions] = None, |
| 47 |
) -> HttpResponse[CreateEmailTemplateResponseContent]: |
| 48 |
""" |
| 49 |
Create an email template. |
| 50 |
|
| 51 |
Parameters |
| 52 |
---------- |
| 53 |
template : EmailTemplateNameEnum |
| 54 |
|
| 55 |
body : typing.Optional[str] |
| 56 |
Body of the email template. |
| 57 |
|
| 58 |
from_ : typing.Optional[str] |
| 59 |
Senders `from` email address. |
| 60 |
|
| 61 |
result_url : typing.Optional[str] |
| 62 |
URL to redirect the user to after a successful action. |
| 63 |
|
| 64 |
subject : typing.Optional[str] |
| 65 |
Subject line of the email. |
| 66 |
|
| 67 |
syntax : typing.Optional[str] |
| 68 |
Syntax of the template body. |
| 69 |
|
| 70 |
url_lifetime_in_seconds : typing.Optional[float] |
| 71 |
Lifetime in seconds that the link within the email will be valid for. |
| 72 |
|
| 73 |
include_email_in_redirect : typing.Optional[bool] |
| 74 |
Whether the `reset_email` and `verify_email` templates should include the user's email address as the `email` parameter in the returnUrl (true) or whether no email address should be included in the redirect (false). Defaults to true. |
| 75 |
|
| 76 |
enabled : typing.Optional[bool] |
| 77 |
Whether the template is enabled (true) or disabled (false). |
| 78 |
|
| 79 |
request_options : typing.Optional[RequestOptions] |
| 80 |
Request-specific configuration. |
| 81 |
|
| 82 |
Returns |
| 83 |
------- |
| 84 |
HttpResponse[CreateEmailTemplateResponseContent] |
| 85 |
Template successfully created. |
| 86 |
""" |
| 87 |
_response = self._client_wrapper.httpx_client.request( |
| 88 |
"email-templates", |
| 89 |
method="POST", |
| 90 |
json={ |
| 91 |
"template": template, |
| 92 |
"body": body, |
| 93 |
"from": from_, |
| 94 |
"resultUrl": result_url, |
| 95 |
"subject": subject, |
| 96 |
"syntax": syntax, |
| 97 |
"urlLifetimeInSeconds": url_lifetime_in_seconds, |
| 98 |
"includeEmailInRedirect": include_email_in_redirect, |
| 99 |
"enabled": enabled, |
| 100 |
}, |
| 101 |
headers={ |
| 102 |
"content-type": "application/json", |
| 103 |
}, |
| 104 |
request_options=request_options, |
| 105 |
omit=OMIT, |
| 106 |
) |
| 107 |
try: |
| 108 |
if 200 <= _response.status_code < 300: |
| 109 |
_data = typing.cast( |
| 110 |
CreateEmailTemplateResponseContent, |
| 111 |
parse_obj_as( |
| 112 |
type_=CreateEmailTemplateResponseContent, |
| 113 |
object_=_response.json(), |
| 114 |
), |
| 115 |
) |
| 116 |
return HttpResponse(response=_response, data=_data) |
| 117 |
if _response.status_code == 400: |
| 118 |
raise BadRequestError( |
| 119 |
headers=dict(_response.headers), |
| 120 |
body=typing.cast( |
| 121 |
typing.Any, |
| 122 |
parse_obj_as( |
| 123 |
type_=typing.Any, |
| 124 |
object_=_response.json(), |
| 125 |
), |
| 126 |
), |
| 127 |
) |
| 128 |
if _response.status_code == 401: |
| 129 |
raise UnauthorizedError( |
| 130 |
headers=dict(_response.headers), |
| 131 |
body=typing.cast( |
| 132 |
typing.Any, |
| 133 |
parse_obj_as( |
| 134 |
type_=typing.Any, |
| 135 |
object_=_response.json(), |
| 136 |
), |
| 137 |
), |
| 138 |
) |
| 139 |
if _response.status_code == 403: |
| 140 |
raise ForbiddenError( |
| 141 |
headers=dict(_response.headers), |
| 142 |
body=typing.cast( |
| 143 |
typing.Any, |
| 144 |
parse_obj_as( |
| 145 |
type_=typing.Any, |
| 146 |
object_=_response.json(), |
| 147 |
), |
| 148 |
), |
| 149 |
) |
| 150 |
if _response.status_code == 409: |
| 151 |
raise ConflictError( |
| 152 |
headers=dict(_response.headers), |
| 153 |
body=typing.cast( |
| 154 |
typing.Any, |
| 155 |
parse_obj_as( |
| 156 |
type_=typing.Any, |
| 157 |
object_=_response.json(), |
| 158 |
), |
| 159 |
), |
| 160 |
) |
| 161 |
if _response.status_code == 429: |
| 162 |
raise TooManyRequestsError( |
| 163 |
headers=dict(_response.headers), |
| 164 |
body=typing.cast( |
| 165 |
typing.Any, |
| 166 |
parse_obj_as( |
| 167 |
type_=typing.Any, |
| 168 |
object_=_response.json(), |
| 169 |
), |
| 170 |
), |
| 171 |
) |
| 172 |
_response_json = _response.json() |
| 173 |
except JSONDecodeError: |
| 174 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 175 |
except ValidationError as e: |
| 176 |
raise ParsingError( |
| 177 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 178 |
) |
| 179 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 180 |
|
| 181 |
def get( |
| 182 |
self, template_name: EmailTemplateNameEnum, *, request_options: typing.Optional[RequestOptions] = None |
| 183 |
) -> HttpResponse[GetEmailTemplateResponseContent]: |
| 184 |
""" |
| 185 |
Retrieve an email template by pre-defined name. These names are `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, and `async_approval`. The names `change_password`, and `password_reset` are also supported for legacy scenarios. |
| 186 |
|
| 187 |
Parameters |
| 188 |
---------- |
| 189 |
template_name : EmailTemplateNameEnum |
| 190 |
Template name. Can be `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, `async_approval`, `change_password` (legacy), or `password_reset` (legacy). |
| 191 |
|
| 192 |
request_options : typing.Optional[RequestOptions] |
| 193 |
Request-specific configuration. |
| 194 |
|
| 195 |
Returns |
| 196 |
------- |
| 197 |
HttpResponse[GetEmailTemplateResponseContent] |
| 198 |
Template successfully retrieved. |
| 199 |
""" |
| 200 |
_response = self._client_wrapper.httpx_client.request( |
| 201 |
f"email-templates/{encode_path_param(template_name)}", |
| 202 |
method="GET", |
| 203 |
request_options=request_options, |
| 204 |
) |
| 205 |
try: |
| 206 |
if 200 <= _response.status_code < 300: |
| 207 |
_data = typing.cast( |
| 208 |
GetEmailTemplateResponseContent, |
| 209 |
parse_obj_as( |
| 210 |
type_=GetEmailTemplateResponseContent, |
| 211 |
object_=_response.json(), |
| 212 |
), |
| 213 |
) |
| 214 |
return HttpResponse(response=_response, data=_data) |
| 215 |
if _response.status_code == 400: |
| 216 |
raise BadRequestError( |
| 217 |
headers=dict(_response.headers), |
| 218 |
body=typing.cast( |
| 219 |
typing.Any, |
| 220 |
parse_obj_as( |
| 221 |
type_=typing.Any, |
| 222 |
object_=_response.json(), |
| 223 |
), |
| 224 |
), |
| 225 |
) |
| 226 |
if _response.status_code == 401: |
| 227 |
raise UnauthorizedError( |
| 228 |
headers=dict(_response.headers), |
| 229 |
body=typing.cast( |
| 230 |
typing.Any, |
| 231 |
parse_obj_as( |
| 232 |
type_=typing.Any, |
| 233 |
object_=_response.json(), |
| 234 |
), |
| 235 |
), |
| 236 |
) |
| 237 |
if _response.status_code == 403: |
| 238 |
raise ForbiddenError( |
| 239 |
headers=dict(_response.headers), |
| 240 |
body=typing.cast( |
| 241 |
typing.Any, |
| 242 |
parse_obj_as( |
| 243 |
type_=typing.Any, |
| 244 |
object_=_response.json(), |
| 245 |
), |
| 246 |
), |
| 247 |
) |
| 248 |
if _response.status_code == 429: |
| 249 |
raise TooManyRequestsError( |
| 250 |
headers=dict(_response.headers), |
| 251 |
body=typing.cast( |
| 252 |
typing.Any, |
| 253 |
parse_obj_as( |
| 254 |
type_=typing.Any, |
| 255 |
object_=_response.json(), |
| 256 |
), |
| 257 |
), |
| 258 |
) |
| 259 |
_response_json = _response.json() |
| 260 |
except JSONDecodeError: |
| 261 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 262 |
except ValidationError as e: |
| 263 |
raise ParsingError( |
| 264 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 265 |
) |
| 266 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 267 |
|
| 268 |
def set( |
| 269 |
self, |
| 270 |
template_name: EmailTemplateNameEnum, |
| 271 |
*, |
| 272 |
template: EmailTemplateNameEnum, |
| 273 |
body: typing.Optional[str] = OMIT, |
| 274 |
from_: typing.Optional[str] = OMIT, |
| 275 |
result_url: typing.Optional[str] = OMIT, |
| 276 |
subject: typing.Optional[str] = OMIT, |
| 277 |
syntax: typing.Optional[str] = OMIT, |
| 278 |
url_lifetime_in_seconds: typing.Optional[float] = OMIT, |
| 279 |
include_email_in_redirect: typing.Optional[bool] = OMIT, |
| 280 |
enabled: typing.Optional[bool] = OMIT, |
| 281 |
request_options: typing.Optional[RequestOptions] = None, |
| 282 |
) -> HttpResponse[SetEmailTemplateResponseContent]: |
| 283 |
""" |
| 284 |
Update an email template. |
| 285 |
|
| 286 |
Parameters |
| 287 |
---------- |
| 288 |
template_name : EmailTemplateNameEnum |
| 289 |
Template name. Can be `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, `async_approval`, `change_password` (legacy), or `password_reset` (legacy). |
| 290 |
|
| 291 |
template : EmailTemplateNameEnum |
| 292 |
|
| 293 |
body : typing.Optional[str] |
| 294 |
Body of the email template. |
| 295 |
|
| 296 |
from_ : typing.Optional[str] |
| 297 |
Senders `from` email address. |
| 298 |
|
| 299 |
result_url : typing.Optional[str] |
| 300 |
URL to redirect the user to after a successful action. |
| 301 |
|
| 302 |
subject : typing.Optional[str] |
| 303 |
Subject line of the email. |
| 304 |
|
| 305 |
syntax : typing.Optional[str] |
| 306 |
Syntax of the template body. |
| 307 |
|
| 308 |
url_lifetime_in_seconds : typing.Optional[float] |
| 309 |
Lifetime in seconds that the link within the email will be valid for. |
| 310 |
|
| 311 |
include_email_in_redirect : typing.Optional[bool] |
| 312 |
Whether the `reset_email` and `verify_email` templates should include the user's email address as the `email` parameter in the returnUrl (true) or whether no email address should be included in the redirect (false). Defaults to true. |
| 313 |
|
| 314 |
enabled : typing.Optional[bool] |
| 315 |
Whether the template is enabled (true) or disabled (false). |
| 316 |
|
| 317 |
request_options : typing.Optional[RequestOptions] |
| 318 |
Request-specific configuration. |
| 319 |
|
| 320 |
Returns |
| 321 |
------- |
| 322 |
HttpResponse[SetEmailTemplateResponseContent] |
| 323 |
Template successfully updated. |
| 324 |
""" |
| 325 |
_response = self._client_wrapper.httpx_client.request( |
| 326 |
f"email-templates/{encode_path_param(template_name)}", |
| 327 |
method="PUT", |
| 328 |
json={ |
| 329 |
"template": template, |
| 330 |
"body": body, |
| 331 |
"from": from_, |
| 332 |
"resultUrl": result_url, |
| 333 |
"subject": subject, |
| 334 |
"syntax": syntax, |
| 335 |
"urlLifetimeInSeconds": url_lifetime_in_seconds, |
| 336 |
"includeEmailInRedirect": include_email_in_redirect, |
| 337 |
"enabled": enabled, |
| 338 |
}, |
| 339 |
headers={ |
| 340 |
"content-type": "application/json", |
| 341 |
}, |
| 342 |
request_options=request_options, |
| 343 |
omit=OMIT, |
| 344 |
) |
| 345 |
try: |
| 346 |
if 200 <= _response.status_code < 300: |
| 347 |
_data = typing.cast( |
| 348 |
SetEmailTemplateResponseContent, |
| 349 |
parse_obj_as( |
| 350 |
type_=SetEmailTemplateResponseContent, |
| 351 |
object_=_response.json(), |
| 352 |
), |
| 353 |
) |
| 354 |
return HttpResponse(response=_response, data=_data) |
| 355 |
if _response.status_code == 400: |
| 356 |
raise BadRequestError( |
| 357 |
headers=dict(_response.headers), |
| 358 |
body=typing.cast( |
| 359 |
typing.Any, |
| 360 |
parse_obj_as( |
| 361 |
type_=typing.Any, |
| 362 |
object_=_response.json(), |
| 363 |
), |
| 364 |
), |
| 365 |
) |
| 366 |
if _response.status_code == 401: |
| 367 |
raise UnauthorizedError( |
| 368 |
headers=dict(_response.headers), |
| 369 |
body=typing.cast( |
| 370 |
typing.Any, |
| 371 |
parse_obj_as( |
| 372 |
type_=typing.Any, |
| 373 |
object_=_response.json(), |
| 374 |
), |
| 375 |
), |
| 376 |
) |
| 377 |
if _response.status_code == 403: |
| 378 |
raise ForbiddenError( |
| 379 |
headers=dict(_response.headers), |
| 380 |
body=typing.cast( |
| 381 |
typing.Any, |
| 382 |
parse_obj_as( |
| 383 |
type_=typing.Any, |
| 384 |
object_=_response.json(), |
| 385 |
), |
| 386 |
), |
| 387 |
) |
| 388 |
if _response.status_code == 404: |
| 389 |
raise NotFoundError( |
| 390 |
headers=dict(_response.headers), |
| 391 |
body=typing.cast( |
| 392 |
typing.Any, |
| 393 |
parse_obj_as( |
| 394 |
type_=typing.Any, |
| 395 |
object_=_response.json(), |
| 396 |
), |
| 397 |
), |
| 398 |
) |
| 399 |
if _response.status_code == 429: |
| 400 |
raise TooManyRequestsError( |
| 401 |
headers=dict(_response.headers), |
| 402 |
body=typing.cast( |
| 403 |
typing.Any, |
| 404 |
parse_obj_as( |
| 405 |
type_=typing.Any, |
| 406 |
object_=_response.json(), |
| 407 |
), |
| 408 |
), |
| 409 |
) |
| 410 |
_response_json = _response.json() |
| 411 |
except JSONDecodeError: |
| 412 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 413 |
except ValidationError as e: |
| 414 |
raise ParsingError( |
| 415 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 416 |
) |
| 417 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 418 |
|
| 419 |
def update( |
| 420 |
self, |
| 421 |
template_name: EmailTemplateNameEnum, |
| 422 |
*, |
| 423 |
template: typing.Optional[EmailTemplateNameEnum] = OMIT, |
| 424 |
body: typing.Optional[str] = OMIT, |
| 425 |
from_: typing.Optional[str] = OMIT, |
| 426 |
result_url: typing.Optional[str] = OMIT, |
| 427 |
subject: typing.Optional[str] = OMIT, |
| 428 |
syntax: typing.Optional[str] = OMIT, |
| 429 |
url_lifetime_in_seconds: typing.Optional[float] = OMIT, |
| 430 |
include_email_in_redirect: typing.Optional[bool] = OMIT, |
| 431 |
enabled: typing.Optional[bool] = OMIT, |
| 432 |
request_options: typing.Optional[RequestOptions] = None, |
| 433 |
) -> HttpResponse[UpdateEmailTemplateResponseContent]: |
| 434 |
""" |
| 435 |
Modify an email template. |
| 436 |
|
| 437 |
Parameters |
| 438 |
---------- |
| 439 |
template_name : EmailTemplateNameEnum |
| 440 |
Template name. Can be `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, `async_approval`, `change_password` (legacy), or `password_reset` (legacy). |
| 441 |
|
| 442 |
template : typing.Optional[EmailTemplateNameEnum] |
| 443 |
|
| 444 |
body : typing.Optional[str] |
| 445 |
Body of the email template. |
| 446 |
|
| 447 |
from_ : typing.Optional[str] |
| 448 |
Senders `from` email address. |
| 449 |
|
| 450 |
result_url : typing.Optional[str] |
| 451 |
URL to redirect the user to after a successful action. |
| 452 |
|
| 453 |
subject : typing.Optional[str] |
| 454 |
Subject line of the email. |
| 455 |
|
| 456 |
syntax : typing.Optional[str] |
| 457 |
Syntax of the template body. |
| 458 |
|
| 459 |
url_lifetime_in_seconds : typing.Optional[float] |
| 460 |
Lifetime in seconds that the link within the email will be valid for. |
| 461 |
|
| 462 |
include_email_in_redirect : typing.Optional[bool] |
| 463 |
Whether the `reset_email` and `verify_email` templates should include the user's email address as the `email` parameter in the returnUrl (true) or whether no email address should be included in the redirect (false). Defaults to true. |
| 464 |
|
| 465 |
enabled : typing.Optional[bool] |
| 466 |
Whether the template is enabled (true) or disabled (false). |
| 467 |
|
| 468 |
request_options : typing.Optional[RequestOptions] |
| 469 |
Request-specific configuration. |
| 470 |
|
| 471 |
Returns |
| 472 |
------- |
| 473 |
HttpResponse[UpdateEmailTemplateResponseContent] |
| 474 |
Template successfully updated. |
| 475 |
""" |
| 476 |
_response = self._client_wrapper.httpx_client.request( |
| 477 |
f"email-templates/{encode_path_param(template_name)}", |
| 478 |
method="PATCH", |
| 479 |
json={ |
| 480 |
"template": template, |
| 481 |
"body": body, |
| 482 |
"from": from_, |
| 483 |
"resultUrl": result_url, |
| 484 |
"subject": subject, |
| 485 |
"syntax": syntax, |
| 486 |
"urlLifetimeInSeconds": url_lifetime_in_seconds, |
| 487 |
"includeEmailInRedirect": include_email_in_redirect, |
| 488 |
"enabled": enabled, |
| 489 |
}, |
| 490 |
headers={ |
| 491 |
"content-type": "application/json", |
| 492 |
}, |
| 493 |
request_options=request_options, |
| 494 |
omit=OMIT, |
| 495 |
) |
| 496 |
try: |
| 497 |
if 200 <= _response.status_code < 300: |
| 498 |
_data = typing.cast( |
| 499 |
UpdateEmailTemplateResponseContent, |
| 500 |
parse_obj_as( |
| 501 |
type_=UpdateEmailTemplateResponseContent, |
| 502 |
object_=_response.json(), |
| 503 |
), |
| 504 |
) |
| 505 |
return HttpResponse(response=_response, data=_data) |
| 506 |
if _response.status_code == 400: |
| 507 |
raise BadRequestError( |
| 508 |
headers=dict(_response.headers), |
| 509 |
body=typing.cast( |
| 510 |
typing.Any, |
| 511 |
parse_obj_as( |
| 512 |
type_=typing.Any, |
| 513 |
object_=_response.json(), |
| 514 |
), |
| 515 |
), |
| 516 |
) |
| 517 |
if _response.status_code == 401: |
| 518 |
raise UnauthorizedError( |
| 519 |
headers=dict(_response.headers), |
| 520 |
body=typing.cast( |
| 521 |
typing.Any, |
| 522 |
parse_obj_as( |
| 523 |
type_=typing.Any, |
| 524 |
object_=_response.json(), |
| 525 |
), |
| 526 |
), |
| 527 |
) |
| 528 |
if _response.status_code == 403: |
| 529 |
raise ForbiddenError( |
| 530 |
headers=dict(_response.headers), |
| 531 |
body=typing.cast( |
| 532 |
typing.Any, |
| 533 |
parse_obj_as( |
| 534 |
type_=typing.Any, |
| 535 |
object_=_response.json(), |
| 536 |
), |
| 537 |
), |
| 538 |
) |
| 539 |
if _response.status_code == 404: |
| 540 |
raise NotFoundError( |
| 541 |
headers=dict(_response.headers), |
| 542 |
body=typing.cast( |
| 543 |
typing.Any, |
| 544 |
parse_obj_as( |
| 545 |
type_=typing.Any, |
| 546 |
object_=_response.json(), |
| 547 |
), |
| 548 |
), |
| 549 |
) |
| 550 |
if _response.status_code == 429: |
| 551 |
raise TooManyRequestsError( |
| 552 |
headers=dict(_response.headers), |
| 553 |
body=typing.cast( |
| 554 |
typing.Any, |
| 555 |
parse_obj_as( |
| 556 |
type_=typing.Any, |
| 557 |
object_=_response.json(), |
| 558 |
), |
| 559 |
), |
| 560 |
) |
| 561 |
_response_json = _response.json() |
| 562 |
except JSONDecodeError: |
| 563 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 564 |
except ValidationError as e: |
| 565 |
raise ParsingError( |
| 566 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 567 |
) |
| 568 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 569 |
|
| 570 |
|
| 571 |
class AsyncRawEmailTemplatesClient: |
| 572 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 573 |
self._client_wrapper = client_wrapper |
| 574 |
|
| 575 |
async def create( |
| 576 |
self, |
| 577 |
*, |
| 578 |
template: EmailTemplateNameEnum, |
| 579 |
body: typing.Optional[str] = OMIT, |
| 580 |
from_: typing.Optional[str] = OMIT, |
| 581 |
result_url: typing.Optional[str] = OMIT, |
| 582 |
subject: typing.Optional[str] = OMIT, |
| 583 |
syntax: typing.Optional[str] = OMIT, |
| 584 |
url_lifetime_in_seconds: typing.Optional[float] = OMIT, |
| 585 |
include_email_in_redirect: typing.Optional[bool] = OMIT, |
| 586 |
enabled: typing.Optional[bool] = OMIT, |
| 587 |
request_options: typing.Optional[RequestOptions] = None, |
| 588 |
) -> AsyncHttpResponse[CreateEmailTemplateResponseContent]: |
| 589 |
""" |
| 590 |
Create an email template. |
| 591 |
|
| 592 |
Parameters |
| 593 |
---------- |
| 594 |
template : EmailTemplateNameEnum |
| 595 |
|
| 596 |
body : typing.Optional[str] |
| 597 |
Body of the email template. |
| 598 |
|
| 599 |
from_ : typing.Optional[str] |
| 600 |
Senders `from` email address. |
| 601 |
|
| 602 |
result_url : typing.Optional[str] |
| 603 |
URL to redirect the user to after a successful action. |
| 604 |
|
| 605 |
subject : typing.Optional[str] |
| 606 |
Subject line of the email. |
| 607 |
|
| 608 |
syntax : typing.Optional[str] |
| 609 |
Syntax of the template body. |
| 610 |
|
| 611 |
url_lifetime_in_seconds : typing.Optional[float] |
| 612 |
Lifetime in seconds that the link within the email will be valid for. |
| 613 |
|
| 614 |
include_email_in_redirect : typing.Optional[bool] |
| 615 |
Whether the `reset_email` and `verify_email` templates should include the user's email address as the `email` parameter in the returnUrl (true) or whether no email address should be included in the redirect (false). Defaults to true. |
| 616 |
|
| 617 |
enabled : typing.Optional[bool] |
| 618 |
Whether the template is enabled (true) or disabled (false). |
| 619 |
|
| 620 |
request_options : typing.Optional[RequestOptions] |
| 621 |
Request-specific configuration. |
| 622 |
|
| 623 |
Returns |
| 624 |
------- |
| 625 |
AsyncHttpResponse[CreateEmailTemplateResponseContent] |
| 626 |
Template successfully created. |
| 627 |
""" |
| 628 |
_response = await self._client_wrapper.httpx_client.request( |
| 629 |
"email-templates", |
| 630 |
method="POST", |
| 631 |
json={ |
| 632 |
"template": template, |
| 633 |
"body": body, |
| 634 |
"from": from_, |
| 635 |
"resultUrl": result_url, |
| 636 |
"subject": subject, |
| 637 |
"syntax": syntax, |
| 638 |
"urlLifetimeInSeconds": url_lifetime_in_seconds, |
| 639 |
"includeEmailInRedirect": include_email_in_redirect, |
| 640 |
"enabled": enabled, |
| 641 |
}, |
| 642 |
headers={ |
| 643 |
"content-type": "application/json", |
| 644 |
}, |
| 645 |
request_options=request_options, |
| 646 |
omit=OMIT, |
| 647 |
) |
| 648 |
try: |
| 649 |
if 200 <= _response.status_code < 300: |
| 650 |
_data = typing.cast( |
| 651 |
CreateEmailTemplateResponseContent, |
| 652 |
parse_obj_as( |
| 653 |
type_=CreateEmailTemplateResponseContent, |
| 654 |
object_=_response.json(), |
| 655 |
), |
| 656 |
) |
| 657 |
return AsyncHttpResponse(response=_response, data=_data) |
| 658 |
if _response.status_code == 400: |
| 659 |
raise BadRequestError( |
| 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 == 401: |
| 670 |
raise UnauthorizedError( |
| 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 |
if _response.status_code == 403: |
| 681 |
raise ForbiddenError( |
| 682 |
headers=dict(_response.headers), |
| 683 |
body=typing.cast( |
| 684 |
typing.Any, |
| 685 |
parse_obj_as( |
| 686 |
type_=typing.Any, |
| 687 |
object_=_response.json(), |
| 688 |
), |
| 689 |
), |
| 690 |
) |
| 691 |
if _response.status_code == 409: |
| 692 |
raise ConflictError( |
| 693 |
headers=dict(_response.headers), |
| 694 |
body=typing.cast( |
| 695 |
typing.Any, |
| 696 |
parse_obj_as( |
| 697 |
type_=typing.Any, |
| 698 |
object_=_response.json(), |
| 699 |
), |
| 700 |
), |
| 701 |
) |
| 702 |
if _response.status_code == 429: |
| 703 |
raise TooManyRequestsError( |
| 704 |
headers=dict(_response.headers), |
| 705 |
body=typing.cast( |
| 706 |
typing.Any, |
| 707 |
parse_obj_as( |
| 708 |
type_=typing.Any, |
| 709 |
object_=_response.json(), |
| 710 |
), |
| 711 |
), |
| 712 |
) |
| 713 |
_response_json = _response.json() |
| 714 |
except JSONDecodeError: |
| 715 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 716 |
except ValidationError as e: |
| 717 |
raise ParsingError( |
| 718 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 719 |
) |
| 720 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 721 |
|
| 722 |
async def get( |
| 723 |
self, template_name: EmailTemplateNameEnum, *, request_options: typing.Optional[RequestOptions] = None |
| 724 |
) -> AsyncHttpResponse[GetEmailTemplateResponseContent]: |
| 725 |
""" |
| 726 |
Retrieve an email template by pre-defined name. These names are `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, and `async_approval`. The names `change_password`, and `password_reset` are also supported for legacy scenarios. |
| 727 |
|
| 728 |
Parameters |
| 729 |
---------- |
| 730 |
template_name : EmailTemplateNameEnum |
| 731 |
Template name. Can be `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, `async_approval`, `change_password` (legacy), or `password_reset` (legacy). |
| 732 |
|
| 733 |
request_options : typing.Optional[RequestOptions] |
| 734 |
Request-specific configuration. |
| 735 |
|
| 736 |
Returns |
| 737 |
------- |
| 738 |
AsyncHttpResponse[GetEmailTemplateResponseContent] |
| 739 |
Template successfully retrieved. |
| 740 |
""" |
| 741 |
_response = await self._client_wrapper.httpx_client.request( |
| 742 |
f"email-templates/{encode_path_param(template_name)}", |
| 743 |
method="GET", |
| 744 |
request_options=request_options, |
| 745 |
) |
| 746 |
try: |
| 747 |
if 200 <= _response.status_code < 300: |
| 748 |
_data = typing.cast( |
| 749 |
GetEmailTemplateResponseContent, |
| 750 |
parse_obj_as( |
| 751 |
type_=GetEmailTemplateResponseContent, |
| 752 |
object_=_response.json(), |
| 753 |
), |
| 754 |
) |
| 755 |
return AsyncHttpResponse(response=_response, data=_data) |
| 756 |
if _response.status_code == 400: |
| 757 |
raise BadRequestError( |
| 758 |
headers=dict(_response.headers), |
| 759 |
body=typing.cast( |
| 760 |
typing.Any, |
| 761 |
parse_obj_as( |
| 762 |
type_=typing.Any, |
| 763 |
object_=_response.json(), |
| 764 |
), |
| 765 |
), |
| 766 |
) |
| 767 |
if _response.status_code == 401: |
| 768 |
raise UnauthorizedError( |
| 769 |
headers=dict(_response.headers), |
| 770 |
body=typing.cast( |
| 771 |
typing.Any, |
| 772 |
parse_obj_as( |
| 773 |
type_=typing.Any, |
| 774 |
object_=_response.json(), |
| 775 |
), |
| 776 |
), |
| 777 |
) |
| 778 |
if _response.status_code == 403: |
| 779 |
raise ForbiddenError( |
| 780 |
headers=dict(_response.headers), |
| 781 |
body=typing.cast( |
| 782 |
typing.Any, |
| 783 |
parse_obj_as( |
| 784 |
type_=typing.Any, |
| 785 |
object_=_response.json(), |
| 786 |
), |
| 787 |
), |
| 788 |
) |
| 789 |
if _response.status_code == 429: |
| 790 |
raise TooManyRequestsError( |
| 791 |
headers=dict(_response.headers), |
| 792 |
body=typing.cast( |
| 793 |
typing.Any, |
| 794 |
parse_obj_as( |
| 795 |
type_=typing.Any, |
| 796 |
object_=_response.json(), |
| 797 |
), |
| 798 |
), |
| 799 |
) |
| 800 |
_response_json = _response.json() |
| 801 |
except JSONDecodeError: |
| 802 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 803 |
except ValidationError as e: |
| 804 |
raise ParsingError( |
| 805 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 806 |
) |
| 807 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 808 |
|
| 809 |
async def set( |
| 810 |
self, |
| 811 |
template_name: EmailTemplateNameEnum, |
| 812 |
*, |
| 813 |
template: EmailTemplateNameEnum, |
| 814 |
body: typing.Optional[str] = OMIT, |
| 815 |
from_: typing.Optional[str] = OMIT, |
| 816 |
result_url: typing.Optional[str] = OMIT, |
| 817 |
subject: typing.Optional[str] = OMIT, |
| 818 |
syntax: typing.Optional[str] = OMIT, |
| 819 |
url_lifetime_in_seconds: typing.Optional[float] = OMIT, |
| 820 |
include_email_in_redirect: typing.Optional[bool] = OMIT, |
| 821 |
enabled: typing.Optional[bool] = OMIT, |
| 822 |
request_options: typing.Optional[RequestOptions] = None, |
| 823 |
) -> AsyncHttpResponse[SetEmailTemplateResponseContent]: |
| 824 |
""" |
| 825 |
Update an email template. |
| 826 |
|
| 827 |
Parameters |
| 828 |
---------- |
| 829 |
template_name : EmailTemplateNameEnum |
| 830 |
Template name. Can be `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, `async_approval`, `change_password` (legacy), or `password_reset` (legacy). |
| 831 |
|
| 832 |
template : EmailTemplateNameEnum |
| 833 |
|
| 834 |
body : typing.Optional[str] |
| 835 |
Body of the email template. |
| 836 |
|
| 837 |
from_ : typing.Optional[str] |
| 838 |
Senders `from` email address. |
| 839 |
|
| 840 |
result_url : typing.Optional[str] |
| 841 |
URL to redirect the user to after a successful action. |
| 842 |
|
| 843 |
subject : typing.Optional[str] |
| 844 |
Subject line of the email. |
| 845 |
|
| 846 |
syntax : typing.Optional[str] |
| 847 |
Syntax of the template body. |
| 848 |
|
| 849 |
url_lifetime_in_seconds : typing.Optional[float] |
| 850 |
Lifetime in seconds that the link within the email will be valid for. |
| 851 |
|
| 852 |
include_email_in_redirect : typing.Optional[bool] |
| 853 |
Whether the `reset_email` and `verify_email` templates should include the user's email address as the `email` parameter in the returnUrl (true) or whether no email address should be included in the redirect (false). Defaults to true. |
| 854 |
|
| 855 |
enabled : typing.Optional[bool] |
| 856 |
Whether the template is enabled (true) or disabled (false). |
| 857 |
|
| 858 |
request_options : typing.Optional[RequestOptions] |
| 859 |
Request-specific configuration. |
| 860 |
|
| 861 |
Returns |
| 862 |
------- |
| 863 |
AsyncHttpResponse[SetEmailTemplateResponseContent] |
| 864 |
Template successfully updated. |
| 865 |
""" |
| 866 |
_response = await self._client_wrapper.httpx_client.request( |
| 867 |
f"email-templates/{encode_path_param(template_name)}", |
| 868 |
method="PUT", |
| 869 |
json={ |
| 870 |
"template": template, |
| 871 |
"body": body, |
| 872 |
"from": from_, |
| 873 |
"resultUrl": result_url, |
| 874 |
"subject": subject, |
| 875 |
"syntax": syntax, |
| 876 |
"urlLifetimeInSeconds": url_lifetime_in_seconds, |
| 877 |
"includeEmailInRedirect": include_email_in_redirect, |
| 878 |
"enabled": enabled, |
| 879 |
}, |
| 880 |
headers={ |
| 881 |
"content-type": "application/json", |
| 882 |
}, |
| 883 |
request_options=request_options, |
| 884 |
omit=OMIT, |
| 885 |
) |
| 886 |
try: |
| 887 |
if 200 <= _response.status_code < 300: |
| 888 |
_data = typing.cast( |
| 889 |
SetEmailTemplateResponseContent, |
| 890 |
parse_obj_as( |
| 891 |
type_=SetEmailTemplateResponseContent, |
| 892 |
object_=_response.json(), |
| 893 |
), |
| 894 |
) |
| 895 |
return AsyncHttpResponse(response=_response, data=_data) |
| 896 |
if _response.status_code == 400: |
| 897 |
raise BadRequestError( |
| 898 |
headers=dict(_response.headers), |
| 899 |
body=typing.cast( |
| 900 |
typing.Any, |
| 901 |
parse_obj_as( |
| 902 |
type_=typing.Any, |
| 903 |
object_=_response.json(), |
| 904 |
), |
| 905 |
), |
| 906 |
) |
| 907 |
if _response.status_code == 401: |
| 908 |
raise UnauthorizedError( |
| 909 |
headers=dict(_response.headers), |
| 910 |
body=typing.cast( |
| 911 |
typing.Any, |
| 912 |
parse_obj_as( |
| 913 |
type_=typing.Any, |
| 914 |
object_=_response.json(), |
| 915 |
), |
| 916 |
), |
| 917 |
) |
| 918 |
if _response.status_code == 403: |
| 919 |
raise ForbiddenError( |
| 920 |
headers=dict(_response.headers), |
| 921 |
body=typing.cast( |
| 922 |
typing.Any, |
| 923 |
parse_obj_as( |
| 924 |
type_=typing.Any, |
| 925 |
object_=_response.json(), |
| 926 |
), |
| 927 |
), |
| 928 |
) |
| 929 |
if _response.status_code == 404: |
| 930 |
raise NotFoundError( |
| 931 |
headers=dict(_response.headers), |
| 932 |
body=typing.cast( |
| 933 |
typing.Any, |
| 934 |
parse_obj_as( |
| 935 |
type_=typing.Any, |
| 936 |
object_=_response.json(), |
| 937 |
), |
| 938 |
), |
| 939 |
) |
| 940 |
if _response.status_code == 429: |
| 941 |
raise TooManyRequestsError( |
| 942 |
headers=dict(_response.headers), |
| 943 |
body=typing.cast( |
| 944 |
typing.Any, |
| 945 |
parse_obj_as( |
| 946 |
type_=typing.Any, |
| 947 |
object_=_response.json(), |
| 948 |
), |
| 949 |
), |
| 950 |
) |
| 951 |
_response_json = _response.json() |
| 952 |
except JSONDecodeError: |
| 953 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 954 |
except ValidationError as e: |
| 955 |
raise ParsingError( |
| 956 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 957 |
) |
| 958 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 959 |
|
| 960 |
async def update( |
| 961 |
self, |
| 962 |
template_name: EmailTemplateNameEnum, |
| 963 |
*, |
| 964 |
template: typing.Optional[EmailTemplateNameEnum] = OMIT, |
| 965 |
body: typing.Optional[str] = OMIT, |
| 966 |
from_: typing.Optional[str] = OMIT, |
| 967 |
result_url: typing.Optional[str] = OMIT, |
| 968 |
subject: typing.Optional[str] = OMIT, |
| 969 |
syntax: typing.Optional[str] = OMIT, |
| 970 |
url_lifetime_in_seconds: typing.Optional[float] = OMIT, |
| 971 |
include_email_in_redirect: typing.Optional[bool] = OMIT, |
| 972 |
enabled: typing.Optional[bool] = OMIT, |
| 973 |
request_options: typing.Optional[RequestOptions] = None, |
| 974 |
) -> AsyncHttpResponse[UpdateEmailTemplateResponseContent]: |
| 975 |
""" |
| 976 |
Modify an email template. |
| 977 |
|
| 978 |
Parameters |
| 979 |
---------- |
| 980 |
template_name : EmailTemplateNameEnum |
| 981 |
Template name. Can be `verify_email`, `verify_email_by_code`, `auth_email_by_code`, `reset_email`, `reset_email_by_code`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `user_invitation`, `async_approval`, `change_password` (legacy), or `password_reset` (legacy). |
| 982 |
|
| 983 |
template : typing.Optional[EmailTemplateNameEnum] |
| 984 |
|
| 985 |
body : typing.Optional[str] |
| 986 |
Body of the email template. |
| 987 |
|
| 988 |
from_ : typing.Optional[str] |
| 989 |
Senders `from` email address. |
| 990 |
|
| 991 |
result_url : typing.Optional[str] |
| 992 |
URL to redirect the user to after a successful action. |
| 993 |
|
| 994 |
subject : typing.Optional[str] |
| 995 |
Subject line of the email. |
| 996 |
|
| 997 |
syntax : typing.Optional[str] |
| 998 |
Syntax of the template body. |
| 999 |
|
| 1000 |
url_lifetime_in_seconds : typing.Optional[float] |
| 1001 |
Lifetime in seconds that the link within the email will be valid for. |
| 1002 |
|
| 1003 |
include_email_in_redirect : typing.Optional[bool] |
| 1004 |
Whether the `reset_email` and `verify_email` templates should include the user's email address as the `email` parameter in the returnUrl (true) or whether no email address should be included in the redirect (false). Defaults to true. |
| 1005 |
|
| 1006 |
enabled : typing.Optional[bool] |
| 1007 |
Whether the template is enabled (true) or disabled (false). |
| 1008 |
|
| 1009 |
request_options : typing.Optional[RequestOptions] |
| 1010 |
Request-specific configuration. |
| 1011 |
|
| 1012 |
Returns |
| 1013 |
------- |
| 1014 |
AsyncHttpResponse[UpdateEmailTemplateResponseContent] |
| 1015 |
Template successfully updated. |
| 1016 |
""" |
| 1017 |
_response = await self._client_wrapper.httpx_client.request( |
| 1018 |
f"email-templates/{encode_path_param(template_name)}", |
| 1019 |
method="PATCH", |
| 1020 |
json={ |
| 1021 |
"template": template, |
| 1022 |
"body": body, |
| 1023 |
"from": from_, |
| 1024 |
"resultUrl": result_url, |
| 1025 |
"subject": subject, |
| 1026 |
"syntax": syntax, |
| 1027 |
"urlLifetimeInSeconds": url_lifetime_in_seconds, |
| 1028 |
"includeEmailInRedirect": include_email_in_redirect, |
| 1029 |
"enabled": enabled, |
| 1030 |
}, |
| 1031 |
headers={ |
| 1032 |
"content-type": "application/json", |
| 1033 |
}, |
| 1034 |
request_options=request_options, |
| 1035 |
omit=OMIT, |
| 1036 |
) |
| 1037 |
try: |
| 1038 |
if 200 <= _response.status_code < 300: |
| 1039 |
_data = typing.cast( |
| 1040 |
UpdateEmailTemplateResponseContent, |
| 1041 |
parse_obj_as( |
| 1042 |
type_=UpdateEmailTemplateResponseContent, |
| 1043 |
object_=_response.json(), |
| 1044 |
), |
| 1045 |
) |
| 1046 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1047 |
if _response.status_code == 400: |
| 1048 |
raise BadRequestError( |
| 1049 |
headers=dict(_response.headers), |
| 1050 |
body=typing.cast( |
| 1051 |
typing.Any, |
| 1052 |
parse_obj_as( |
| 1053 |
type_=typing.Any, |
| 1054 |
object_=_response.json(), |
| 1055 |
), |
| 1056 |
), |
| 1057 |
) |
| 1058 |
if _response.status_code == 401: |
| 1059 |
raise UnauthorizedError( |
| 1060 |
headers=dict(_response.headers), |
| 1061 |
body=typing.cast( |
| 1062 |
typing.Any, |
| 1063 |
parse_obj_as( |
| 1064 |
type_=typing.Any, |
| 1065 |
object_=_response.json(), |
| 1066 |
), |
| 1067 |
), |
| 1068 |
) |
| 1069 |
if _response.status_code == 403: |
| 1070 |
raise ForbiddenError( |
| 1071 |
headers=dict(_response.headers), |
| 1072 |
body=typing.cast( |
| 1073 |
typing.Any, |
| 1074 |
parse_obj_as( |
| 1075 |
type_=typing.Any, |
| 1076 |
object_=_response.json(), |
| 1077 |
), |
| 1078 |
), |
| 1079 |
) |
| 1080 |
if _response.status_code == 404: |
| 1081 |
raise NotFoundError( |
| 1082 |
headers=dict(_response.headers), |
| 1083 |
body=typing.cast( |
| 1084 |
typing.Any, |
| 1085 |
parse_obj_as( |
| 1086 |
type_=typing.Any, |
| 1087 |
object_=_response.json(), |
| 1088 |
), |
| 1089 |
), |
| 1090 |
) |
| 1091 |
if _response.status_code == 429: |
| 1092 |
raise TooManyRequestsError( |
| 1093 |
headers=dict(_response.headers), |
| 1094 |
body=typing.cast( |
| 1095 |
typing.Any, |
| 1096 |
parse_obj_as( |
| 1097 |
type_=typing.Any, |
| 1098 |
object_=_response.json(), |
| 1099 |
), |
| 1100 |
), |
| 1101 |
) |
| 1102 |
_response_json = _response.json() |
| 1103 |
except JSONDecodeError: |
| 1104 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1105 |
except ValidationError as e: |
| 1106 |
raise ParsingError( |
| 1107 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1108 |
) |
| 1109 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |