Hello all,
we are currently populating an external system with the Jira ID via a put call. We need this to be able to send updates from this system to the respective Jira issue.
Thus, when creating the issue via workflow, we want to trigger a script runner script which will then perform the put post. However, we are currently still getting an error message, the body is intentionally empty for now for testing purposes. The endpoint differs to a field value which is filled by the creation, this is happening via post call from this external system.
I suspect the syntax of my script does not fit.
package utils
import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
public class UpdateFieldValuePut{
public static String postResponse(Issue issue)
{
def hostUrl = "https://test-api.com/"
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_12727")
def strErgebnis = issue.getCustomFieldValue(customField).toString()
def endpointAndQuery = "https://test-api.com/test/" +strErgebnis+".json"
// Turn the data will be sent into JSON, the HTTP requests specify in the header to accept application/JSON
// If the API accepts different types then you can change this and format the data accordingly
def bodyJson = JsonOutput.toJson([data: "<YOUR DATA>"
])
def client = new RESTClient(hostUrl)
client.setHeaders([
'Accept' : ContentType.JSON,
// If authentication mechanism of the API is Basic Authentication, 'Authorization' header with username and password encoded as Base 64 can be specified here
'Authorization': "Basic ${'APIToken:x'.bytes.encodeBase64()}"
])
client.handler.success = { HttpResponseDecorator response, json ->
json
}
client.handler.failure = { HttpResponseDecorator response ->
// Failure can be handled here
log.error response.entity.content.text
[
:
]
}
client.put(
path: endpointAndQuery,
contentType: ContentType.JSON,
body: bodyJson
)
}
}
Best regards,
Tobias
Hi @Tobias
Could you please clarify, when you mentioned External System, i.e. are you referring to an external REST Service?
If so, you could try to use this sample code provided in the Adaptavist Library.
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
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.