Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,459,882
Community Members
 
Community Events
176
Community Groups

How to get REST api from Groovy Script?

Edited

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?

1 answer

I think the property of resp you need to use is data. Can you try to check it with?

log.info("Resp : " + resp.data)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS

Atlassian Community Events