First of all, create a new API Key Token:

  1. Create an API key: https://id.atlassian.com/manage/api-tokens#
  2. Combine the key with login name in base64 string, go to https://www.base64encode.org/ 
  3. Format is loginname:API-key exampel: email@email.com:ABCDE12345 give result: a3Jpc3Rlci5icm9tYW5AYWR2YW5pYS5zZTpBQkNERTEyMzQ1
  4. 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();

Some notes:

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.

By MrAddon.

.

Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s