@@ -23,6 +23,7 @@ import {
2323
2424import { TypingInfo } from "./models/TypingInfo" ;
2525import { APIErrorResponse } from "./models/APIErrorResponse" ;
26+ import { Email } from "./models/Email" ;
2627import { EscalationPolicy } from "./models/EscalationPolicy" ;
2728import { EscalationPolicyCreateRequest } from "./models/EscalationPolicyCreateRequest" ;
2829import { EscalationPolicyUpdateRequest } from "./models/EscalationPolicyUpdateRequest" ;
@@ -166,6 +167,67 @@ export class OnCallApiRequestFactory extends BaseAPIRequestFactory {
166167 return requestContext ;
167168 }
168169
170+ public async createUserEmailNotificationChannel (
171+ userId : string ,
172+ body : Email ,
173+ _options ?: Configuration ,
174+ ) : Promise < RequestContext > {
175+ const _config = _options || this . configuration ;
176+
177+ // verify required parameter 'userId' is not null or undefined
178+ if ( userId === null || userId === undefined ) {
179+ throw new RequiredError ( "userId" , "createUserEmailNotificationChannel" ) ;
180+ }
181+
182+ // verify required parameter 'body' is not null or undefined
183+ if ( body === null || body === undefined ) {
184+ throw new RequiredError ( "body" , "createUserEmailNotificationChannel" ) ;
185+ }
186+
187+ // Path Params
188+ const localVarPath =
189+ "/api/v2/on-call/users/{user_id}/notification-channels/emails" . replace (
190+ "{user_id}" ,
191+ encodeURIComponent ( String ( userId ) ) ,
192+ ) ;
193+
194+ // Make Request Context
195+ const { server, overrides } = _config . getServerAndOverrides (
196+ "OnCallApi.v2.createUserEmailNotificationChannel" ,
197+ OnCallApi . operationServers ,
198+ ) ;
199+ const requestContext = server . makeRequestContext (
200+ localVarPath ,
201+ HttpMethod . POST ,
202+ overrides ,
203+ ) ;
204+ requestContext . setHeaderParam ( "Accept" , "*/*" ) ;
205+ requestContext . setHttpConfig ( _config . httpConfig ) ;
206+
207+ // Set User-Agent
208+ if ( this . userAgent ) {
209+ requestContext . setHeaderParam ( "User-Agent" , this . userAgent ) ;
210+ }
211+
212+ // Body Params
213+ const contentType = getPreferredMediaType ( [ "application/json" ] ) ;
214+ requestContext . setHeaderParam ( "Content-Type" , contentType ) ;
215+ const serializedBody = stringify (
216+ serialize ( body , TypingInfo , "Email" , "" ) ,
217+ contentType ,
218+ ) ;
219+ requestContext . setBody ( serializedBody ) ;
220+
221+ // Apply auth methods
222+ applySecurityAuthentication ( _config , requestContext , [
223+ "apiKeyAuth" ,
224+ "appKeyAuth" ,
225+ "AuthZ" ,
226+ ] ) ;
227+
228+ return requestContext ;
229+ }
230+
169231 public async deleteOnCallEscalationPolicy (
170232 policyId : string ,
171233 _options ?: Configuration ,
@@ -879,6 +941,57 @@ export class OnCallApiResponseProcessor {
879941 ) ;
880942 }
881943
944+ /**
945+ * Unwraps the actual response sent by the server from the response context and deserializes the response content
946+ * to the expected objects
947+ *
948+ * @params response Response returned by the server for a request to createUserEmailNotificationChannel
949+ * @throws ApiException if the response code was not in [200, 299]
950+ */
951+ public async createUserEmailNotificationChannel (
952+ response : ResponseContext ,
953+ ) : Promise < void > {
954+ const contentType = normalizeMediaType ( response . headers [ "content-type" ] ) ;
955+ if ( response . httpStatusCode === 201 ) {
956+ return ;
957+ }
958+ if (
959+ response . httpStatusCode === 400 ||
960+ response . httpStatusCode === 401 ||
961+ response . httpStatusCode === 403 ||
962+ response . httpStatusCode === 404 ||
963+ response . httpStatusCode === 429
964+ ) {
965+ const bodyText = parse ( await response . body . text ( ) , contentType ) ;
966+ let body : APIErrorResponse ;
967+ try {
968+ body = deserialize (
969+ bodyText ,
970+ TypingInfo ,
971+ "APIErrorResponse" ,
972+ ) as APIErrorResponse ;
973+ } catch ( error ) {
974+ logger . debug ( `Got error deserializing error: ${ error } ` ) ;
975+ throw new ApiException < APIErrorResponse > (
976+ response . httpStatusCode ,
977+ bodyText ,
978+ ) ;
979+ }
980+ throw new ApiException < APIErrorResponse > ( response . httpStatusCode , body ) ;
981+ }
982+
983+ // Work around for missing responses in specification, e.g. for petstore.yaml
984+ if ( response . httpStatusCode >= 200 && response . httpStatusCode <= 299 ) {
985+ return ;
986+ }
987+
988+ const body = ( await response . body . text ( ) ) || "" ;
989+ throw new ApiException < string > (
990+ response . httpStatusCode ,
991+ 'Unknown API Status Code!\nBody: "' + body + '"' ,
992+ ) ;
993+ }
994+
882995 /**
883996 * Unwraps the actual response sent by the server from the response context and deserializes the response content
884997 * to the expected objects
@@ -1483,6 +1596,18 @@ export interface OnCallApiCreateOnCallScheduleRequest {
14831596 include ?: string ;
14841597}
14851598
1599+ export interface OnCallApiCreateUserEmailNotificationChannelRequest {
1600+ /**
1601+ * The user ID
1602+ * @type string
1603+ */
1604+ userId : string ;
1605+ /**
1606+ * @type Email
1607+ */
1608+ body : Email ;
1609+ }
1610+
14861611export interface OnCallApiDeleteOnCallEscalationPolicyRequest {
14871612 /**
14881613 * The ID of the escalation policy
@@ -1686,6 +1811,31 @@ export class OnCallApi {
16861811 } ) ;
16871812 }
16881813
1814+ /**
1815+ * Create a new email notification channel for an on-call user
1816+ * @param param The request object
1817+ */
1818+ public createUserEmailNotificationChannel (
1819+ param : OnCallApiCreateUserEmailNotificationChannelRequest ,
1820+ options ?: Configuration ,
1821+ ) : Promise < void > {
1822+ const requestContextPromise =
1823+ this . requestFactory . createUserEmailNotificationChannel (
1824+ param . userId ,
1825+ param . body ,
1826+ options ,
1827+ ) ;
1828+ return requestContextPromise . then ( ( requestContext ) => {
1829+ return this . configuration . httpApi
1830+ . send ( requestContext )
1831+ . then ( ( responseContext ) => {
1832+ return this . responseProcessor . createUserEmailNotificationChannel (
1833+ responseContext ,
1834+ ) ;
1835+ } ) ;
1836+ } ) ;
1837+ }
1838+
16891839 /**
16901840 * Delete an On-Call escalation policy
16911841 * @param param The request object
0 commit comments