Debian Codegraph @

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