REST API etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
REST API etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

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();     
    }

JIRA REST API - Edit Issues


  • When you want to update a field with JIRA REST API, first write it i json format.  Ex: I want to update the summary of an issue.        
  • {"fields": {"summary":{"name":"bahar"}}}
  •  You can try it with curl commant whether it works or not.
  •   curl -D- -X PUT -H "Authorization: Basic YWRtaW46SDF0MXQ=" --data "{\"fields\":{\"summary\":\"bahar\"}}"   -H "Content-Type: application/json" "http://localhost:8080/rest/api/2/issue/TAI-9"
  •  You should use PUT for updating.
  • Don't forget to add "\" backslash  before the double quotes.
  • You should encode your username:password with base 64 encode.
  • encoder 
  • write your username:password, and the output will be "YWRtaW46SDF0MXQ= " something like this. Write the output to the authorization. 
  • Ex: "Authorization: Basic YWRtaW46SDF0MXQ="  
  • "http://localhost:8080/rest/api/2/issue/TAI-9" is the issue that you want to update.
  •   You can do the same thing with java code.Here is the method:   
     public static String updateSummary() throws IOException {
     
        URL url = new URL("http://localhost:8080/rest/api/2/issue/TAI-9");
        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("PUT");
        conn.setRequestProperty("Content-Type", "application/json");
       
        conn.connect();
      
        String st="{\"fields\":{\"summary\":\"bahar\"}}"; 

        byte[] outputBytes = st.getBytes("UTF-8");
        OutputStream os = conn.getOutputStream();
        os.write(outputBytes);
        os.flush();
       
        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();
        return sb.toString();

    }                                                                                                                               

  • you can use Base64Convertor.java class. Download
  • Here is the atlassian documentation for updating issue via JIRA REST API. atlassian