In our issues, we’ve linked the affected service from the asset database. Now, in the outgoing sync, I want to transfer the asset name instead of the link. How do I access the asset information?
I tried to following. To grant permission, I have given the Exalate app read access to the asset space.
def affectedServiceField = issue.customFields."10482"
if (affectedServiceField?.value && !affectedServiceField.value.isEmpty()) {
// Get the object ID
def objectId = affectedServiceField.value[0].objectId
// Use the httpClient to fetch the object details
def assetObject = httpClient.get("/ex/jira/${cloudid}/jsm/assets/workspace/{workspaceId}/v1/object/${objectId}")
if (assetObject) {
// Assets API returns 'label' as the display name
replica.customKeys."affectedService" = assetObject.label
} else {
replica.customKeys."affectedService" = "Object not found"
}
} else {
replica.customKeys."affectedService" = "Field Empty"
}
This leads to the following error:
Error Detail Message:
Could not authenticate to this Jira Cloud when performing action: #http. Error(s):
(null)
Encountered a "null - null" error while loading this page.
Go to Jira home
com.exalate.api.exception.script.IssueTrackerScriptException: Could not authenticate to this Jira Cloud when performing action: #http. Error(s):
(null)
Encountered a "null - null" error while loading this page.
Hi @Felix-PCG ,
Since Exalate does not natively support syncing Asset fields, we can work around this by leveraging Groovy scripting along with an API call to the Atlassian Assets endpoint.
Approach
On the sending side, we’ll extract the Asset field data using the Jira Issue API and then call the Assets API to retrieve the required details.
Step 1: Include HTTP Client
Add the GroovyHttpClient.groovy class to your outgoing script.
Step 2: Fetch Asset Details via API
Use the following logic in your outgoing script:
// Get workspaceId and objectId from Jira Issue API
String key = issue.key
def result = httpClient.get("/rest/api/latest/issue/" + "$key")
def workspaceId = ("${result.fields."customfield_10062".workspaceId}".replace("[","").replace("]",""))
def objectId = ("${result.fields."customfield_10062".objectId}".replace("[","").replace("]",""))
def USER = "<<jira_username>>"
def token = "<<jira_token>>"
// Fetch Asset object details
def res = new GroovyHttpClient(nodeHelper)
.http(
"GET",
"https://api.atlassian.com/jsm/assets/workspace/${workspaceId}/v1/object/${objectId}",
null,
[
"Content-type": ["application/json"],
"Authorization": ["Basic ${(USER + ":" + token).bytes.encodeBase64().toString()}"]
]
)
def js = new groovy.json.JsonSlurper()
def jsonRes = js.parseText(res)
// Store the required value in replica
replica."Asset information" = jsonRes.label
Required Changes
-
Update the custom field ID in:
result.fields."customfield_10062"→ replace with your actual Asset field ID
-
Provide your credentials:
-
<<jira_username>> -
<<jira_token>>
-
Next Steps
Once this data is sent to the destination side, a similar approach can be used to:
-
Identify the corresponding Asset object
-
Set it via the Assets REST API
For reference, you can use the Assets REST API guide for available endpoints and payload structure.
Thanks, Dhiren
GroovyHttpClient.groovy (7.6 KB)
Hi Dhiren,
Thank you so much for the solution. It’s unfortunate that the HTTP client isn’t usable without logging in. Since I’d rather not use a separate token, I’ve decided to determine the relevant asset database values using Jira Automation and store them in the issue.
Thanks again for your support!