How to enable integration with OpsGenie?
Asked by pavol_cvincek01:

Hello,  
I had to install OpsGenie Edge Connector on our test Jira server but when I am trying to submit alert on OpsGenie side, I can't get Jira SD to make ticket from that alert. Communication works from OpsGenie (OG) to Jira SD server. This is part of the output.txt file:  
WARNING:root:\[createIssue\] Could not execute at Jira Service Desk; response: b'{"errorMessages":\[\],"errors":{"components":"Component/s is required."}}' status code: 400  
In the settings for that project there are fields which are needed for creation of the ticket. "Component/s" is there as hidden. I was not able to remove it completely. When I made it blank - didn't help  
I tried to define "Component/s" on OG side but no success as well. I am still getting above warning.  
Can you please help me get thru that error message so Jira SD could create tickets based on OG alerts?


Answers:
author: Robert
body: Hi [@pavol_cvincek01](/t5/user/viewprofilepage/user-id/3990727) !

If the Jira project and issue type you are sending alerts to have (non-standard) required fields (like a component), there are two main options for getting them filled:

1. Use [Manual Issue Creation for Jira Software](https://docs.opsgenie.com/docs/jira-software-cloud#creating-and-linking-issues-from-opsgenie). This flow will essentially bring up the same *Create Issue* modal from Jira, including custom fields. The downside of this option is it isn't automated; a user would have to click the "Create Issue" button in an alert. ![2020-07-02_11-50-38_01.png](https://community.atlassian.com/t5/image/serverpage/image-id/101487i52F186C7215464E5/image-dimensions/452x396?v=v2 "2020-07-02_11-50-38_01.png")
2. Customize the OEC script to include component in the createIssue action: <https://github.com/opsgenie/oec-scripts/blob/master/Jira/scripts/actionExecutor.py#L113>  

   This would end up looking something like this:

   ```
    content_params = {
        "fields": {
            "project": {
               "key": project_key
            },
            "issuetype": { 
               "name": issue_type_name 
            },
            "summary": queue_message.get("summary"),
            "description": queue_message.get("description"),
            "labels": [toLabel.replace("\\s", "")],
            "components": [{
                "id": component
            }]
        }
    }
   ```

Hope this helps!

comments: author: pavol_cvincek01
body: Hello Robert,  
First of all, thanks a lot for your feedback. Option 1 is not suitable for us so I went for second one. I added "compoment" there as suggested but after I started OEC I could see there error saying " NameError: name 'component' is not defined". I tried to define it by adding "import component" on the top of the actionExecutor.py but another problem appeared - "ImportError: No module named 'component". It would be great if you would be able to advice with this as well.  
Thank you in advance and have a nice day.


author: Robert
body: Hi [@pavol_cvincek01](/t5/user/viewprofilepage/user-id/3990727) !

The "component" I had included in that snippet was an example variable name, so there's no need to do any additional imports in the script.   

You would need to define "component" somewhere in the script, or at least substitute it with your component ID:

```
 content_params = {
     "fields": {
         "project": {
            "key": project_key
         },
         "issuetype": { 
            "name": issue_type_name 
         },
         "summary": queue_message.get("summary"),
         "description": queue_message.get("description"),
         "labels": [toLabel.replace("\\s", "")],
         "components": [{
             "id": "12345"
         }]
     }
 }
```

Hope this helps clarify things a bit!


author: pavol_cvincek01
body: Hi [@Robert](/t5/user/viewprofilepage/user-id/2275658)   
Yep, I used our value for component at first but no success as mentioned above. Afterwards I changed "id" to "name" and it finally works. Thanks a lot for that, it helped significantly.

<br />

Unfortunately now I can see this there:  
"WARNING:root:\[createIssue\] Could not execute at Jira Service Desk; response: b'{"errorMessages":\[\],"errors":{"customfield_13040":"Field Customer Request Type is required.","customfield_15340":"Field Did It work in the past? is required."}}' status code: 400"  

Field Customer Request Type should be "Alerts"  
Field Did It work in the past? should be "Yes"  

When I tried the same approach like for "components" I wasn't successful. Can you advice how the code should looks like?  

Thanks in advance and have a nice day.  


author: Robert
body: [@pavol_cvincek01](/t5/user/viewprofilepage/user-id/3990727) I think you're on the right track by following the same process as the first field. My first guess is those fields might be a different "type" of custom field though, so the format in the API request may need to be modified.

[This page](https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/) has some great examples in the **Creating an issue using custom fields** section. I'd check the types of those custom fields and make sure they're using the format mentioned in those docs.