Debian Codegraph @

src/auth0/management/user_attribute_profiles/raw_client.py

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