Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Testing POST request in Script runner console gets undefine variable error

serge calderara
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2020

Dear all,

I am actually testing the way to send POST request from script runner inside Script console from Jira.

The issue I have is that it says that some variable are not declare from beeing part of the request. Any idea how to solved it ?

Here is sample call I used below :

====> BEGININ CODE SAMPLE 

import groovy.json.*

import groovyx.net.*
import groovyx.net.http.*

import static groovy.json.JsonOutput.*

import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*

String targetUrl = 'https://login.microsoftonline.com/oauth2/token'
def http = new HTTPBuilder(targetUrl)

http.request(POST) {

requestContentType = URLENC

body = [from: 'fromAddress', to: 'toAddress', subject: 'sub', text: 'random message']

headers.'Authorization' = "Basic " + "api:my_api_key".bytes.encodeBase64().toString()
headers.'Accept' = 'application/json'

response.success = { resp, json ->
return prettyPrint(toJson(json))
}
}

Any idea why bold variable are reported as undefined in script console ?

Thanks for help on how solving

regards

 

0 answers

Suggest an answer

Log in or Sign up to answer