in resource-types/typescript-example-website-monitor/src/handlers.ts [246:273]
public async delete(
session: Optional<SessionProxy>,
request: ResourceHandlerRequest<ResourceModel>,
callbackContext: CallbackContext,
logger: LoggerProxy
): Promise<ProgressEvent> {
logger.log('request', request);
const model = new ResourceModel(request.desiredResourceState);
// The Id property, being the primary identifier, cannot be left empty.
if (!model.id) {
throw new exceptions.NotFound(this.typeName, request.logicalResourceIdentifier);
}
// Remove the synthetics monitor by calling the delete endpoint with its ID.
// https://docs.newrelic.com/docs/apis/synthetics-rest-api/monitor-examples/manage-synthetics-monitors-rest-api#delete-monitor
model.endpointRegion = model.endpointRegion || 'US';
const apiEndpoint = ApiEndpoints[model.endpointRegion as EndpointRegions];
const response: Response = await fetch(`${apiEndpoint}/v3/monitors/${model.id}`, {
method: 'DELETE',
headers: { ...Resource.DEFAULT_HEADERS, 'Api-Key': model.apiKey }
});
await this.checkResponse(response, logger, model.id);
const progress = ProgressEvent.success<ProgressEvent<ResourceModel>>();
logger.log('progress', progress);
return progress;
}