27 Kasım 2012 Salı

JIRA REST API - Updating Status

You can change a status with executing the transition.

  • You should give the transition id. "{transition\": {\"id\": \"61\"}"
  • The url should be :  "http://localhost:8080/rest/api/2/issue/TAI-39/transitions?expand=transitions.fields" SElect the issue that you want to update.
  • You shoul use "POST"
  • Here is the curl command: curl -D- -X POST -H "Authorization: Basic YWRtaW46SDF0MXQ=" --data "{\"transition\": {\"id\": \"81\"}}" -H "Content-Type: application/json" "http://localhost:8080/rest/api/2/issue/TAI-39/transitions?expand=transitions.fields"
  • Here is the java implementation:          
  •                                                                
    public static String httpGet() throws IOException {         
    URL url = new URL("http://localhost:8080/rest/api/2/issue/TAI-39/transitions?expand=transitions.fields");         
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
    conn.setDoOutput(true);         
    conn.setDoInput(true);                 
    String credentials = "username" + ":" + "password";        
     String encoding = Base64Converter.encode(credentials.getBytes("UTF-8"));   
    conn.setRequestProperty("Authorization", String.format("Basic %s", encoding));  
    conn.setRequestMethod("POST"); 
    conn.setRequestProperty("Content-Type", "application/json");    
      conn.connect();                  
     String st = "{\"transition\": {\"id\": \"91\"}}";    
     System.out.println(st);      
      byte[] outputBytes = st.getBytes("UTF-8");     
     OutputStream os = conn.getOutputStream();  
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));        
     StringBuilder sb = new StringBuilder();        
     String line;         
    while ((line = rd.readLine()) != null) {           
    sb.append(line);         
    }         
    rd.close();             
    conn.disconnect();        
    System.out.println("sb: "+ sb.toString());         
    return sb.toString();     
    }

Hiç yorum yok:

Yorum Gönder