Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Hosting

CLOUD

Problem

Use Projectrak REST API from ScriptRunner console.

Solution

  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:

    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 -> 
                    logger.info("Project ${item.project.name}")
    }
    
    return "Done!"

    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.




  • No labels