Hi I would like to perform a Get request in scriptrunner. I'm getting the desired output for post request but when I work with get request I'm getting either 400 bad request or 500 Internal server error message.
Hi @Pradeep A ,
would you please share us, how exactly your GET request looks like (or the script), so we can try to find out, what's wrong?
Thank you.
Hi @Hana Kučerová This is the script I have used
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import groovy.json.JsonSlurper;
import com.atlassian.jira.issue.IssueInputParameters
import groovy.json.StreamingJsonBuilder;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import org.apache.commons.codec.binary.Base64;
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import net.sf.json.groovy.JsonSlurper
import groovy.json.JsonOutput
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
@BaseScript CustomEndpointDelegate delegate
testGetMethod(httpMethod: "GET") { MultivaluedMap queryParams ->
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
def issueId = queryParams.getFirst("issueId") as long
Issue issue = issueManager.getIssueObject(issueId)
log.warn("The issue ID"+issueId)
def issueSum=issue.getSummary()
def ContainerPath = """ "LDAP://OU=BU3,OU=BU2,OU=BU1,OU=Employees,OU=contoso,DC=consto,DC=com" """
def displayName=issueSum
def description="test channel"
def membershipType="standard"
//-------------------------------------Get Users---------------------------------------------------------------//
URL url = new URL("https://graph.microsoft.com/v1.0/users/pradeep@avaMigration.onmicrosoft.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setDoOutput(true)
con.setRequestProperty("Authorization", "Bearer "+token);
con.connect();
log.warn(con.getResponseCode() as String);
BufferedReader input = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = input.readLine()) != null) {
content.append(inputLine);
}
input.close();
log.warn(content as String);
def flag = [
type : 'success',
title: "Channel Created",
close: 'auto',
body : "The Channel have been successfully created",
issueID:issueId,
display_Name:displayName
]
Response.ok(JsonOutput.toJson(flag)).build()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Pradeep A ,
please remove the authorization string from your post - this is public forum, so somebody could use it and get to your systems...
So, the URL your are calling is
https://your-jira-url/rest/scriptrunner/latest/custom/testGetMethod?issueId=123 ?
The problem could be, that issue id is invalid and issue is not found.
If you remove all the code from the request processing and just return the flag variable like this:
def flag = [
type : 'success',
title: "Channel Created",
close: 'auto',
body : "The Channel have been successfully created"
]
Is it working?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you use this code, you still GET error 500?
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
testGetMethod(httpMethod: "GET") { MultivaluedMap queryParams ->
return Response.ok(new JsonBuilder([abc: 42]).toString()).build()
}
If so, are you able to get the error message? If not, please try to use app like Postman to send the request and get the response with error message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.