I am running:
Jira Server 7.10
ScriptRunner 5.4.47
JMWE 5.7.1
I am attempting to make an API call from either Scriptrunner or JMWE script consoles to populate my DNS server in a post function, both of which return the following:
2019-06-14 11:57:24,167 http-nio-8080-exec-8 url:/secure/WorkflowUIDispatcher.jspa username:esmith WARN esmith 717x46053x1 4cyrf5 (IP_ADDRESS),10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.onresolve.jira.groovy] Failed = [error:Unauthorized]
I turned on ScriptRunner debugging and get the following additional lines:
2019-06-14 11:57:24,157 http-nio-8080-exec-8 url:/secure/WorkflowUIDispatcher.jspa username:esmith DEBUG esmith 717x46053x1 4cyrf5 10.233.231.47,10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.o.j.groovy.groovyrunner.spring] BeforeInstantiation [bean=com.onresolve.jira.groovy.GroovyFunctionPlugin, type=com.onresolve.jira.groovy.GroovyFunctionPlugin]
2019-06-14 11:57:24,158 http-nio-8080-exec-8 url:/secure/WorkflowUIDispatcher.jspa username:esmith DEBUG esmith 717x46053x1 4cyrf5 10.233.231.47,10.231.220.22 /secure/WorkflowUIDispatcher.jspa [c.o.j.groovy.groovyrunner.spring] AfterInitialisation [bean=com.onresolve.jira.groovy.GroovyFunctionPlugin, type=com.onresolve.jira.groovy.GroovyFunctionPlugin]
I have confirmed that I can make curl from the machine that is running Jira, and have also confirmed that the user running Jira can make a successful curl from command line
below is a copy of my code, JMWE says its fine, returns null in test. Scriptrunner barks about the API lines as being undefined but it compiles:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug statements"
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//Call the School URL field from the ticket
def schoolUrl_field = customFieldManager.getCustomFieldObject("customfield_12456")
// Get the value of the School URL field from schoolURL
def schoolUrl_value = issue.getCustomFieldValue(schoolUrl_field).toString()
//define CNAME entry based on School URL field first octet
def siteName = schoolUrl_value.tokenize(".")[0]
//Define domain based on the School URL field second octet
def siteDomain = schoolUrl_value.tokenize(".")[1]
//Get the value of the Shard field
def shard_field = customFieldManager.getCustomFieldObject("customfield_12454")
// Get the value of the Shard field from schoolURL
def shard = issue.getCustomFieldValue(shard_field).toString()
def http = new HTTPBuilder("http://(IP_ADDRESS):8080/api/v1/servers/localhost/zones/${siteDomain}")
def authString = "(AUTH_STRING_HERE)".getBytes().encodeBase64().toString();
http.request(PATCH, ContentType.JSON) {
requestContentType = ContentType.JSON
request.addHeader("X-API-KEY: ${authString}", "ContentType: application/json")
body = [ fields: "{\"rrsets\":\5[{\"name\": \"[siteName].\", \"type\": \"CNAME\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": \5[{\"content\": \"owsoo[shard].[siteDomain].com.\", \"disabled\": false}\5]}\5]}"]
response.success = { resp, JSON ->
log.warn("Successful = " + JSON)
}
response.failure = { resp, JSON ->
log.warn("Failed = " + JSON)
}
}
Any ideas why its failing?