Hi all,
I'm trying to access my company's jira test instance through the JSON RPC services (as per https://developer.atlassian.com/display/JIRADEV/JIRA+JSON-RPC+Overview ) but I always get a negative response like
[id:null, error:[message:JSON-RPC requests must have the Content-type: application/json, data:null, code:-32600], jsonrpc:2.0]
even if I always send a "Content-Type" request header set to "application/json".
My JIRA instance has the JSON RPC plugin enabled. Moreover I get the same error trying to access https://jira.atlassian.com (although I don't know if that instance has json rpc enabled)
Here you are a groovy script that automates the login through JSON RPC on https://jira.atlassian.com: what's wrong with it?
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'https://jira.atlassian.com' )
// perform a GET request, expecting JSON response data
http.request (POST, JSON){
uri.path = '/rpc/json-rpc/jirasoapservice-v2'
uri.query = [
"jsonrpc" : "2.0",
"method" : "login",
"params" : ["user name","user password"],
"id" : 12345
]
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
headers.'Content-Type' = 'application/json; charset=UTF-8'
// response handler for a success response code:
response.success = { resp, json ->
println resp.statusLine
println " json : ${json}"
}
// handler for any failure status code:
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}
}
Cheers
Davide