Add Issue Key and URL to Incident
Asked by Oalimerko:

Dear all,

i am using opsgenie ,OEC and Python Script for creating some jira issues with some custom jira fields which are not filled by default,the synchronization opsgenie-jira works fine and the jira tickets are created.I use the following scenario:

* I select e.g an alert and create manually for this alert an incident.
* Incident itself creates an R alert and based on some rules which i defined,the R alert triggers the ticket creation.

But i would like also to have within Incident the Issue Key and URL under Extra Properties,like below:  
![Issue Key.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/177772iB2D937218D707351/image-size/large?v=v2&px=999 "Issue Key.JPG")  

Could you pls give me a hint how to achieve this?I use this [py script](https://nextcloud.gk-software.com/index.php/s/wbJnqJaiL9fcSep)

Regards  
Oltion Alimerko


Answers:
author: Samir
body: Hi [@Oalimerko](/t5/user/viewprofilepage/user-id/4664515) ,

You could have the script add those fields to the Incident via [Incident API](https://docs.opsgenie.com/docs/incident-api). The responder alert that is triggering your script will have the incident-id as an Extra Property

e.g.

![2022-01-14_09-13-14.png](https://community.atlassian.com/t5/image/serverpage/image-id/177812iB236B7060D7FBC73/image-size/large?v=v2&px=999 "2022-01-14_09-13-14.png")

So you could have your script use that incident-id for the API request to update the incident fields with those additional fields.

Hope this helps!

Thanks,

Samir

comments: author: Oalimerko
body: Hi [@Samir](/t5/user/viewprofilepage/user-id/2168284) ,  

i am not sure if i got it right.Do you mean first create incident manually and then update it via API or create the incident directly via API?


author: Samir
body: [@Oalimerko](/t5/user/viewprofilepage/user-id/4664515) It sounds like the responder alert created *from* the incident is triggering OEC to create the issue in Jira, right?

If so - that means the incident is being created *before* the Jira issue is being created.

So I was thinking modify the script that is *creating* the Jira issue, so that after it gets the response from Jira that the issue was created, it updates the incident with the additional fields via Incident API.


author: Oalimerko
body: [@Samir](/t5/user/viewprofilepage/user-id/2168284) ,  
now i got your idea.But how can the script gets the response from Jira that the issue was created,especially how to get the issue key?  
In order to update the incident,first i need the incidentId of respective incident,how to get it?  

Do you have any code example?


author: Samir
body: [@Oalimerko](/t5/user/viewprofilepage/user-id/4664515)

I don't have an example of the script. But the script is receiving the details of the responder alert from Opsgenie, which is then used to create the issue in Jira. So you could make another Get Alert API request back to Opsgenie to get all the responder alert fields (the **incident-id** field is an **extraProperty** of the responder alert as shown in my screenshot in my initial reply).

So you can grab that incident-id and assign it to a variable in the script.

Then when it makes the request to Jira to create the issue via API, it then grabs the *response* of that api request (line 256 below) and grabs the issueKey that is returned, and then adds that issueKey as an extra property to the alert.

![2022-01-14_11-14-50.png](https://community.atlassian.com/t5/image/serverpage/image-id/177847i5F6540CEE5DF5DDA/image-size/large?v=v2&px=999 "2022-01-14_11-14-50.png")

So you could add lines there for it to then make an [Add Details to Incident](https://docs.opsgenie.com/docs/incident-api#add-detailscustom-properties-to-incident) API Request (since you have the incident-id), and add the Jira issueKey and link to jira issue as details (i.e. extra Properties) to the incident.


Tags: cloud

python