github.com/newrelic/newrelic-client-go@v1.1.0/pkg/notifications/notifications_api.go (about)

     1  // Code generated by tutone: DO NOT EDIT
     2  package notifications
     3  
     4  import (
     5  	"context"
     6  
     7  	"github.com/newrelic/newrelic-client-go/pkg/ai"
     8  )
     9  
    10  // Create a Channel
    11  func (a *Notifications) AiNotificationsCreateChannel(
    12  	accountID int,
    13  	channel AiNotificationsChannelInput,
    14  ) (*AiNotificationsChannelResponse, error) {
    15  	return a.AiNotificationsCreateChannelWithContext(context.Background(),
    16  		accountID,
    17  		channel,
    18  	)
    19  }
    20  
    21  // Create a Channel
    22  func (a *Notifications) AiNotificationsCreateChannelWithContext(
    23  	ctx context.Context,
    24  	accountID int,
    25  	channel AiNotificationsChannelInput,
    26  ) (*AiNotificationsChannelResponse, error) {
    27  
    28  	resp := AiNotificationsCreateChannelQueryResponse{}
    29  	vars := map[string]interface{}{
    30  		"accountId": accountID,
    31  		"channel":   channel,
    32  	}
    33  
    34  	if err := a.client.NerdGraphQueryWithContext(ctx, AiNotificationsCreateChannelMutation, vars, &resp); err != nil {
    35  		return nil, err
    36  	}
    37  
    38  	return &resp.AiNotificationsChannelResponse, nil
    39  }
    40  
    41  type AiNotificationsCreateChannelQueryResponse struct {
    42  	AiNotificationsChannelResponse AiNotificationsChannelResponse `json:"AiNotificationsCreateChannel"`
    43  }
    44  
    45  const AiNotificationsCreateChannelMutation = `mutation(
    46  	$accountId: Int!,
    47  	$channel: AiNotificationsChannelInput!,
    48  ) { aiNotificationsCreateChannel(
    49  	accountId: $accountId,
    50  	channel: $channel,
    51  ) {
    52  	channel {
    53  		accountId
    54  		active
    55  		createdAt
    56  		destinationId
    57  		id
    58  		name
    59  		product
    60  		properties {
    61  			displayValue
    62  			key
    63  			label
    64  			value
    65  		}
    66  		status
    67  		type
    68  		updatedAt
    69  		updatedBy
    70  	}
    71      error {
    72        ... on AiNotificationsConstraintsError {
    73          constraints {
    74            dependencies
    75            name
    76          }
    77        }
    78        ... on AiNotificationsDataValidationError {
    79          details
    80          fields {
    81            field
    82            message
    83          }
    84        }
    85        ... on AiNotificationsSuggestionError {
    86          description
    87          details
    88          type
    89        }
    90        ... on AiNotificationsResponseError {
    91          description
    92          details
    93          type
    94        }
    95      }
    96      errors {
    97        ... on AiNotificationsSuggestionError {
    98          description
    99          type
   100          details
   101        }
   102        ... on AiNotificationsResponseError {
   103          description
   104          type
   105          details
   106        }
   107        ... on AiNotificationsDataValidationError {
   108          details
   109          fields {
   110            message
   111            field
   112          }
   113        }
   114        ... on AiNotificationsConstraintsError {
   115          constraints {
   116            dependencies
   117            name
   118          }
   119        }
   120      }
   121  } }`
   122  
   123  // Create a Destination
   124  func (a *Notifications) AiNotificationsCreateDestination(
   125  	accountID int,
   126  	destination AiNotificationsDestinationInput,
   127  ) (*AiNotificationsDestinationResponse, error) {
   128  	return a.AiNotificationsCreateDestinationWithContext(context.Background(),
   129  		accountID,
   130  		destination,
   131  	)
   132  }
   133  
   134  // Create a Destination
   135  func (a *Notifications) AiNotificationsCreateDestinationWithContext(
   136  	ctx context.Context,
   137  	accountID int,
   138  	destination AiNotificationsDestinationInput,
   139  ) (*AiNotificationsDestinationResponse, error) {
   140  
   141  	resp := AiNotificationsCreateDestinationQueryResponse{}
   142  	vars := map[string]interface{}{
   143  		"accountId":   accountID,
   144  		"destination": destination,
   145  	}
   146  
   147  	if err := a.client.NerdGraphQueryWithContext(ctx, AiNotificationsCreateDestinationMutation, vars, &resp); err != nil {
   148  		return nil, err
   149  	}
   150  
   151  	return &resp.AiNotificationsDestinationResponse, nil
   152  }
   153  
   154  type AiNotificationsCreateDestinationQueryResponse struct {
   155  	AiNotificationsDestinationResponse AiNotificationsDestinationResponse `json:"AiNotificationsCreateDestination"`
   156  }
   157  
   158  const AiNotificationsCreateDestinationMutation = `mutation(
   159  	$accountId: Int!,
   160  	$destination: AiNotificationsDestinationInput!,
   161  ) { aiNotificationsCreateDestination(
   162  	accountId: $accountId,
   163  	destination: $destination,
   164  ) {
   165  	destination {
   166  		accountId
   167  		active
   168  		auth {
   169  			... on AiNotificationsBasicAuth {
   170  			  authType
   171  			  user
   172  			}
   173  			... on AiNotificationsOAuth2Auth {
   174  			  accessTokenUrl
   175  			  scope
   176  			  refreshable
   177  			  refreshInterval
   178  			  prefix
   179  			  clientId
   180  			  authorizationUrl
   181  			  authType
   182  			}
   183  			... on AiNotificationsTokenAuth {
   184  			  authType
   185  			  prefix
   186  			}
   187  		}
   188  		createdAt
   189  		id
   190  		isUserAuthenticated
   191  		lastSent
   192  		name
   193  		properties {
   194  			displayValue
   195  			key
   196  			label
   197  			value
   198  		}
   199  		status
   200  		type
   201  		updatedAt
   202  		updatedBy
   203  	}
   204  	errors {
   205        ... on AiNotificationsConstraintsError {
   206          constraints {
   207            dependencies
   208            name
   209          }
   210        }
   211        ... on AiNotificationsDataValidationError {
   212          details
   213          fields {
   214            field
   215            message
   216          }
   217        }
   218        ... on AiNotificationsResponseError {
   219          description
   220          details
   221          type
   222        }
   223        ... on AiNotificationsSuggestionError {
   224          description
   225          type
   226          details
   227        }
   228      }
   229      error {
   230        ... on AiNotificationsSuggestionError {
   231          description
   232          type
   233          details
   234        }
   235        ... on AiNotificationsResponseError {
   236          description
   237          type
   238          details
   239        }
   240        ... on AiNotificationsDataValidationError {
   241          details
   242          fields {
   243            message
   244            field
   245          }
   246        }
   247        ... on AiNotificationsConstraintsError {
   248          constraints {
   249            name
   250            dependencies
   251          }
   252        }
   253      }
   254  } }`
   255  
   256  // Delete a Channel
   257  func (a *Notifications) AiNotificationsDeleteChannel(
   258  	accountID int,
   259  	channelId string,
   260  ) (*AiNotificationsDeleteResponse, error) {
   261  	return a.AiNotificationsDeleteChannelWithContext(context.Background(),
   262  		accountID,
   263  		channelId,
   264  	)
   265  }
   266  
   267  // Delete a Channel
   268  func (a *Notifications) AiNotificationsDeleteChannelWithContext(
   269  	ctx context.Context,
   270  	accountID int,
   271  	channelId string,
   272  ) (*AiNotificationsDeleteResponse, error) {
   273  
   274  	resp := AiNotificationsDeleteChannelQueryResponse{}
   275  	vars := map[string]interface{}{
   276  		"accountId": accountID,
   277  		"channelId": channelId,
   278  	}
   279  
   280  	if err := a.client.NerdGraphQueryWithContext(ctx, AiNotificationsDeleteChannelMutation, vars, &resp); err != nil {
   281  		return nil, err
   282  	}
   283  
   284  	return &resp.AiNotificationsDeleteResponse, nil
   285  }
   286  
   287  type AiNotificationsDeleteChannelQueryResponse struct {
   288  	AiNotificationsDeleteResponse AiNotificationsDeleteResponse `json:"AiNotificationsDeleteChannel"`
   289  }
   290  
   291  const AiNotificationsDeleteChannelMutation = `mutation(
   292  	$accountId: Int!,
   293  	$channelId: ID!,
   294  ) { aiNotificationsDeleteChannel(
   295  	accountId: $accountId,
   296  	channelId: $channelId,
   297  ) {
   298  	error {
   299  		description
   300  		details
   301  		type
   302  	}
   303  	errors {
   304  		description
   305  		details
   306  		type
   307  	}
   308  	ids
   309  } }`
   310  
   311  // Delete a Destination
   312  func (a *Notifications) AiNotificationsDeleteDestination(
   313  	accountID int,
   314  	destinationId string,
   315  ) (*AiNotificationsDeleteResponse, error) {
   316  	return a.AiNotificationsDeleteDestinationWithContext(context.Background(),
   317  		accountID,
   318  		destinationId,
   319  	)
   320  }
   321  
   322  // Delete a Destination
   323  func (a *Notifications) AiNotificationsDeleteDestinationWithContext(
   324  	ctx context.Context,
   325  	accountID int,
   326  	destinationId string,
   327  ) (*AiNotificationsDeleteResponse, error) {
   328  
   329  	resp := AiNotificationsDeleteDestinationQueryResponse{}
   330  	vars := map[string]interface{}{
   331  		"accountId":     accountID,
   332  		"destinationId": destinationId,
   333  	}
   334  
   335  	if err := a.client.NerdGraphQueryWithContext(ctx, AiNotificationsDeleteDestinationMutation, vars, &resp); err != nil {
   336  		return nil, err
   337  	}
   338  
   339  	return &resp.AiNotificationsDeleteResponse, nil
   340  }
   341  
   342  type AiNotificationsDeleteDestinationQueryResponse struct {
   343  	AiNotificationsDeleteResponse AiNotificationsDeleteResponse `json:"AiNotificationsDeleteDestination"`
   344  }
   345  
   346  const AiNotificationsDeleteDestinationMutation = `mutation(
   347  	$accountId: Int!,
   348  	$destinationId: ID!,
   349  ) { aiNotificationsDeleteDestination(
   350  	accountId: $accountId,
   351  	destinationId: $destinationId,
   352  ) {
   353  	error {
   354  		description
   355  		details
   356  		type
   357  	}
   358  	errors {
   359  		description
   360  		details
   361  		type
   362  	}
   363  	ids
   364  } }`
   365  
   366  // Update a Channel
   367  func (a *Notifications) AiNotificationsUpdateChannel(
   368  	accountID int,
   369  	channel AiNotificationsChannelUpdate,
   370  	channelId string,
   371  ) (*AiNotificationsChannelResponse, error) {
   372  	return a.AiNotificationsUpdateChannelWithContext(context.Background(),
   373  		accountID,
   374  		channel,
   375  		channelId,
   376  	)
   377  }
   378  
   379  // Update a Channel
   380  func (a *Notifications) AiNotificationsUpdateChannelWithContext(
   381  	ctx context.Context,
   382  	accountID int,
   383  	channel AiNotificationsChannelUpdate,
   384  	channelId string,
   385  ) (*AiNotificationsChannelResponse, error) {
   386  
   387  	resp := AiNotificationsUpdateChannelQueryResponse{}
   388  	vars := map[string]interface{}{
   389  		"accountId": accountID,
   390  		"channel":   channel,
   391  		"channelId": channelId,
   392  	}
   393  
   394  	if err := a.client.NerdGraphQueryWithContext(ctx, AiNotificationsUpdateChannelMutation, vars, &resp); err != nil {
   395  		return nil, err
   396  	}
   397  
   398  	return &resp.AiNotificationsChannelResponse, nil
   399  }
   400  
   401  type AiNotificationsUpdateChannelQueryResponse struct {
   402  	AiNotificationsChannelResponse AiNotificationsChannelResponse `json:"AiNotificationsUpdateChannel"`
   403  }
   404  
   405  const AiNotificationsUpdateChannelMutation = `mutation(
   406  	$accountId: Int!,
   407  	$channel: AiNotificationsChannelUpdate!,
   408  	$channelId: ID!,
   409  ) { aiNotificationsUpdateChannel(
   410  	accountId: $accountId,
   411  	channel: $channel,
   412  	channelId: $channelId,
   413  ) {
   414  	channel {
   415  		accountId
   416  		active
   417  		createdAt
   418  		destinationId
   419  		id
   420  		name
   421  		product
   422  		properties {
   423  			displayValue
   424  			key
   425  			label
   426  			value
   427  		}
   428  		status
   429  		type
   430  		updatedAt
   431  		updatedBy
   432  	}
   433      error {
   434        ... on AiNotificationsConstraintsError {
   435          constraints {
   436            dependencies
   437            name
   438          }
   439        }
   440        ... on AiNotificationsDataValidationError {
   441          details
   442          fields {
   443            field
   444            message
   445          }
   446        }
   447        ... on AiNotificationsSuggestionError {
   448          description
   449          details
   450          type
   451        }
   452        ... on AiNotificationsResponseError {
   453          description
   454          details
   455          type
   456        }
   457      }
   458      errors {
   459        ... on AiNotificationsSuggestionError {
   460          description
   461          type
   462          details
   463        }
   464        ... on AiNotificationsResponseError {
   465          description
   466          type
   467          details
   468        }
   469        ... on AiNotificationsDataValidationError {
   470          details
   471          fields {
   472            message
   473            field
   474          }
   475        }
   476        ... on AiNotificationsConstraintsError {
   477          constraints {
   478            dependencies
   479            name
   480          }
   481        }
   482      }
   483  } }`
   484  
   485  // Update a Destination
   486  func (a *Notifications) AiNotificationsUpdateDestination(
   487  	accountID int,
   488  	destination AiNotificationsDestinationUpdate,
   489  	destinationId string,
   490  ) (*AiNotificationsDestinationResponse, error) {
   491  	return a.AiNotificationsUpdateDestinationWithContext(context.Background(),
   492  		accountID,
   493  		destination,
   494  		destinationId,
   495  	)
   496  }
   497  
   498  // Update a Destination
   499  func (a *Notifications) AiNotificationsUpdateDestinationWithContext(
   500  	ctx context.Context,
   501  	accountID int,
   502  	destination AiNotificationsDestinationUpdate,
   503  	destinationId string,
   504  ) (*AiNotificationsDestinationResponse, error) {
   505  
   506  	resp := AiNotificationsUpdateDestinationQueryResponse{}
   507  	vars := map[string]interface{}{
   508  		"accountId":     accountID,
   509  		"destination":   destination,
   510  		"destinationId": destinationId,
   511  	}
   512  
   513  	if err := a.client.NerdGraphQueryWithContext(ctx, AiNotificationsUpdateDestinationMutation, vars, &resp); err != nil {
   514  		return nil, err
   515  	}
   516  
   517  	return &resp.AiNotificationsDestinationResponse, nil
   518  }
   519  
   520  type AiNotificationsUpdateDestinationQueryResponse struct {
   521  	AiNotificationsDestinationResponse AiNotificationsDestinationResponse `json:"AiNotificationsUpdateDestination"`
   522  }
   523  
   524  const AiNotificationsUpdateDestinationMutation = `mutation(
   525  	$accountId: Int!,
   526  	$destination: AiNotificationsDestinationUpdate!,
   527  	$destinationId: ID!,
   528  ) { aiNotificationsUpdateDestination(
   529  	accountId: $accountId,
   530  	destination: $destination,
   531  	destinationId: $destinationId,
   532  ) {
   533  	destination {
   534  		accountId
   535  		active
   536  		auth {
   537  			... on AiNotificationsBasicAuth {
   538  			  authType
   539  			  user
   540  			}
   541  			... on AiNotificationsOAuth2Auth {
   542  			  accessTokenUrl
   543  			  scope
   544  			  refreshable
   545  			  refreshInterval
   546  			  prefix
   547  			  clientId
   548  			  authorizationUrl
   549  			  authType
   550  			}
   551  			... on AiNotificationsTokenAuth {
   552  			  authType
   553  			  prefix
   554  			}
   555  		}
   556  		createdAt
   557  		id
   558  		isUserAuthenticated
   559  		lastSent
   560  		name
   561  		properties {
   562  			displayValue
   563  			key
   564  			label
   565  			value
   566  		}
   567  		status
   568  		type
   569  		updatedAt
   570  		updatedBy
   571  	}
   572  	errors {
   573        ... on AiNotificationsConstraintsError {
   574          constraints {
   575            dependencies
   576            name
   577          }
   578        }
   579        ... on AiNotificationsDataValidationError {
   580          details
   581          fields {
   582            field
   583            message
   584          }
   585        }
   586        ... on AiNotificationsResponseError {
   587          description
   588          details
   589          type
   590        }
   591        ... on AiNotificationsSuggestionError {
   592          description
   593          type
   594          details
   595        }
   596      }
   597      error {
   598        ... on AiNotificationsSuggestionError {
   599          description
   600          type
   601          details
   602        }
   603        ... on AiNotificationsResponseError {
   604          description
   605          type
   606          details
   607        }
   608        ... on AiNotificationsDataValidationError {
   609          details
   610          fields {
   611            message
   612            field
   613          }
   614        }
   615        ... on AiNotificationsConstraintsError {
   616          constraints {
   617            name
   618            dependencies
   619          }
   620        }
   621      }
   622  } }`
   623  
   624  // Fetch a Channel by product
   625  func (a *Notifications) GetChannels(
   626  	accountID int,
   627  	cursor string,
   628  	filters ai.AiNotificationsChannelFilter,
   629  	sorter AiNotificationsChannelSorter,
   630  ) (*AiNotificationsChannelsResponse, error) {
   631  	return a.GetChannelsWithContext(context.Background(),
   632  		accountID,
   633  		cursor,
   634  		filters,
   635  		sorter,
   636  	)
   637  }
   638  
   639  // Fetch a Channel by product
   640  func (a *Notifications) GetChannelsWithContext(
   641  	ctx context.Context,
   642  	accountID int,
   643  	cursor string,
   644  	filters ai.AiNotificationsChannelFilter,
   645  	sorter AiNotificationsChannelSorter,
   646  ) (*AiNotificationsChannelsResponse, error) {
   647  
   648  	resp := channelsResponse{}
   649  	vars := map[string]interface{}{
   650  		"accountID": accountID,
   651  		"cursor":    cursor,
   652  		"filters":   filters,
   653  		"sorter":    sorter,
   654  	}
   655  
   656  	if err := a.client.NerdGraphQueryWithContext(ctx, getChannelsQuery, vars, &resp); err != nil {
   657  		return nil, err
   658  	}
   659  
   660  	return &resp.Actor.Account.AiNotifications.Channels, nil
   661  }
   662  
   663  const getChannelsQuery = `query(
   664  	$accountID: Int!, $filters: AiNotificationsChannelFilter,
   665  ) { actor { account(id: $accountID) { aiNotifications { channels(filters: $filters) {
   666  	entities {
   667  		accountId
   668  		active
   669  		createdAt
   670  		destinationId
   671  		id
   672  		name
   673  		product
   674  		properties {
   675  			displayValue
   676  			key
   677  			label
   678  			value
   679  		}
   680  		status
   681  		type
   682  		updatedAt
   683  		updatedBy
   684  	}
   685  	error {
   686  		description
   687  		details
   688  		type
   689  	}
   690  	errors {
   691  		description
   692  		details
   693  		type
   694  	}
   695  	nextCursor
   696  	totalCount
   697  } } } } }`
   698  
   699  // Fetch a Destinations by type
   700  func (a *Notifications) GetDestinations(
   701  	accountID int,
   702  	cursor string,
   703  	filters ai.AiNotificationsDestinationFilter,
   704  	sorter AiNotificationsDestinationSorter,
   705  ) (*AiNotificationsDestinationsResponse, error) {
   706  	return a.GetDestinationsWithContext(context.Background(),
   707  		accountID,
   708  		cursor,
   709  		filters,
   710  		sorter,
   711  	)
   712  }
   713  
   714  // Fetch a Destinations by type
   715  func (a *Notifications) GetDestinationsWithContext(
   716  	ctx context.Context,
   717  	accountID int,
   718  	cursor string,
   719  	filters ai.AiNotificationsDestinationFilter,
   720  	sorter AiNotificationsDestinationSorter,
   721  ) (*AiNotificationsDestinationsResponse, error) {
   722  
   723  	resp := destinationsResponse{}
   724  	vars := map[string]interface{}{
   725  		"accountID": accountID,
   726  		"cursor":    cursor,
   727  		"filters":   filters,
   728  		"sorter":    sorter,
   729  	}
   730  
   731  	if err := a.client.NerdGraphQueryWithContext(ctx, getDestinationsQuery, vars, &resp); err != nil {
   732  		return nil, err
   733  	}
   734  
   735  	return &resp.Actor.Account.AiNotifications.Destinations, nil
   736  }
   737  
   738  const getDestinationsQuery = `query(
   739  	$accountID: Int!, $filters: AiNotificationsDestinationFilter,
   740  ) { actor { account(id: $accountID) { aiNotifications { destinations(filters: $filters) {
   741  	entities {
   742  		accountId
   743  		active
   744  		auth {
   745  			... on AiNotificationsBasicAuth {
   746  			  authType
   747  			  user
   748  			}
   749  			... on AiNotificationsOAuth2Auth {
   750  			  accessTokenUrl
   751  			  scope
   752  			  refreshable
   753  			  refreshInterval
   754  			  prefix
   755  			  clientId
   756  			  authorizationUrl
   757  			  authType
   758  			}
   759  			... on AiNotificationsTokenAuth {
   760  			  authType
   761  			  prefix
   762  			}
   763  		}
   764  		createdAt
   765  		id
   766  		isUserAuthenticated
   767  		lastSent
   768  		name
   769  		properties {
   770  			displayValue
   771  			key
   772  			label
   773  			value
   774  		}
   775  		status
   776  		type
   777  		updatedAt
   778  		updatedBy
   779  	}
   780  	error {
   781  		description
   782  		details
   783  		type
   784  	}
   785  	errors {
   786  		description
   787  		details
   788  		type
   789  	}
   790  	nextCursor
   791  	totalCount
   792  } } } } }`