Hello,
I am creating an automation rule on Jira that sends a POST request to an external API and the response is stored in a text field. Now the problem I have is that the JSON format is changed when I try to access the body via {{webhookResponse.body}}.
Also, I see the proper JSON format when I try to validate the rule manually before deploying it. I am aware that the automation formats the response so that the JSON values can be accessible via dot notation. But is there a way to access the raw response?
I also have a scriptrunner plugin which I can utilize.
Payload:
webhookResponse.body:
I somehow need that data as show in the Payload format since I am using it for processing data for other requirements.
In a scriptrunner script (listener, postfunction or job) you can use groovyx.net.http.HTTPBuilder or groovyx.net.http.RESTClient to make post requests to external systems.
You will have access to the full response
There are almost no limit to what you can do with that.
Hey Peter,
Thanks for responding!
I am currently having some issues with the RESTClient on my Scriptrunner. I wrote a simple GET request to google.com and when I execute, the circle keeps spinning and it returns nothing. Am I doing something wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a better example than google (which isn't an api)
I don't know why this would just spin on your end. Does your server have outgoing internet access?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Peter,
It's still the same issue. Nothing ever loads.
But when I try to reach google.com or any URL from the Jira Automation's SEND web request action, I am able to reach it and retrieve the data. Also, I have disabled the allowlist on my Jira.
Let me know if there is anything else that I can check.
Below are the logs that I found in the diagnostic.log
2024-01-16 11:12:59,321+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705399979307 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/cb-automation/latest/project/10600/rule/184/execute","username":"shumesh","elapsedTimeInMillis":63704}
2024-01-16 16:54:22,691+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705420462678 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":523921}
2024-01-16 17:10:12,960+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705421412947 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":130434}
2024-01-17 06:24:27,894+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705469067881 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":129990}
2024-01-17 06:50:01,852+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705470601822 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":129799}
2024-01-17 07:16:33,129+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705472193111 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":131126}
2024-01-17 07:39:23,254+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705473563241 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":131193}
2024-01-17 08:07:28,771+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705475248755 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":130251}
2024-01-17 08:32:34,014+0100 pool-16-thread-1 INFO [atlassian-diagnostics-data-logger] 1705476754004 ; INFO ; HTTP ; HTTP-3001 ; Slow HTTP request detected ; not-detected ; ; ; {"requestPath":"/rest/scriptrunner/latest/user/exec/","username":"shumesh","elapsedTimeInMillis":130597}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, never encountered this type of issue. This goes beyond my expertise.
Do other scripts (without rest calls) complete without issues in the console.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, all the other scripts work without any issue. Anyways, I will try asking help from Adaptavist to see if they know what exactly is happening here..
Thanks for your help Peter! 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan ,
I figured out that the HTTP requests from Scriptrunner was not passing through the proxy. So I googled up and looked up for a line that sets the RESTClient to use the proxy.
import groovyx.net.http.RESTClient
def url = 'https://myurl'
def authToken = 'my_token'
def restClient = new RESTClient(url)
restClient.setProxy('security-proxy.emea.svc.net', 3128, 'http')
def headers = [
'Authorization': "Basic $authToken",
'Content-Type': 'application/x-www-form-urlencoded'
]
def response = restClient.post(headers: headers)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The RESTClient automatically converts the JSON string into an actual object.
If you only need to work with the underlying data, it's best to keep it as the object. Then you can easily access various elements.
In my example from above, you could do something like this:
import groovyx.net.http.RESTClient
def url = 'https://restcountries.com'
def restClient = new RESTClient(url)
def response = restClient.get(path:'/v3.1/alpha/us', query:[fields:'name']).data
response.name.common
But if you need to just store the json as an actual string elsewhere, then you can easily convert it back:
import groovyx.net.http.RESTClient
import groovy.json.JsonBuilder
def url = 'https://restcountries.com'
def restClient = new RESTClient(url)
def response = restClient.get(path:'/v3.1/alpha/us', query:[fields:'name']).data
def responseJson = new JsonBuilder(response).toString()
//or alternatively
def responseJsonPretty = new JsonBuilder(response).toPrettyString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan
Do you have any working Scriptrunner code that can send a POST request to an external API and retrieve a JSON? Or do you have any other suggestions for my issue mentioned above?
My POST request should include a bearer token and a payload.
Thanks in advance and a Happy New Year!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shamanth
As far as I'm concerned, it's currently not possible to access the payload as RAW JSON in Jira Automation. There's a related feature request for this at https://jira.atlassian.com/browse/AUTO-1016.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.