You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I have created custom REST Endpoint using scriptrunner and its working properly.
Now I want to get the json data from the REST API url created by REST Endpoint using Groovy Script. Can anyone help me on how to do it?
This is the format of my API,
{
total: 1,
values: [
{
jiraid: "BOR-102",
row_id: 166,
row_type: "Recurring",
nor_location_code: "LOC-285212",
}
}
I tried to follow
https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Call-Rest-API-with-parameters/qaq-p/840702 this thread.
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
def httpBuilder = new HTTPBuilder(apiUrl)
log.info(httpBuilder.toString())
httpBuilder.get(
path: "/",
requestContentType: ContentType.JSON,
) {
resp, reader ->
doSomething(resp, reader)
}
def doSomething(def resp, def reader) {
log.info("Resp : " + resp)
log.info("reader : " + reader)
// do something with the data
}
Executing above code gave me
2021-08-10 12:41:35,686 [ajp-nio-8009-exec-2] | groovyx.net.http.HTTPBuilder@3c4270a3
2021-08-10 12:41:35,793 [ajp-nio-8009-exec-2] | Resp : groovyx.net.http.HttpResponseDecorator@2c73ca93
2021-08-10 12:41:35,793 [ajp-nio-8009-exec-2] | reader : var AJS=AJS||{};AJS.debug=true;
(function() {
var contextPath = '';
var eventBuffer = [];
function printDeprecatedMsg() {
if (console && console.warn) {
console.warn('DEPRECATED JS - contextPath global variable has been deprecated since 7.4.0. Use `wrm/context-path` module instead.');
}
}
function sendEvent(analytics, postfix) {
analytics.send({
name: 'js.globals.contextPath.' + postfix
});
}
function sendDeprecatedEvent(postfix) {
try {
var analytics = require('jira/analytics');
if (eventBuffer.length) {
eventBuffer.forEach(function(value) {
sendEvent(analytics, value);
});
eventBuffer = [];
}
if (postfix) {
sendEvent(analytics, postfix);
}
} catch(ex) {
eventBuffer.push(postfix);
setTimeout(sendDeprecatedEvent, 1000);
}
}
Object.defineProperty(window, 'contextPath', {
get: function() {
printDeprecatedMsg();
sendDeprecatedEvent('get');
return contextPath;
},
set: function(value) {
printDeprecatedMsg();
sendDeprecatedEvent('set');
contextPath = value;
}
});
})();
How can I get the json data from the API?
I think the property of resp you need to use is data. Can you try to check it with?
log.info("Resp : " + resp.data)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.