Debian Codegraph @

src/auth0/management/hooks/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4 from json.decoder import JSONDecodeError
5
6 from ..core.api_error import ApiError
7 from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8 from ..core.http_response import AsyncHttpResponse, HttpResponse
9 from ..core.jsonable_encoder import encode_path_param
10 from ..core.pagination import AsyncPager, SyncPager
11 from ..core.parse_error import ParsingError
12 from ..core.pydantic_utilities import parse_obj_as
13 from ..core.request_options import RequestOptions
14 from ..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_hook_response_content import CreateHookResponseContent
21 from ..types.get_hook_response_content import GetHookResponseContent
22 from ..types.hook import Hook
23 from ..types.hook_dependencies import HookDependencies
24 from ..types.hook_trigger_id_enum import HookTriggerIdEnum
25 from ..types.list_hooks_offset_paginated_response_content import ListHooksOffsetPaginatedResponseContent
26 from ..types.update_hook_response_content import UpdateHookResponseContent
27 from pydantic import ValidationError
28
29 # this is used as the default value for optional parameters
30 OMIT = typing.cast(typing.Any, ...)
31
32
33 class RawHooksClient:
34 def __init__(self, *, client_wrapper: SyncClientWrapper):
35 self._client_wrapper = client_wrapper
36
37 def list(
38 self,
39 *,
40 page: typing.Optional[int] = 0,
41 per_page: typing.Optional[int] = 50,
42 include_totals: typing.Optional[bool] = True,
43 enabled: typing.Optional[bool] = None,
44 fields: typing.Optional[str] = None,
45 trigger_id: typing.Optional[HookTriggerIdEnum] = None,
46 request_options: typing.Optional[RequestOptions] = None,
47 ) -> SyncPager[Hook, ListHooksOffsetPaginatedResponseContent]:
48 """
49 Retrieve all [hooks](https://auth0.com/docs/hooks). Accepts a list of fields to include or exclude in the result.
50
51 Parameters
52 ----------
53 page : typing.Optional[int]
54 Page index of the results to return. First page is 0.
55
56 per_page : typing.Optional[int]
57 Number of results per page.
58
59 include_totals : typing.Optional[bool]
60 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
61
62 enabled : typing.Optional[bool]
63 Optional filter on whether a hook is enabled (true) or disabled (false).
64
65 fields : typing.Optional[str]
66 Comma-separated list of fields to include in the result. Leave empty to retrieve all fields.
67
68 trigger_id : typing.Optional[HookTriggerIdEnum]
69 Retrieves hooks that match the trigger
70
71 request_options : typing.Optional[RequestOptions]
72 Request-specific configuration.
73
74 Returns
75 -------
76 SyncPager[Hook, ListHooksOffsetPaginatedResponseContent]
77 Hooks successfully retrieved.
78 """
79 page = page if page is not None else 0
80
81 _response = self._client_wrapper.httpx_client.request(
82 "hooks",
83 method="GET",
84 params={
85 "page": page,
86 "per_page": per_page,
87 "include_totals": include_totals,
88 "enabled": enabled,
89 "fields": fields,
90 "triggerId": trigger_id,
91 },
92 request_options=request_options,
93 )
94 try:
95 if 200 <= _response.status_code < 300:
96 _parsed_response = typing.cast(
97 ListHooksOffsetPaginatedResponseContent,
98 parse_obj_as(
99 type_=ListHooksOffsetPaginatedResponseContent, # type: ignore
100 object_=_response.json(),
101 ),
102 )
103 _items = _parsed_response.hooks
104 _has_next = len(_items or []) > 0
105 _get_next = lambda: self.list(
106 page=page + 1,
107 per_page=per_page,
108 include_totals=include_totals,
109 enabled=enabled,
110 fields=fields,
111 trigger_id=trigger_id,
112 request_options=request_options,
113 )
114 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
115 if _response.status_code == 400:
116 raise BadRequestError(
117 headers=dict(_response.headers),
118 body=typing.cast(
119 typing.Any,
120 parse_obj_as(
121 type_=typing.Any, # type: ignore
122 object_=_response.json(),
123 ),
124 ),
125 )
126 if _response.status_code == 401:
127 raise UnauthorizedError(
128 headers=dict(_response.headers),
129 body=typing.cast(
130 typing.Any,
131 parse_obj_as(
132 type_=typing.Any, # type: ignore
133 object_=_response.json(),
134 ),
135 ),
136 )
137 if _response.status_code == 403:
138 raise ForbiddenError(
139 headers=dict(_response.headers),
140 body=typing.cast(
141 typing.Any,
142 parse_obj_as(
143 type_=typing.Any, # type: ignore
144 object_=_response.json(),
145 ),
146 ),
147 )
148 if _response.status_code == 404:
149 raise NotFoundError(
150 headers=dict(_response.headers),
151 body=typing.cast(
152 typing.Any,
153 parse_obj_as(
154 type_=typing.Any, # type: ignore
155 object_=_response.json(),
156 ),
157 ),
158 )
159 if _response.status_code == 429:
160 raise TooManyRequestsError(
161 headers=dict(_response.headers),
162 body=typing.cast(
163 typing.Any,
164 parse_obj_as(
165 type_=typing.Any, # type: ignore
166 object_=_response.json(),
167 ),
168 ),
169 )
170 _response_json = _response.json()
171 except JSONDecodeError:
172 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
173 except ValidationError as e:
174 raise ParsingError(
175 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
176 )
177 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
178
179 def create(
180 self,
181 *,
182 name: str,
183 script: str,
184 trigger_id: HookTriggerIdEnum,
185 enabled: typing.Optional[bool] = OMIT,
186 dependencies: typing.Optional[HookDependencies] = OMIT,
187 request_options: typing.Optional[RequestOptions] = None,
188 ) -> HttpResponse[CreateHookResponseContent]:
189 """
190 Create a new hook.
191
192 Parameters
193 ----------
194 name : str
195 Name of this hook.
196
197 script : str
198 Code to be executed when this hook runs.
199
200 trigger_id : HookTriggerIdEnum
201 Execution stage of this rule. Can be `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, or `send-phone-message`.
202
203 enabled : typing.Optional[bool]
204 Whether this hook will be executed (true) or ignored (false).
205
206 dependencies : typing.Optional[HookDependencies]
207
208 request_options : typing.Optional[RequestOptions]
209 Request-specific configuration.
210
211 Returns
212 -------
213 HttpResponse[CreateHookResponseContent]
214 Hook successfully created.
215 """
216 _response = self._client_wrapper.httpx_client.request(
217 "hooks",
218 method="POST",
219 json={
220 "name": name,
221 "script": script,
222 "enabled": enabled,
223 "dependencies": dependencies,
224 "triggerId": trigger_id,
225 },
226 headers={
227 "content-type": "application/json",
228 },
229 request_options=request_options,
230 omit=OMIT,
231 )
232 try:
233 if 200 <= _response.status_code < 300:
234 _data = typing.cast(
235 CreateHookResponseContent,
236 parse_obj_as(
237 type_=CreateHookResponseContent, # type: ignore
238 object_=_response.json(),
239 ),
240 )
241 return HttpResponse(response=_response, data=_data)
242 if _response.status_code == 400:
243 raise BadRequestError(
244 headers=dict(_response.headers),
245 body=typing.cast(
246 typing.Any,
247 parse_obj_as(
248 type_=typing.Any, # type: ignore
249 object_=_response.json(),
250 ),
251 ),
252 )
253 if _response.status_code == 401:
254 raise UnauthorizedError(
255 headers=dict(_response.headers),
256 body=typing.cast(
257 typing.Any,
258 parse_obj_as(
259 type_=typing.Any, # type: ignore
260 object_=_response.json(),
261 ),
262 ),
263 )
264 if _response.status_code == 403:
265 raise ForbiddenError(
266 headers=dict(_response.headers),
267 body=typing.cast(
268 typing.Any,
269 parse_obj_as(
270 type_=typing.Any, # type: ignore
271 object_=_response.json(),
272 ),
273 ),
274 )
275 if _response.status_code == 409:
276 raise ConflictError(
277 headers=dict(_response.headers),
278 body=typing.cast(
279 typing.Any,
280 parse_obj_as(
281 type_=typing.Any, # type: ignore
282 object_=_response.json(),
283 ),
284 ),
285 )
286 if _response.status_code == 429:
287 raise TooManyRequestsError(
288 headers=dict(_response.headers),
289 body=typing.cast(
290 typing.Any,
291 parse_obj_as(
292 type_=typing.Any, # type: ignore
293 object_=_response.json(),
294 ),
295 ),
296 )
297 _response_json = _response.json()
298 except JSONDecodeError:
299 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
300 except ValidationError as e:
301 raise ParsingError(
302 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
303 )
304 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
305
306 def get(
307 self, id: str, *, fields: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
308 ) -> HttpResponse[GetHookResponseContent]:
309 """
310 Retrieve [a hook](https://auth0.com/docs/hooks) by its ID. Accepts a list of fields to include in the result.
311
312 Parameters
313 ----------
314 id : str
315 ID of the hook to retrieve.
316
317 fields : typing.Optional[str]
318 Comma-separated list of fields to include in the result. Leave empty to retrieve all fields.
319
320 request_options : typing.Optional[RequestOptions]
321 Request-specific configuration.
322
323 Returns
324 -------
325 HttpResponse[GetHookResponseContent]
326 Hook successfully retrieved.
327 """
328 _response = self._client_wrapper.httpx_client.request(
329 f"hooks/{encode_path_param(id)}",
330 method="GET",
331 params={
332 "fields": fields,
333 },
334 request_options=request_options,
335 )
336 try:
337 if 200 <= _response.status_code < 300:
338 _data = typing.cast(
339 GetHookResponseContent,
340 parse_obj_as(
341 type_=GetHookResponseContent, # type: ignore
342 object_=_response.json(),
343 ),
344 )
345 return HttpResponse(response=_response, data=_data)
346 if _response.status_code == 400:
347 raise BadRequestError(
348 headers=dict(_response.headers),
349 body=typing.cast(
350 typing.Any,
351 parse_obj_as(
352 type_=typing.Any, # type: ignore
353 object_=_response.json(),
354 ),
355 ),
356 )
357 if _response.status_code == 401:
358 raise UnauthorizedError(
359 headers=dict(_response.headers),
360 body=typing.cast(
361 typing.Any,
362 parse_obj_as(
363 type_=typing.Any, # type: ignore
364 object_=_response.json(),
365 ),
366 ),
367 )
368 if _response.status_code == 403:
369 raise ForbiddenError(
370 headers=dict(_response.headers),
371 body=typing.cast(
372 typing.Any,
373 parse_obj_as(
374 type_=typing.Any, # type: ignore
375 object_=_response.json(),
376 ),
377 ),
378 )
379 if _response.status_code == 404:
380 raise NotFoundError(
381 headers=dict(_response.headers),
382 body=typing.cast(
383 typing.Any,
384 parse_obj_as(
385 type_=typing.Any, # type: ignore
386 object_=_response.json(),
387 ),
388 ),
389 )
390 if _response.status_code == 429:
391 raise TooManyRequestsError(
392 headers=dict(_response.headers),
393 body=typing.cast(
394 typing.Any,
395 parse_obj_as(
396 type_=typing.Any, # type: ignore
397 object_=_response.json(),
398 ),
399 ),
400 )
401 _response_json = _response.json()
402 except JSONDecodeError:
403 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
404 except ValidationError as e:
405 raise ParsingError(
406 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
407 )
408 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
409
410 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
411 """
412 Delete a hook.
413
414 Parameters
415 ----------
416 id : str
417 ID of the hook to delete.
418
419 request_options : typing.Optional[RequestOptions]
420 Request-specific configuration.
421
422 Returns
423 -------
424 HttpResponse[None]
425 """
426 _response = self._client_wrapper.httpx_client.request(
427 f"hooks/{encode_path_param(id)}",
428 method="DELETE",
429 request_options=request_options,
430 )
431 try:
432 if 200 <= _response.status_code < 300:
433 return HttpResponse(response=_response, data=None)
434 if _response.status_code == 400:
435 raise BadRequestError(
436 headers=dict(_response.headers),
437 body=typing.cast(
438 typing.Any,
439 parse_obj_as(
440 type_=typing.Any, # type: ignore
441 object_=_response.json(),
442 ),
443 ),
444 )
445 if _response.status_code == 401:
446 raise UnauthorizedError(
447 headers=dict(_response.headers),
448 body=typing.cast(
449 typing.Any,
450 parse_obj_as(
451 type_=typing.Any, # type: ignore
452 object_=_response.json(),
453 ),
454 ),
455 )
456 if _response.status_code == 403:
457 raise ForbiddenError(
458 headers=dict(_response.headers),
459 body=typing.cast(
460 typing.Any,
461 parse_obj_as(
462 type_=typing.Any, # type: ignore
463 object_=_response.json(),
464 ),
465 ),
466 )
467 if _response.status_code == 429:
468 raise TooManyRequestsError(
469 headers=dict(_response.headers),
470 body=typing.cast(
471 typing.Any,
472 parse_obj_as(
473 type_=typing.Any, # type: ignore
474 object_=_response.json(),
475 ),
476 ),
477 )
478 _response_json = _response.json()
479 except JSONDecodeError:
480 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
481 except ValidationError as e:
482 raise ParsingError(
483 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
484 )
485 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
486
487 def update(
488 self,
489 id: str,
490 *,
491 name: typing.Optional[str] = OMIT,
492 script: typing.Optional[str] = OMIT,
493 enabled: typing.Optional[bool] = OMIT,
494 dependencies: typing.Optional[HookDependencies] = OMIT,
495 request_options: typing.Optional[RequestOptions] = None,
496 ) -> HttpResponse[UpdateHookResponseContent]:
497 """
498 Update an existing hook.
499
500 Parameters
501 ----------
502 id : str
503 ID of the hook to update.
504
505 name : typing.Optional[str]
506 Name of this hook.
507
508 script : typing.Optional[str]
509 Code to be executed when this hook runs.
510
511 enabled : typing.Optional[bool]
512 Whether this hook will be executed (true) or ignored (false).
513
514 dependencies : typing.Optional[HookDependencies]
515
516 request_options : typing.Optional[RequestOptions]
517 Request-specific configuration.
518
519 Returns
520 -------
521 HttpResponse[UpdateHookResponseContent]
522 Hook successfully created.
523 """
524 _response = self._client_wrapper.httpx_client.request(
525 f"hooks/{encode_path_param(id)}",
526 method="PATCH",
527 json={
528 "name": name,
529 "script": script,
530 "enabled": enabled,
531 "dependencies": dependencies,
532 },
533 headers={
534 "content-type": "application/json",
535 },
536 request_options=request_options,
537 omit=OMIT,
538 )
539 try:
540 if 200 <= _response.status_code < 300:
541 _data = typing.cast(
542 UpdateHookResponseContent,
543 parse_obj_as(
544 type_=UpdateHookResponseContent, # type: ignore
545 object_=_response.json(),
546 ),
547 )
548 return HttpResponse(response=_response, data=_data)
549 if _response.status_code == 400:
550 raise BadRequestError(
551 headers=dict(_response.headers),
552 body=typing.cast(
553 typing.Any,
554 parse_obj_as(
555 type_=typing.Any, # type: ignore
556 object_=_response.json(),
557 ),
558 ),
559 )
560 if _response.status_code == 401:
561 raise UnauthorizedError(
562 headers=dict(_response.headers),
563 body=typing.cast(
564 typing.Any,
565 parse_obj_as(
566 type_=typing.Any, # type: ignore
567 object_=_response.json(),
568 ),
569 ),
570 )
571 if _response.status_code == 403:
572 raise ForbiddenError(
573 headers=dict(_response.headers),
574 body=typing.cast(
575 typing.Any,
576 parse_obj_as(
577 type_=typing.Any, # type: ignore
578 object_=_response.json(),
579 ),
580 ),
581 )
582 if _response.status_code == 404:
583 raise NotFoundError(
584 headers=dict(_response.headers),
585 body=typing.cast(
586 typing.Any,
587 parse_obj_as(
588 type_=typing.Any, # type: ignore
589 object_=_response.json(),
590 ),
591 ),
592 )
593 if _response.status_code == 409:
594 raise ConflictError(
595 headers=dict(_response.headers),
596 body=typing.cast(
597 typing.Any,
598 parse_obj_as(
599 type_=typing.Any, # type: ignore
600 object_=_response.json(),
601 ),
602 ),
603 )
604 if _response.status_code == 429:
605 raise TooManyRequestsError(
606 headers=dict(_response.headers),
607 body=typing.cast(
608 typing.Any,
609 parse_obj_as(
610 type_=typing.Any, # type: ignore
611 object_=_response.json(),
612 ),
613 ),
614 )
615 _response_json = _response.json()
616 except JSONDecodeError:
617 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
618 except ValidationError as e:
619 raise ParsingError(
620 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
621 )
622 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
623
624
625 class AsyncRawHooksClient:
626 def __init__(self, *, client_wrapper: AsyncClientWrapper):
627 self._client_wrapper = client_wrapper
628
629 async def list(
630 self,
631 *,
632 page: typing.Optional[int] = 0,
633 per_page: typing.Optional[int] = 50,
634 include_totals: typing.Optional[bool] = True,
635 enabled: typing.Optional[bool] = None,
636 fields: typing.Optional[str] = None,
637 trigger_id: typing.Optional[HookTriggerIdEnum] = None,
638 request_options: typing.Optional[RequestOptions] = None,
639 ) -> AsyncPager[Hook, ListHooksOffsetPaginatedResponseContent]:
640 """
641 Retrieve all [hooks](https://auth0.com/docs/hooks). Accepts a list of fields to include or exclude in the result.
642
643 Parameters
644 ----------
645 page : typing.Optional[int]
646 Page index of the results to return. First page is 0.
647
648 per_page : typing.Optional[int]
649 Number of results per page.
650
651 include_totals : typing.Optional[bool]
652 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
653
654 enabled : typing.Optional[bool]
655 Optional filter on whether a hook is enabled (true) or disabled (false).
656
657 fields : typing.Optional[str]
658 Comma-separated list of fields to include in the result. Leave empty to retrieve all fields.
659
660 trigger_id : typing.Optional[HookTriggerIdEnum]
661 Retrieves hooks that match the trigger
662
663 request_options : typing.Optional[RequestOptions]
664 Request-specific configuration.
665
666 Returns
667 -------
668 AsyncPager[Hook, ListHooksOffsetPaginatedResponseContent]
669 Hooks successfully retrieved.
670 """
671 page = page if page is not None else 0
672
673 _response = await self._client_wrapper.httpx_client.request(
674 "hooks",
675 method="GET",
676 params={
677 "page": page,
678 "per_page": per_page,
679 "include_totals": include_totals,
680 "enabled": enabled,
681 "fields": fields,
682 "triggerId": trigger_id,
683 },
684 request_options=request_options,
685 )
686 try:
687 if 200 <= _response.status_code < 300:
688 _parsed_response = typing.cast(
689 ListHooksOffsetPaginatedResponseContent,
690 parse_obj_as(
691 type_=ListHooksOffsetPaginatedResponseContent, # type: ignore
692 object_=_response.json(),
693 ),
694 )
695 _items = _parsed_response.hooks
696 _has_next = len(_items or []) > 0
697
698 async def _get_next():
699 return await self.list(
700 page=page + 1,
701 per_page=per_page,
702 include_totals=include_totals,
703 enabled=enabled,
704 fields=fields,
705 trigger_id=trigger_id,
706 request_options=request_options,
707 )
708
709 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
710 if _response.status_code == 400:
711 raise BadRequestError(
712 headers=dict(_response.headers),
713 body=typing.cast(
714 typing.Any,
715 parse_obj_as(
716 type_=typing.Any, # type: ignore
717 object_=_response.json(),
718 ),
719 ),
720 )
721 if _response.status_code == 401:
722 raise UnauthorizedError(
723 headers=dict(_response.headers),
724 body=typing.cast(
725 typing.Any,
726 parse_obj_as(
727 type_=typing.Any, # type: ignore
728 object_=_response.json(),
729 ),
730 ),
731 )
732 if _response.status_code == 403:
733 raise ForbiddenError(
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 == 404:
744 raise NotFoundError(
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 == 429:
755 raise TooManyRequestsError(
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 _response_json = _response.json()
766 except JSONDecodeError:
767 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
768 except ValidationError as e:
769 raise ParsingError(
770 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
771 )
772 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
773
774 async def create(
775 self,
776 *,
777 name: str,
778 script: str,
779 trigger_id: HookTriggerIdEnum,
780 enabled: typing.Optional[bool] = OMIT,
781 dependencies: typing.Optional[HookDependencies] = OMIT,
782 request_options: typing.Optional[RequestOptions] = None,
783 ) -> AsyncHttpResponse[CreateHookResponseContent]:
784 """
785 Create a new hook.
786
787 Parameters
788 ----------
789 name : str
790 Name of this hook.
791
792 script : str
793 Code to be executed when this hook runs.
794
795 trigger_id : HookTriggerIdEnum
796 Execution stage of this rule. Can be `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, or `send-phone-message`.
797
798 enabled : typing.Optional[bool]
799 Whether this hook will be executed (true) or ignored (false).
800
801 dependencies : typing.Optional[HookDependencies]
802
803 request_options : typing.Optional[RequestOptions]
804 Request-specific configuration.
805
806 Returns
807 -------
808 AsyncHttpResponse[CreateHookResponseContent]
809 Hook successfully created.
810 """
811 _response = await self._client_wrapper.httpx_client.request(
812 "hooks",
813 method="POST",
814 json={
815 "name": name,
816 "script": script,
817 "enabled": enabled,
818 "dependencies": dependencies,
819 "triggerId": trigger_id,
820 },
821 headers={
822 "content-type": "application/json",
823 },
824 request_options=request_options,
825 omit=OMIT,
826 )
827 try:
828 if 200 <= _response.status_code < 300:
829 _data = typing.cast(
830 CreateHookResponseContent,
831 parse_obj_as(
832 type_=CreateHookResponseContent, # type: ignore
833 object_=_response.json(),
834 ),
835 )
836 return AsyncHttpResponse(response=_response, data=_data)
837 if _response.status_code == 400:
838 raise BadRequestError(
839 headers=dict(_response.headers),
840 body=typing.cast(
841 typing.Any,
842 parse_obj_as(
843 type_=typing.Any, # type: ignore
844 object_=_response.json(),
845 ),
846 ),
847 )
848 if _response.status_code == 401:
849 raise UnauthorizedError(
850 headers=dict(_response.headers),
851 body=typing.cast(
852 typing.Any,
853 parse_obj_as(
854 type_=typing.Any, # type: ignore
855 object_=_response.json(),
856 ),
857 ),
858 )
859 if _response.status_code == 403:
860 raise ForbiddenError(
861 headers=dict(_response.headers),
862 body=typing.cast(
863 typing.Any,
864 parse_obj_as(
865 type_=typing.Any, # type: ignore
866 object_=_response.json(),
867 ),
868 ),
869 )
870 if _response.status_code == 409:
871 raise ConflictError(
872 headers=dict(_response.headers),
873 body=typing.cast(
874 typing.Any,
875 parse_obj_as(
876 type_=typing.Any, # type: ignore
877 object_=_response.json(),
878 ),
879 ),
880 )
881 if _response.status_code == 429:
882 raise TooManyRequestsError(
883 headers=dict(_response.headers),
884 body=typing.cast(
885 typing.Any,
886 parse_obj_as(
887 type_=typing.Any, # type: ignore
888 object_=_response.json(),
889 ),
890 ),
891 )
892 _response_json = _response.json()
893 except JSONDecodeError:
894 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
895 except ValidationError as e:
896 raise ParsingError(
897 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
898 )
899 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
900
901 async def get(
902 self, id: str, *, fields: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
903 ) -> AsyncHttpResponse[GetHookResponseContent]:
904 """
905 Retrieve [a hook](https://auth0.com/docs/hooks) by its ID. Accepts a list of fields to include in the result.
906
907 Parameters
908 ----------
909 id : str
910 ID of the hook to retrieve.
911
912 fields : typing.Optional[str]
913 Comma-separated list of fields to include in the result. Leave empty to retrieve all fields.
914
915 request_options : typing.Optional[RequestOptions]
916 Request-specific configuration.
917
918 Returns
919 -------
920 AsyncHttpResponse[GetHookResponseContent]
921 Hook successfully retrieved.
922 """
923 _response = await self._client_wrapper.httpx_client.request(
924 f"hooks/{encode_path_param(id)}",
925 method="GET",
926 params={
927 "fields": fields,
928 },
929 request_options=request_options,
930 )
931 try:
932 if 200 <= _response.status_code < 300:
933 _data = typing.cast(
934 GetHookResponseContent,
935 parse_obj_as(
936 type_=GetHookResponseContent, # type: ignore
937 object_=_response.json(),
938 ),
939 )
940 return AsyncHttpResponse(response=_response, data=_data)
941 if _response.status_code == 400:
942 raise BadRequestError(
943 headers=dict(_response.headers),
944 body=typing.cast(
945 typing.Any,
946 parse_obj_as(
947 type_=typing.Any, # type: ignore
948 object_=_response.json(),
949 ),
950 ),
951 )
952 if _response.status_code == 401:
953 raise UnauthorizedError(
954 headers=dict(_response.headers),
955 body=typing.cast(
956 typing.Any,
957 parse_obj_as(
958 type_=typing.Any, # type: ignore
959 object_=_response.json(),
960 ),
961 ),
962 )
963 if _response.status_code == 403:
964 raise ForbiddenError(
965 headers=dict(_response.headers),
966 body=typing.cast(
967 typing.Any,
968 parse_obj_as(
969 type_=typing.Any, # type: ignore
970 object_=_response.json(),
971 ),
972 ),
973 )
974 if _response.status_code == 404:
975 raise NotFoundError(
976 headers=dict(_response.headers),
977 body=typing.cast(
978 typing.Any,
979 parse_obj_as(
980 type_=typing.Any, # type: ignore
981 object_=_response.json(),
982 ),
983 ),
984 )
985 if _response.status_code == 429:
986 raise TooManyRequestsError(
987 headers=dict(_response.headers),
988 body=typing.cast(
989 typing.Any,
990 parse_obj_as(
991 type_=typing.Any, # type: ignore
992 object_=_response.json(),
993 ),
994 ),
995 )
996 _response_json = _response.json()
997 except JSONDecodeError:
998 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
999 except ValidationError as e:
1000 raise ParsingError(
1001 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1002 )
1003 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1004
1005 async def delete(
1006 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
1007 ) -> AsyncHttpResponse[None]:
1008 """
1009 Delete a hook.
1010
1011 Parameters
1012 ----------
1013 id : str
1014 ID of the hook to delete.
1015
1016 request_options : typing.Optional[RequestOptions]
1017 Request-specific configuration.
1018
1019 Returns
1020 -------
1021 AsyncHttpResponse[None]
1022 """
1023 _response = await self._client_wrapper.httpx_client.request(
1024 f"hooks/{encode_path_param(id)}",
1025 method="DELETE",
1026 request_options=request_options,
1027 )
1028 try:
1029 if 200 <= _response.status_code < 300:
1030 return AsyncHttpResponse(response=_response, data=None)
1031 if _response.status_code == 400:
1032 raise BadRequestError(
1033 headers=dict(_response.headers),
1034 body=typing.cast(
1035 typing.Any,
1036 parse_obj_as(
1037 type_=typing.Any, # type: ignore
1038 object_=_response.json(),
1039 ),
1040 ),
1041 )
1042 if _response.status_code == 401:
1043 raise UnauthorizedError(
1044 headers=dict(_response.headers),
1045 body=typing.cast(
1046 typing.Any,
1047 parse_obj_as(
1048 type_=typing.Any, # type: ignore
1049 object_=_response.json(),
1050 ),
1051 ),
1052 )
1053 if _response.status_code == 403:
1054 raise ForbiddenError(
1055 headers=dict(_response.headers),
1056 body=typing.cast(
1057 typing.Any,
1058 parse_obj_as(
1059 type_=typing.Any, # type: ignore
1060 object_=_response.json(),
1061 ),
1062 ),
1063 )
1064 if _response.status_code == 429:
1065 raise TooManyRequestsError(
1066 headers=dict(_response.headers),
1067 body=typing.cast(
1068 typing.Any,
1069 parse_obj_as(
1070 type_=typing.Any, # type: ignore
1071 object_=_response.json(),
1072 ),
1073 ),
1074 )
1075 _response_json = _response.json()
1076 except JSONDecodeError:
1077 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1078 except ValidationError as e:
1079 raise ParsingError(
1080 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1081 )
1082 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1083
1084 async def update(
1085 self,
1086 id: str,
1087 *,
1088 name: typing.Optional[str] = OMIT,
1089 script: typing.Optional[str] = OMIT,
1090 enabled: typing.Optional[bool] = OMIT,
1091 dependencies: typing.Optional[HookDependencies] = OMIT,
1092 request_options: typing.Optional[RequestOptions] = None,
1093 ) -> AsyncHttpResponse[UpdateHookResponseContent]:
1094 """
1095 Update an existing hook.
1096
1097 Parameters
1098 ----------
1099 id : str
1100 ID of the hook to update.
1101
1102 name : typing.Optional[str]
1103 Name of this hook.
1104
1105 script : typing.Optional[str]
1106 Code to be executed when this hook runs.
1107
1108 enabled : typing.Optional[bool]
1109 Whether this hook will be executed (true) or ignored (false).
1110
1111 dependencies : typing.Optional[HookDependencies]
1112
1113 request_options : typing.Optional[RequestOptions]
1114 Request-specific configuration.
1115
1116 Returns
1117 -------
1118 AsyncHttpResponse[UpdateHookResponseContent]
1119 Hook successfully created.
1120 """
1121 _response = await self._client_wrapper.httpx_client.request(
1122 f"hooks/{encode_path_param(id)}",
1123 method="PATCH",
1124 json={
1125 "name": name,
1126 "script": script,
1127 "enabled": enabled,
1128 "dependencies": dependencies,
1129 },
1130 headers={
1131 "content-type": "application/json",
1132 },
1133 request_options=request_options,
1134 omit=OMIT,
1135 )
1136 try:
1137 if 200 <= _response.status_code < 300:
1138 _data = typing.cast(
1139 UpdateHookResponseContent,
1140 parse_obj_as(
1141 type_=UpdateHookResponseContent, # type: ignore
1142 object_=_response.json(),
1143 ),
1144 )
1145 return AsyncHttpResponse(response=_response, data=_data)
1146 if _response.status_code == 400:
1147 raise BadRequestError(
1148 headers=dict(_response.headers),
1149 body=typing.cast(
1150 typing.Any,
1151 parse_obj_as(
1152 type_=typing.Any, # type: ignore
1153 object_=_response.json(),
1154 ),
1155 ),
1156 )
1157 if _response.status_code == 401:
1158 raise UnauthorizedError(
1159 headers=dict(_response.headers),
1160 body=typing.cast(
1161 typing.Any,
1162 parse_obj_as(
1163 type_=typing.Any, # type: ignore
1164 object_=_response.json(),
1165 ),
1166 ),
1167 )
1168 if _response.status_code == 403:
1169 raise ForbiddenError(
1170 headers=dict(_response.headers),
1171 body=typing.cast(
1172 typing.Any,
1173 parse_obj_as(
1174 type_=typing.Any, # type: ignore
1175 object_=_response.json(),
1176 ),
1177 ),
1178 )
1179 if _response.status_code == 404:
1180 raise NotFoundError(
1181 headers=dict(_response.headers),
1182 body=typing.cast(
1183 typing.Any,
1184 parse_obj_as(
1185 type_=typing.Any, # type: ignore
1186 object_=_response.json(),
1187 ),
1188 ),
1189 )
1190 if _response.status_code == 409:
1191 raise ConflictError(
1192 headers=dict(_response.headers),
1193 body=typing.cast(
1194 typing.Any,
1195 parse_obj_as(
1196 type_=typing.Any, # type: ignore
1197 object_=_response.json(),
1198 ),
1199 ),
1200 )
1201 if _response.status_code == 429:
1202 raise TooManyRequestsError(
1203 headers=dict(_response.headers),
1204 body=typing.cast(
1205 typing.Any,
1206 parse_obj_as(
1207 type_=typing.Any, # type: ignore
1208 object_=_response.json(),
1209 ),
1210 ),
1211 )
1212 _response_json = _response.json()
1213 except JSONDecodeError:
1214 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1215 except ValidationError as e:
1216 raise ParsingError(
1217 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1218 )
1219 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)