Validating a Spacekey in a blueprint


I am new to developing the confluence plugins. I have a space plugin that is creating new spaces from template.

I am trying to figure out how to use the java script to validate that the space key does not already exist.

Any help would be appreciated


Easiest way is to call the rest API via AJAX and if result is empty, no space exist with this key.
Exemple :

function existProject(spaceKey) {
            url: AJS.contextPath() + "/rest/api/space?spaceKey=" + spaceKey,
            type: "GET",
            dataType: "json",
            success: function (response) {
                if (response.size > 0) {
                    //Manage error here
                } else {
                   //Manage success here


That helps a lot.