@@ -135,6 +135,94 @@ def list_alert_comments(self, alert_id: str, limit: int = 10,
135135 "offset" : offset
136136 }
137137
138+ # TEAMS
139+ # ======
140+
141+ def create_team (
142+ self ,
143+ name : str ,
144+ notes : Optional [str ] = None ,
145+ member_account_user_ids : Optional [List [str ]] = None ,
146+ admin_account_user_ids : Optional [List [str ]] = None
147+ ) -> Dict [str , Any ]:
148+ """Create a new team in PagerTree."""
149+ payload = {
150+ "name" : name ,
151+ "notes" : notes ,
152+ "member_account_user_ids" : member_account_user_ids or [],
153+ "admin_account_user_ids" : admin_account_user_ids or []
154+ }
155+ payload = {k : v for k , v in payload .items () if v is not None }
156+ response = self .session .post (f"{ self .base_url } /teams" , json = payload )
157+ response .raise_for_status ()
158+ return response .json ()
159+
160+ def list_teams (self , limit : int = 10 , offset : int = 0 , search : Optional [str ] = None ) -> Dict [str , Any ]:
161+ """List all teams in PagerTree."""
162+ params = {k : v for k , v in {"limit" : limit , "offset" : offset , "q" : search }.items () if v is not None }
163+ response = self .session .get (f"{ self .base_url } /teams" , params = params )
164+ response .raise_for_status ()
165+ data = response .json ()
166+ return {
167+ "data" : data .get ("data" , []),
168+ "total" : data .get ("total_count" , 0 ),
169+ "has_more" : data .get ("has_more" , False ),
170+ "limit" : limit ,
171+ "offset" : offset
172+ }
173+
174+ def show_team (self , team_id : str ) -> Dict [str , Any ]:
175+ """Fetch a single team by ID from PagerTree."""
176+ response = self .session .get (f"{ self .base_url } /teams/{ team_id } " )
177+ response .raise_for_status ()
178+ return response .json ()
179+
180+ def update_team (
181+ self ,
182+ team_id : str ,
183+ name : Optional [str ] = None ,
184+ notes : Optional [str ] = None ,
185+ member_account_user_ids : Optional [List [str ]] = None ,
186+ admin_account_user_ids : Optional [List [str ]] = None
187+ ) -> Dict [str , Any ]:
188+ """Update a team in PagerTree."""
189+ payload = {
190+ "name" : name ,
191+ "notes" : notes ,
192+ "member_account_user_ids" : member_account_user_ids ,
193+ "admin_account_user_ids" : admin_account_user_ids
194+ }
195+ payload = {k : v for k , v in payload .items () if v is not None }
196+ response = self .session .put (f"{ self .base_url } /teams/{ team_id } " , json = payload )
197+ response .raise_for_status ()
198+ return response .json ()
199+
200+ def delete_team (self , team_id : str ) -> Dict [str , Any ]:
201+ """Delete a team in PagerTree."""
202+ response = self .session .delete (f"{ self .base_url } /teams/{ team_id } " )
203+ response .raise_for_status ()
204+ return response .json () if response .content else {"message" : "Team deleted successfully" }
205+
206+ def get_team_current_oncall (self , team_id : str ) -> Dict [str , Any ]:
207+ """Fetch current on-call users for a team in PagerTree."""
208+ response = self .session .get (f"{ self .base_url } /teams/{ team_id } /current_oncall" )
209+ response .raise_for_status ()
210+ return response .json ()
211+
212+ def get_team_alerts (self , team_id : str , limit : int = 10 , offset : int = 0 ) -> Dict [str , Any ]:
213+ """Fetch alerts for a specific team in PagerTree."""
214+ params = {k : v for k , v in {"limit" : limit , "offset" : offset }.items () if v is not None }
215+ response = self .session .get (f"{ self .base_url } /teams/{ team_id } /alerts" , params = params )
216+ response .raise_for_status ()
217+ data = response .json ()
218+ return {
219+ "data" : data .get ("data" , []),
220+ "total" : data .get ("total_count" , 0 ),
221+ "has_more" : data .get ("has_more" , False ),
222+ "limit" : limit ,
223+ "offset" : offset
224+ }
225+
138226 # USERS
139227 # ======
140228
0 commit comments