# Managed API for Opsgenie
Managed API for Opsgenie is an API Client for Opsgenie by [Adaptavist](https://www.adaptavist.com/) primarily designed for the use in [ScriptRunner Connect](https://scriptrunnerconnect.com). You can read more about Managed APIs [here](https://docs.adaptavist.com/src/managed-apis).

This is a runtime agnostic version of the Managed API (with `core` suffix) that makes it easy to port it to any runtime you may want to use this Managed API on.

# Platform specific ports
- [ScriptRunner Connect](https://www.npmjs.com/package/@managed-api/opsgenie-sr-connect)

# Supported API calls
- [fetch](https://docs.adaptavist.com/src/managed-apis/managed-api-abstractions)
- Alert
    - [acknowledgeAlert](https://docs.opsgenie.com/docs/alert-api#acknowledge-alert)
    - [addResponder](https://docs.opsgenie.com/docs/alert-api#add-responder-to-alert)
    - [addTeam](https://docs.opsgenie.com/docs/alert-api#add-team-to-alert)
    - [assignAlert](https://docs.opsgenie.com/docs/alert-api#assign-alert)
    - [closeAlert](https://docs.opsgenie.com/docs/alert-api#close-alert)
    - [countAlerts](https://docs.opsgenie.com/docs/alert-api#count-alerts)
    - [createAlert](https://docs.opsgenie.com/docs/alert-api#create-alert)
    - [deleteAlert](https://docs.opsgenie.com/docs/alert-api#delete-alert)
    - [escalateAlertToNext](https://docs.opsgenie.com/docs/alert-api#escalate-alert-to-next)
    - [executeCustomAction](https://docs.opsgenie.com/docs/alert-api#execute-custom-action)
    - [getAlert](https://docs.opsgenie.com/docs/alert-api#get-alert)
    - [getAlerts](https://docs.opsgenie.com/docs/alert-api#list-alerts)
    - [getLogs](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-logs)
    - [getRecipients](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-recipients)
    - [getRequestStatus](https://docs.opsgenie.com/docs/alert-api#get-request-status)
    - [snoozeAlert](https://docs.opsgenie.com/docs/alert-api#snooze-alert)
    - [unacknowledgeAlert](https://docs.opsgenie.com/docs/alert-api#unacknowledge-alert)
    - [updateDescription](https://docs.opsgenie.com/docs/alert-api-continued#update-alert-description)
    - [updateMessage](https://docs.opsgenie.com/docs/alert-api-continued#update-alert-message)
    - [updatePriority](https://docs.opsgenie.com/docs/alert-api-continued#update-alert-priority)
    - Attachment
        - [createAttachment](https://docs.opsgenie.com/docs/alert-api-continued#create-alert-attachment)
        - [deleteAttachment](https://docs.opsgenie.com/docs/alert-api-continued#delete-alert-attachment)
        - [getAttachment](https://docs.opsgenie.com/docs/alert-api-continued#get-alert-attachment)
        - [getAttachments](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-attachments)
    - Details
        - [addDetails](https://docs.opsgenie.com/docs/alert-api-continued#add-details-custom-properties-to-alert)
        - [removeDetails](https://docs.opsgenie.com/docs/alert-api-continued#remove-details-custom-properties-from-alert)
    - Note
        - [addNote](https://docs.opsgenie.com/docs/alert-api#add-note-to-alert)
        - [getNotes](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-notes)
    - Saved
        - Search
            - [createSavedSearch](https://docs.opsgenie.com/docs/alert-api-continued#create-a-saved-search)
            - [deleteSavedSearch](https://docs.opsgenie.com/docs/alert-api-continued#delete-saved-search)
            - [getSavedSearch](https://docs.opsgenie.com/docs/alert-api-continued#get-saved-search)
            - [getSavedSearches](https://docs.opsgenie.com/docs/alert-api-continued#list-saved-searches)
            - [updateSavedSearch](https://docs.opsgenie.com/docs/alert-api-continued#update-saved-search)
    - Tags
        - [addTags](https://docs.opsgenie.com/docs/alert-api#add-tags-to-alert)
        - [removeTags](https://docs.opsgenie.com/docs/alert-api#remove-tags-from-alert)
- Incident
    - [addResponder](https://docs.opsgenie.com/docs/incident-api#add-responder-to-incident)
    - [closeIncident](https://docs.opsgenie.com/docs/incident-api#close-incident)
    - [createIncident](https://docs.opsgenie.com/docs/incident-api#create-incident)
    - [deleteIncident](https://docs.opsgenie.com/docs/incident-api#delete-incident)
    - [getIncident](https://docs.opsgenie.com/docs/incident-api#get-incident)
    - [getIncidents](https://docs.opsgenie.com/docs/incident-api#list-incidents)
    - [getLogs](https://docs.opsgenie.com/docs/incident-api#list-incident-logs)
    - [getRequestStatus](https://docs.opsgenie.com/docs/incident-api#get-request-status)
    - [reopenIncident](https://docs.opsgenie.com/docs/incident-api#reopen-incident)
    - [resolveIncident](https://docs.opsgenie.com/docs/incident-api#resolve-incident)
    - [updateDescription](https://docs.opsgenie.com/docs/incident-api#update-incident-description)
    - [updateMessage](https://docs.opsgenie.com/docs/incident-api#update-incident-message)
    - [updatePriority](https://docs.opsgenie.com/docs/incident-api#update-incident-priority)
    - Alert
        - [getAssociatedAlerts](https://docs.opsgenie.com/docs/incident-api#get-associated-alerts)
        - [getResponderAlerts](https://docs.opsgenie.com/docs/incident-api#get-responder-alerts)
    - Details
        - [addDetails](https://docs.opsgenie.com/docs/incident-api#add-detailscustom-properties-to-incident)
        - [removeDetails](https://docs.opsgenie.com/docs/incident-api#remove-detailscustom-properties-from-incident)
    - Note
        - [addNote](https://docs.opsgenie.com/docs/incident-api#add-note-to-incident)
        - [getNotes](https://docs.opsgenie.com/docs/incident-api#list-incident-notes)
    - Tags
        - [addTags](https://docs.opsgenie.com/docs/incident-api#add-tags-to-incident)
        - [removeTags](https://docs.opsgenie.com/docs/incident-api#remove-tags-from-incident)
    - Timeline
        - [addEntry](https://docs.opsgenie.com/docs/incident-timeline-api#add-incident-timeline-entry)
        - [deleteEntry](https://docs.opsgenie.com/docs/incident-timeline-api#delete-incident-timeline-entry)
        - [getEntries](https://docs.opsgenie.com/docs/incident-timeline-api#list-incident-timeline-entries)
        - [getEntry](https://docs.opsgenie.com/docs/incident-timeline-api#get-incident-timeline-entry)
        - [hideEntry](https://docs.opsgenie.com/docs/incident-timeline-api#hide-incident-timeline-entry)
        - [unhideEntry](https://docs.opsgenie.com/docs/incident-timeline-api#unhide-incident-timeline-entry)
        - [updateEntry](https://docs.opsgenie.com/docs/incident-timeline-api#update-incident-timeline-entry)


# Porting to other runtimes
While the primary reason for creating Managed APIs was to use them in [ScriptRunner Connect](https://scriptrunnerconnect.com) runtime, then you can easily port them to any runtime of your choosing.

You can do so by extending the `*Core` Managed API class where you'll be asked to provide implementation for `getPlatformImplementation` function. In this implementation you have to specify how to perform buffer encoding/decoding operations and how to perform HTTP calls:
```typescript
{
    buffer: {
        encode(input: string): ArrayBuffer;
        decode(input: ArrayBuffer): string;
    },
    performHttpCall(request: Request): Promise<Response>
}
```

Here is an example how to create a [Node](https://nodejs.org/en/) port of the Managed API:
```typescript
import { OpsgenieApiCore } from "@managed-api/opsgenie-core";
import { PlatformImplementation, Request, Response, Headers } from "@managed-api/commons-core";
import fetch from "node-fetch";

export class OpsgenieApi extends OpsgenieApiCore {
    constructor(private baseUrl: string, private authToken: string) {
        super();
    }

    protected getPlatformImplementation(): PlatformImplementation {
        return {
            buffer: {
                encode: (input) => Buffer.from(input, 'utf-8'),
                decode: (input) => Buffer.from(input).toString('utf-8')
            },
            performHttpCall: (request) => this.performHttpCall(request)
        };
    }
    
    private async performHttpCall(request: Request): Promise<Response> {
        const requestUrl = `${this.baseUrl}${request.url}`; // Substitute base URL
        request.headers.set('Authorization', `Basic ${this.authToken}`); // Substitute auth token
        const response = await fetch(requestUrl, {
            method: request.method,
            headers: request.headers as any,
            body: request.method.toLowerCase() !== 'get' ? Buffer.from((await request.arrayBuffer()) ?? new ArrayBuffer(0)) : undefined
        });

        const apiHeaders = new Headers();
        response.headers.forEach((value, key) => apiHeaders.append(key, value));

        const body = await response.arrayBuffer();

        return super.buildResponse(response.url, response.status, response.statusText, apiHeaders, body);
    }
}
```

Please note that the authentication handling details may not be accurate and serve as an example. If you wish to use these Managed APIs without having to concern yourself how to deal with and secure authentication details when working with APIs, then feel free to evaluate [ScriptRunner Connect](https://scriptrunnerconnect.com) platform.

# Contact
At this time Managed APIs are unlicensed and close sourced, but feel free to drop an email to [eknoll@adaptavist.com](mailto://eknoll@adaptavist.com) for ideas, suggestions and improvements.

 # Changelog
# 2.1.0

- Removed non-empty body from HEAD requests.

# 2.0.0

- # Breaking change: URL and query string parameters are now URL encoded, meaning if you encoded them explicitly before you have to remove your own encoding, otherwise they will get double encoded.

# 0.2.0

- # Added support for the following Alert methods:
    - [Acknowledge Alert](https://docs.opsgenie.com/docs/alert-api#acknowledge-alert) that can be used as `Alert.acknowledgeAlert` or `All.acknowledgeAlert`.
    - [Add Responder to Alert](https://docs.opsgenie.com/docs/alert-api#add-responder-to-alert) that can be used as `Alert.addResponder` or `All.addResponderToAlert`.
    - [Add Team to Alert](https://docs.opsgenie.com/docs/alert-api#add-team-to-alert) that can be used as `Alert.addTeam` or `All.addTeamToAlert`.
    - [Assign Alert](https://docs.opsgenie.com/docs/alert-api#assign-alert) that can be used as `Alert.assignAlert` or `All.assignAlert`.
    - [Close Alert](https://docs.opsgenie.com/docs/alert-api#close-alert) that can be used as `Alert.closeAlert` or `All.closeAlert`.
    - [Count Alerts](https://docs.opsgenie.com/docs/alert-api#count-alerts) that can be used as `Alert.countAlerts` or `All.countAlerts`.
    - [Create Alert](https://docs.opsgenie.com/docs/alert-api#create-alert) that can be used as `Alert.createAlert` or `All.createAlert`.
    - [Delete Alert](https://docs.opsgenie.com/docs/alert-api#delete-alert) that can be used as `Alert.deleteAlert` or `All.deleteAlert`.
    - [Escalate Alert to Next](https://docs.opsgenie.com/docs/alert-api#escalate-alert-to-next) that can be used as `Alert.escalateAlertToNext` or `All.escalateAlertToNext`.
    - [Execute Custom Action](https://docs.opsgenie.com/docs/alert-api#execute-custom-action) that can be used as `Alert.executeCustomAction` or `All.executeCustomAlertAction`.
    - [Get Alert](https://docs.opsgenie.com/docs/alert-api#get-alert) that can be used as `Alert.getAlert` or `All.getAlert`.
    - [List Alerts](https://docs.opsgenie.com/docs/alert-api#list-alerts) that can be used as `Alert.getAlerts` or `All.getAlerts`.
    - [List Alert Logs](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-logs) that can be used as `Alert.getLogs` or `All.getAlertLogs`.
    - [List Alert Recipients](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-recipients) that can be used as `Alert.getRecipient` or `All.getAlertRecipients`.
    - [List Alert Recipients](https://docs.opsgenie.com/docs/alert-api#get-request-status) that can be used as `Alert.getRequestStatus` or `All.getRequestStatusforAlert`.
    - [Snooze Alert](https://docs.opsgenie.com/docs/alert-api#snooze-alert) that can be used as `Alert.snoozeAlert` or `All.snoozeAlert`.
    - [Unacknowledge Alert](https://docs.opsgenie.com/docs/alert-api#unacknowledge-alert) that can be used as `Alert.unacknowledgeAlert` or `All.unacknowledgeAlert`.
    - [Update Alert Description](https://docs.opsgenie.com/docs/alert-api-continued#update-alert-description) that can be used as `Alert.updateDescription` or `All.updateAlertDescription`.
    - [Update Alert Message](https://docs.opsgenie.com/docs/alert-api-continued#update-alert-message) that can be used as `Alert.updateMessage` or `All.updateAlertMessage`.
    - [Update Alert Priority](https://docs.opsgenie.com/docs/alert-api-continued#update-alert-priority) that can be used as `Alert.updatePriority` or `All.updateIncidentPriority`.

- # Added support for the following Alert.Attachment methods:
    - [Create Alert Attachment](https://docs.opsgenie.com/docs/alert-api-continued#create-alert-attachment) that can be used as `Alert.Attachment.createAttachment` or `All.createAlertAttachment`.
    - [Delete Alert Attachment](https://docs.opsgenie.com/docs/alert-api-continued#delete-alert-attachment) that can be used as `Alert.Attachment.deleteAttachment` or `All.deleteAlertAttachment`.
    - [Get Alert Attachment](https://docs.opsgenie.com/docs/alert-api-continued#get-alert-attachment) that can be used as `Alert.Attachment.getAttachment` or `All.getAlertAttachment`.
    - [List Alert Attachments](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-attachments) that can be used as `Alert.Attachment.getAttachments` or `All.getAlertAttachments`.

- # Added support for the following Alert.Details methods:
    - [Add Details (Custom Properties) to Alert](https://docs.opsgenie.com/docs/alert-api-continued#add-details-custom-properties-to-alert) that can be used as `Alert.Details.addDetails` or `All.addDetailsToAlert`.
    - [Remove Details (Custom Properties) from Alert](https://docs.opsgenie.com/docs/alert-api-continued#remove-details-custom-properties-from-alert) that can be used as `Alert.Details.removeDetails` or `All.removeDetailsFromAlert`.

- # Added support for the following Alert.Note methods:
    - [Add Note to Alert](https://docs.opsgenie.com/docs/alert-api#add-note-to-alert) that can be used as `Alert.Note.addNote` or `All.addNoteToAlert`.
    - [List Alert Notes](https://docs.opsgenie.com/docs/alert-api-continued#list-alert-notes) that can be used as `Alert.Note.getNote` or `All.getAlertNotes`.

- # Added support for the following Alert.Saved.Search methods:
    - [Create a Saved Search](https://docs.opsgenie.com/docs/alert-api-continued#create-a-saved-search) that can be used as `Alert.Saved.Search.createSavedSearch` or `All.createSavedSearchForAlert`.
    - [Delete Saved Search](https://docs.opsgenie.com/docs/alert-api-continued#delete-saved-search) that can be used as `Alert.Saved.Search.deleteSavedSearch` or `All.deleteSavedSearchForAlert`.
    - [Get Saved Search](https://docs.opsgenie.com/docs/alert-api-continued#get-saved-search) that can be used as `Alert.Saved.Search.getSavedSearch` or `All.getSavedSearchForAlert`.
    - [List Saved Searches](https://docs.opsgenie.com/docs/alert-api-continued#list-saved-searches) that can be used as `Alert.Saved.Search.getSavedSearches` or `All.getSavedSearchesForAlert`.
    - [Update Saved Search](https://docs.opsgenie.com/docs/alert-api-continued#update-saved-search) that can be used as `Alert.Saved.Search.updateSavedSearch` or `All.updateSavedSearchForAlert`.

- # Added support for the following Alert.Tags methods:
    - [Add Tags to Alert](https://docs.opsgenie.com/docs/alert-api#add-tags-to-alert) that can be used as `Alert.Tags.addTags` or `All.addTagsToAlert`.
    - [Remove Tags from Alert](https://docs.opsgenie.com/docs/alert-api#remove-tags-from-alert) that can be used as `Alert.Tags.removeTags` or `All.removeTagsFromAlert`.

- # Added support for the following Incident methods:
    - [Add Responder to Incident](https://docs.opsgenie.com/docs/incident-api#add-responder-to-incident) that can be used as `Incident.addResponder` or `All.addResponderToIncident`.
    - [Close Incident](https://docs.opsgenie.com/docs/incident-api#close-incident) that can be used as `Incident.closeIncident` or `All.closeIncident`.
    - [Create Incident](https://docs.opsgenie.com/docs/incident-api#create-incident) that can be used as `Incident.createIncident` or `All.createIncident`.
    - [Delete Incident](https://docs.opsgenie.com/docs/incident-api#delete-incident) that can be used as `Incident.deleteIncident` or `All.deleteIncident`.
    - [Get Incident](https://docs.opsgenie.com/docs/incident-api#get-incident) that can be used as `Incident.getIncident` or `All.getIncident`.
    - [List Incidents](https://docs.opsgenie.com/docs/incident-api#list-incidents) that can be used as `Incident.getIncidenst` or `All.getIncidents`.
    - [List Incident Logs](https://docs.opsgenie.com/docs/incident-api#list-incident-logs) that can be used as `Incident.getLogs` or `All.getIncidentLogs`.
    - [Get Request Status](https://docs.opsgenie.com/docs/incident-api#get-request-status) that can be used as `Incident.getRequestStatus` or `All.getRequestStatusForIncident`.
    - [Reopen Incident](https://docs.opsgenie.com/docs/incident-api#reopen-incident) that can be used as `Incident.reopenIncident` or `All.reopenIncident`.
    - [Resolve Incident](https://docs.opsgenie.com/docs/incident-api#resolve-incident) that can be used as `Incident.resolveIncident` or `All.resolveIncident`.
    - [Update Incident Description](https://docs.opsgenie.com/docs/incident-api#update-incident-description) that can be used as `Incident.updateDescription` or `All.updateIncidentDescription`.
    - [Update Incident Message](https://docs.opsgenie.com/docs/incident-api#update-incident-message) that can be used as `Incident.updateMessage` or `All.updateIncidentMessage`.
    - [Update Incident Priority](https://docs.opsgenie.com/docs/incident-api#update-incident-priority) that can be used as `Incident.updatePriority` or `All.updateIncidentPriority`.

- # Added support for the following Incident.Alert methods:
    - [Get Associated Alerts](https://docs.opsgenie.com/docs/incident-api#get-associated-alerts) that can be used as `Incident.Alert.getAssociatedAlerts` or `All.getAssociatedAlertsForIncident`.
    - [Get Responder Alerts](https://docs.opsgenie.com/docs/incident-api#get-responder-alerts) that can be used as `Incident.Alert.getResponderAlerts` or `All.getResponderAlertsForIncident`.

- # Added support for the following Incident.Details methods:
    - [Add Details(Custom Properties) to Incident](https://docs.opsgenie.com/docs/incident-api#add-detailscustom-properties-to-incident) that can be used as `Incident.Details.addDetails` or `All.addDetailsToIncident`.
    - [Remove Details(Custom Properties) from Incident](https://docs.opsgenie.com/docs/incident-api#remove-detailscustom-properties-from-incident) that can be used as `Incident.Details.removeDetails` or `All.removeDetailsFromIncident`.

- # Added support for the following Incident.Note methods:
    - [Add Note to Incident](https://docs.opsgenie.com/docs/incident-api#add-note-to-incident) that can be used as `Incident.Note.addNote` or `All.addNoteToIncident`.
    - [List Incident Notes](https://docs.opsgenie.com/docs/incident-api#list-incident-notes) that can be used as `Incident.Note.getNotes` or `All.getIncidentNotes`.

- # Added support for the following Incident.Tags methods:
    - [Add Tags to Incident](https://docs.opsgenie.com/docs/incident-api#add-tags-to-incident) that can be used as `Incident.Tags.addTags` or `All.addTagsToIncident`.
    - [Remove Tags from Incident](https://docs.opsgenie.com/docs/incident-api#remove-tags-from-incident) that can be used as `Incident.Tags.removeTags` or `All.removeTagsFromIncident`.

- # Added support for the following Incident.Timeline methods:
    - [Add Incident Timeline Entry](https://docs.opsgenie.com/docs/incident-timeline-api#add-incident-timeline-entry) that can be used as `Incident.Timeline.addEntry` or `All.addIncidentTimelineEntry`.
    - [Delete Incident Timeline Entry](https://docs.opsgenie.com/docs/incident-timeline-api#delete-incident-timeline-entry) that can be used as `Incident.Timeline.deleteEntry` or `All.deleteIncidentTimelineEntry`.
    - [List Incident Timeline Entries](https://docs.opsgenie.com/docs/incident-timeline-api#list-incident-timeline-entries) that can be used as `Incident.Timeline.getEntries` or `All.getIncidentTimelineEntries`.
    - [Get Incident Timeline Entrys](https://docs.opsgenie.com/docs/incident-timeline-api#get-incident-timeline-entry) that can be used as `Incident.Timeline.getEntry` or `All.getIncidentTimelineEntry`.
    - [Hide Incident Timeline Entry](https://docs.opsgenie.com/docs/incident-timeline-api#hide-incident-timeline-entry) that can be used as `Incident.Timeline.hideEntry` or `All.hideIncidentTimelineEntry`.
    - [Unhide Incident Timeline Entry](https://docs.opsgenie.com/docs/incident-timeline-api#unhide-incident-timeline-entry) that can be used as `Incident.Timeline.unhideEntry` or `All.unhideIncidentTimelineEntry`.
    - [Update Incident Timeline Entry](https://docs.opsgenie.com/docs/incident-timeline-api#update-incident-timeline-entry) that can be used as `Incident.Timeline.updateEntry` or `All.updateIncidentTimelineEntry`.

Copyright Adaptavist 2025 (c) All rights reserved