Incident "Events" from JSM
Asked by Ken Young:

Hi Again,

We are using JSM in it's current OpsGenie(Alerts) -\> JSM(Incidents) configuration that the OpsGenie-\>JSM integration provides. As such, we are not using OpsGenie incidents. We are, however, linking linking services to our JSM Incident tickets (using Automation) though by doing a service lookup by name via the OpsGenie API.

In looking up the "service" via the LookupObject automation component, we can retrieve the service. In the JSM UI it with also show the Compass component (if you have it linked), but the lookup object doesn't seem to contain the compass component, or the id/link.

Our ultimate goal is that when a incident is opened in JSM (with a service assigned to the incident), it create a corresponding "Incident" event in Compass. Would be best if I didn't have to write it, but looking to utilize the [REST API](https://developer.atlassian.com/cloud/compass/rest/api-group-events/#api-group-events) to accomplish this. My question is if I am targeting a specific component/service in the event request body, how do you indicate that, and how do you lookup the Id dynamically if Automation doesn't currently support GraphQL (or what alternatives are there)

Thank you

Ken


Answers:
author: Ken Young
body: To close the loop on this if this helps anyone creating an Incident Event. I was eventually able to do this with Jira Automation on the GraphQL gateway.

Graphql queries/mutations need to be converted into rest format in order to utilized in in the Web Request component. To help in converting Queries/Mutations, I has some success with the "[GraphQL to REST queries](https://marketplace.visualstudio.com/items?itemName=orasik.graphql-to-rest-queries)" available on the VS Code Marketplace

The first step was to execute a query against the GraphQL Gateway to retrieve a Compass component by it's Name.

![lookupComponent.png](https://community.atlassian.com/t5/image/serverpage/image-id/284711i59FE82474B0F9054/image-size/large?v=v2&px=999 "lookupComponent.png")

Next was to validate that a single eventsource was returned in the webResponse. The total # of components is found by using the following smart value

```
{{webResponse.body.data.compass.searchComponents.totalCount}}?
```

After confirming that a component was retreived, the For Each Advance Branching was utilized to loop over the components event sources.

```
{{webResponse.body.data.compass.searchComponents.nodes.first.component.eventSources}}
```

![flow_findexternaleventsource.png](https://community.atlassian.com/t5/image/serverpage/image-id/284714iD868B17709230742/image-size/large?v=v2&px=999 "flow_findexternaleventsource.png")

After retrieving the Incident externalEventSourceId, variables for start DateTime and updated DateTime were created separately so they could be formatted specifically for Graphql. ++Note: the smart values date and time formatter for jiraDateTime is the correct format, but the formatter doesn't seem to be currently working as documented.++

To create the actual Incident Event in Compass, a mutation using the related JSM Incident issue information is sent via a web request.

![webrequest_incidentmutation.png](https://community.atlassian.com/t5/image/serverpage/image-id/284717i95A9FE34762CDA05/image-size/large?v=v2&px=999 "webrequest_incidentmutation.png")

I am hoping this is helpful.


author: Ken Young
body: After a bit more investigation, I have found the answer to using Automation's web request function to do queries and mutations into Compass. ([Link](https://community.atlassian.com/t5/Jira-Software-questions/Jira-Automation-Can-we-use-Graph-API-in-Jira-Automation-Web/qaq-p/2417319#U2491570) ) After crafting a query to pass in the service name, I can find the correct Component., as well as the eventsources's related to that component. So hopefully I now have all of the data to post/mutate events with an external url back to the JSM "incident" ticket.