Hosting
CLOUD
Problem
Use Projectrak REST API from ScriptRunner console.
Solution
First of all, Projectrak and Scriptrunner for Cloud, have to be installed in a Jira instance.
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.Create ScriptRunner variables:
Store the Projectrak API token Id & Password as variables. Also the Projectrak API base URL: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.