Get tinyId as variable when creating an alert via API
Asked by LL92:

We're creating alerts in OpsGenie via a New Relic workflow webhook.

When the alert is created. Is there any way of getting the tinyId to be written as an attribute in the same alert?

Or can I create a custom action to use the same tinyId when doing another API request.

I know that many people are using Jira. We're using Microsoft Dynamics as CRM. We want to be able to create a new support ticket in MS Dynamics. This is today done via a website which we forward the url to in the alert. The website is calling a stored procedure which gets all data from a table that that we populate via a job that gets data from OpsGenie once per minute.

If we can get the tinyId directly to be appended as parameter to the url that we're building. Then we could pass that information to the website, which passes it to the stored procedure, which gets the data from OpsGenie by just getting data from one alert instead of getting all active and then trying to match them.

Or is it a better way to forward data to other tools? We need to go Vai our website since our on call staff needs to fill other information from a form before creating the support ticket. So we cannot purely use OpsGenie. Therefore it would be good to extract some unique identifier from the alert to pass in the link (in the alert). Let's say we want to have a link in the alert that are saying "Create support ticket". Then we would need the tinyId to be dynamically added to the link when the alert is created. Otherwise we cannot reference it back when extracting more data from the alert.

Or is there a better solution?

Thanks in advance.


Answers:
author: Rafael Meira
body: Hey [@LL92](/t5/user/viewprofilepage/user-id/5331487)

I'm glad you found a workaround using the New Relic \`issueId\`. Indeed, the \`alias\` field in Opsgenie is a unique identifier for an alert and can be used to correlate the alert with issues in other systems.

As for your original question about embedding the \`tinyId\` in a URL, I apologize for any confusion. Unfortunately, as of now, Opsgenie does not have the capability to automatically insert the \`tinyId\` into the alert fields (like \`message\` or \`description\` or \`link\`) at the time of alert creation. The \`tinyId\` is generated by Opsgenie only after the alert is created.

However, I understand your use case and it's a valid point.

For now, your current approach of using the New Relic \`issueId\` as the \`alias\` in Opsgenie and sending it as a parameter in the URL seems to be a good solution for your requirement.

Thank you for your feedback and feel free to reach out if you have any more questions.

Best,  
Rafa


author: Rafael Meira
body: Hey [@LL92](/t5/user/viewprofilepage/user-id/5331487) happy to help!  

I will send you some general information on your question.

For creating an alert via API and retrieving the \`tinyId\`, please refer to the "Create Alert" section of the Alert API documentation: \[Create Alert\] <https://docs.opsgenie.com/docs/alert-api#create-alert>

In response of the create alert request, you'll receive the \`tinyId\` along with other details of the alert.  

<br />

To understand more about Alert fields (which includes \`tinyId\`), you can check out this document: <https://support.atlassian.com/opsgenie/docs/alert-fields/>

3. For using dynamic fields within alerts, you can use OpsGenie's in-built capabilities to include dynamic data in the alert fields. More details are in this guide about managing alert content: <https://support.atlassian.com/opsgenie/docs/alert-fields/>  

For your requirement of creating a support ticket link within the alert, you can do this by including the \`tinyId\` in the alert message or description. This requires careful crafting of the alert message/description when creating an alert via the API.

For example, the message field in the create alert request could look something like this:

\`\`\`json  
{  
"message": "Alert created with tinyId: <https://yourwebsite.com/ticket/{{tinyId>}}"  
...  
}  
\`\`\`

Just make sure to replace \`{{tinyId}}\` with the actual \`tinyId\` in your API request.

If you need to filter alerts based on specific patterns in the alert fields, you can use OpsGenie's capabilities of using regular expressions in alert filtering. More details are in this guide: \[Regular Expressions for Improved Alert Filtering\]   

<https://support.atlassian.com/opsgenie/docs/regular-expressions-for-improved-alert-filtering/>

I hope this helps.  

Best,  
Rafa

comments: author: LL92
body: Hi [@Rafael Meira](/t5/user/viewprofilepage/user-id/4969383) and thanks for your reply.  
I'm not sure about "Just make sure to replace \`{{tinyId}}\` with the actual \`tinyId\` in your API request"  

When sending the alert to Opsgenie we want to also send a link so Opsgenie would populate the link with the tinyId automatically.  

Here is an example of the body:  
{  
"message": "ServerA is DOWN",  
"link": "\<a href=<https://ourdomain.com/ticket?tinyId=%tinyId%>\>Create Issue\</a\>"  
**...**   
}  

Can Opsgenie populate %tinyId% with the actual tinyId that was created?  

So when someone clicks the \[Create Issue\] link they will come to a pre-populated form with the correct data including the tinyId. So our backend will just need to connect to Opsgenie to fetch the necessary data based on the tinyId and then create the issue in our ticket system.  

Or can this be done easier via for example Opsgenie Actions? However, in both cases I would need some identifier to use when connecting to Opsgenie to get the correct data. I assume it's the tinyId I need to use?  

Thanks in advance.


author: LL92
body: I'm using the New Relic integration.

For now I solved it by using the New Relic *issueId* which is automatically added as Alias in Opsgenie.

So I'm appending the *issueId* as an attribute to a link when sending the body to Opsgenie. Which means that when someone clicks the link our webserver will connect to the Opsgenie API to GET the correct data in order to create the ticket in our ticket system.