First of all, create a new API Key Token:
- Create an API key: https://id.atlassian.com/manage/api-tokens#
- Combine the key with login name in base64 string, go to https://www.base64encode.org/
- Format is loginname:API-key exampel: email@example.com:ABCDE12345 give result: a3Jpc3Rlci5icm9tYW5AYWR2YW5pYS5zZTpBQkNERTEyMzQ1
- Combine this with the authentication type in the below case a basic so the full text is: Basic a3Jpc3Rlci5icm9tYW5AYWR2YW5pYS5zZTpBQkNERTEyMzQ1
Now we are ready to create the Workflow Postfunction with Scriptrunner for Jira Cloud.
import groovy.json.JsonBuilder def params = [ key: "TESTCONF", name: "Test Confluence", description: [ plain: [ value: "Space created automatically on " + new Date().format("dd/MMM/yyyy HH:mm"), representation: "plain" ] ] ] HttpResponse<JsonNode> response = Unirest.post("https://yourconfluence.atlassian.net/wiki/rest/api/space") .header("Authorization", "Basic xxx") .header("accept", "application/json") .header("Content-Type", "application/json") .body(new JsonBuilder(params).toString()) .asJson();
Remember to replace xxx in the code by the API Key...
401/403 errors are usually related to permission issues. Using the API key would not be enough, you will need to combine the key with the login name in base64 string for it to be successfully authorized.