Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to use text and list functions to variably obtain Webhook data

Summary

To start, when using Automation for Jira we have a trigger that reads incoming Webhooks. When we use this trigger, we can use the {{webhookData}} smart value to represent the POST payload. That said this smart value gets the root of the JSON Payload by looking up the key/value pairs of parent and child values.

However, how can we achieve this same result from the Webhook data using text and list functions? Why would this be useful?

Use Case

You are looking to obtain JSON value from the Webhook data, however, you want to use a variable to access the JSON values without it being a fixed tag for a specific key/value pair. This is useful if you have a location field where it is paired with a user email in JSON, such as:

{
"CN":"osmar.email1@s4e.cl",
"MA":"osmar.email2@s4e.cl",
"FR":"osmar.email3@s4e.cl",
"ES":"osmar.email4@s4e.cl"
}

Automation Configuration

1. Create Variable > webhookResponse as textResponse Smart Value - This converts the JSON payload to a String. This could be just the list of possible countries, not the entire JSON Response.

2. Then we would want to use an Advanced Branch such as the following

Advanced Branch >

{{textResponse.split(",")}}

As value Smart Value - This converts the String to a List, separating it by commas.

3. Then you will want to use a smart value Advanced Compare Condition that converts the string to a list, separating it by commas.

Condition >

{{value}}

Contains >

{{issue.country}}=

4. This checks if the current entry it is going through contains the country code (for example). The = is important, because the email address might contain equivalent characters and that would result in a false positive, but this makes it so that it only actually checks the country code, since an email address won't have an = in it.

5. Action > What-have-you, using this to return just the email address:

{{value.split("=").last.replaceAll("\}","").replaceAll("\{","")}}

This is a different way to achieve the ultimate goal of "I have a JSON Payload, and I want to dynamically return just a value based on a key in an object.

In short, the solution is that we are not using JSON Keys via the built-in JSON functionality in Automation Smart Values and instead are using the text functions and list functions to achieve the same effect.

Article references

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events