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

« Previous Version 5 Current »

You need to have an active credential added to add-ons configuration if you don't have it please visit Add and activate credentia

Goal

Get number of Confluence spaces using a Confluence admin credential and compare it to same result without authentication.

0.Before we start

We created a credential with the key "myCredential" and we activated that. in our case since we're trying to authenticate as a Confluence admin, username and password should belong to a confluence admin

1.Confluence REST API to list Spaces

To see how we can use Credential to authenticate and get data we will use Confluence REST API, our Confluence running on a localhost using port 8090 so replace the base-url with your Confluence instance base-url

to get list of spaces we will send request to http://localhost:8090/rest/api/space the result will be following json

{ results: [ { id: 98305, key: "ds", name: "Demonstration Space", type: "global", _links: { webui: "/display/ds", self: "http://localhost:8090/rest/api/space/ds" }, _expandable: { metadata: "", icon: "", description: "", homepage: "/rest/api/content/65547" } }, { id: 98306, key: "SPAC", name: "SPACE", type: "global", _links: { webui: "/display/SPAC", self: "http://localhost:8090/rest/api/space/SPAC" }, _expandable: { metadata: "", icon: "", description: "", homepage: "/rest/api/content/65576" } } ], start: 0, limit: 25, size: 2, _links: { self: "http://localhost:8090/rest/api/space", base: "http://localhost:8090", context: "" } }

1.Create a new Confluence page (or edit and existing one) and add JavaScript Runner macro with following script inside its body

var spacesWithCredential=JSON.parse(http.get("http://localhost:8090/rest/api/space","myCredential"));
var spacesWithoutCredential=JSON.parse(http.get("http://localhost:8090/rest/api/space"));
out.element("h3","Space count:"+spacesWithCredential.size);
out.element("h3","Space count:"+spacesWithoutCredential.size);




  • No labels