Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. First of all, Projectrak and Scriptrunner for Cloud, have to be installed in a Jira instance.

  2. A Projectrak API token is needed in order to make REST calls.
    If you don’t have one yet, please create one. But if you have already got it, you can reuse it.

  3. Create ScriptRunner variables:
    Store the Projectrak API token Id & Password as variables. Also the Projectrak API base URL:

    imagen-20240318-082301.png

  4. Open the Scriptrunner console and insert the following code example:

    Code Block
    def apiKeyCredentials = [name: "${PROJECTRAK_API_TOKEN_ID}", password: "${PROJECTRAK_API_TOKEN_PASSWORD}"];
    
    Map<String, Object> response = post("${PROJECTRAK_API_BASE_URL}/api-keys/jwt")
          .header("Content-Type","application/json")
          .body(apiKeyCredentials)
          .asObject(Map).body;
          
    def jwt = response.jwt;
    response = get("${PROJECTRAK_API_BASE_URL}/search/projects")
                .header("Authorization", "Bearer ${jwt}")
                .queryString('size', '2')
                .asObject(Map).body;
                
    def projects = (List<Map<String, Object>>) response.projects.values
    projects.each { item ->def project = projects.get(0).project;
    def fieldId = <fieldId>;
    
    response = get("${PROJECTRAK_API_BASE_URL}/values/projects/${project.id}/fields/${fieldId}")
                .header("Authorization", "Bearer ${jwt}")
            logger.info(    .asObject(Map).body;
    def projectField = response;
                
    return "Project '${item.project.name}")
    }
    
    return "Done!"' '${projectField.field.name}' field value: ${projectField.value.value.value}"

    This simple example gets a valid JWT using the API key credentials and then makes a call to fetch all the Jira instance projects and log their names in the console.
    Please, set the “<fieldId>” with the desired one from the Projectrak Field manager.

...