Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using Forms via API

Lukasz Grobelny
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
July 14, 2023

So, I've been struggling to get the forms via API using Scriptrunner. In general, Atlassian documentation is omitting one crucial part - formid which needs to be pulled first. 

 

So, if anyone needs it, here's a code:

- pulls the form ID from an existing issue

- authenticates to api.atlassian.com

- pulls the form details

 

import javax.xml.bind.DatatypeConverter

def issueKey = XXX-123
def username = 'NAME'
def password = 'Auth Token'
def authString = "${username}:${password}"
def encodedAuthString = DatatypeConverter.printBase64Binary(authString.getBytes('UTF-8'))

def formId = get("/rest/api/2/issue/${issueKey}/properties/proforma.forms")
.header('Content-Type', 'application/json')
.asObject(Map).body

def id = formId.value.forms[0].uuid

def fields = get("https://api.atlassian.com/jira/forms/cloud/CLOUDID/issue/${issueKey}/form/${id}")
.header('Content-Type', 'application/json')
.header('Authorization', "Basic ${encodedAuthString}")
.header('X-ExperimentalApi', 'opt-in')
.asObject(Map).body

 

It pulls the first form, but you can iterate, etc. Hope it will make somebody's day easier ;)  

2 answers

1 vote
Frédéric Dubois
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 23, 2023

thanks  a lot for the sharing :-)

0 votes
Jeffrey Bistrong
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 29, 2026

I can't get this to work. Any thoughts? my ticket definitely has a form on it

getting this error

java.lang.NullPointerException: Cannot get property 'forms' on null object at Script_d6a87e4086ed1f81632a13d3d3cafb1b.run(Script_d6a87e4086ed1f81632a13d3d3cafb1b.groovy:17) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:35) at com.adaptavist.sr.cloud.workflow.AbstractScript.runScriptFromRequest(AbstractScript.groovy:98) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:59) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)

 

Monosnap Script Console - JIRA 2026-04-29 21-31-36.pngMonosnap [HR-1244] nj - Exited April 28 - JIRA 2026-04-29 21-32-44.png

Jeffrey Bistrong
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 29, 2026

I was able to get as far as this and after testing each call in postman and verifying i get results, my last return (fields4) does not return any data

 

import javax.xml.bind.DatatypeConverter
import groovy.json.JsonSlurper

// --- CONFIG ---
def issueKey = 'HR-1244'
def username = 'XXXXX'
def password = 'XXXXXX0"

def cloudId = "XXXX"

// --- AUTH GEN ---
def authString = "${username}:${password}"
def encodedAuthString = DatatypeConverter.printBase64Binary(authString.getBytes('UTF-8'))

// --- THE REQUEST ---
def response = get("https://api.atlassian.com/jira/forms/cloud/${cloudId}/issue/${issueKey}/form")
.header('Authorization', "Basic ${encodedAuthString}")
.header('Accept', 'application/json') // Added to ensure JSON return
.header('X-ExperimentalApi', 'opt-in') // Required for most Forms API calls
.asString() // We use asString to see the raw output if it's not JSON

//return response.body

def responseBody = response.body

// 1. Parse the JSON string into an object
def slurper = new JsonSlurper()
def slurper1 = new JsonSlurper()

def formsList = slurper.parseText(responseBody)

// 2. Access the first item in the list [0]
// and navigate to formTemplate -> id
def templateId = formsList[0]?.id

return templateId //does return what i expect 

// 3. Call the specific form instance to get the answers
def fields4 = get("https://api.atlassian.com/jira/forms/cloud/${cloudId}/issue/${issueKey}/form/${templateId}")
.header('Authorization', "Basic ${encodedAuthString}")
.header('Accept', 'application/json') // Added to ensure JSON return
.header('X-ExperimentalApi', 'opt-in') // Required for most Forms API calls
.asString() // We use asString to see the raw output if it's not JSON


return fields4

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events