Skip to main content
Skip table of contents

Valsight API Client

Valsight ships a tool to simplify programming against the API. It handles cookie authentication and provides useful methods to access objects as well as many default java & groovy methods to simplify the handling of JSON responses. Its only requirement is a JRE with Version 8+.

Of course, you can also use any other tool to access the REST based API.


To download the client, contact the Valsight Support at support@valsight.com .

Running the Valsight Client

CODE
java -jar valsight-client-launcher-x.x.jar <script-file> (-s <server-url> | --serverless) ([-u <username> -p <password>] | [-u <username> -k <API key>]) <other-script-args>


Example script

GROOVY
import groovy.json.JsonOutput
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.CommandLineParser
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.Options

// static imports are required for autocompletion

import static com.valsight.rest.ScriptDelegate.client
import static com.valsight.rest.ScriptDelegate.log

// Variables/environment passed to the script:
//
// ValsightRESTClient client: a connected/logged in ValsightRESTClient instance (unless --serverless mode is specified)
// String[] args: the list of all script arguments
// Logger log: a logger with the name of the script



// Example: parsing command line arguments
// The script is passed all remaining command line arguments after the script launcher
// has processed its arguments (e.g. server url / username)
// You can use any mechanism to parse the args, commons-cli is in the classpath and is recommended

log.info "All args: ${args}"

Options options = new Options()
options.addOption('project', 'project-key', true, '')

CommandLineParser parser = new DefaultParser()
CommandLine cmd = parser.parse(options, args)

log.info "Options/flags: ${cmd.options.collectEntries { [it.opt, it.value] }} "
log.info "positional arguments: ${cmd.args}"

// Example: using the ValsightRESTClient object

List projects = client.findAllProjectSpaces()
String projectFilter = cmd.getOptionValue('project')
if (projectFilter  != null) {
    projects  = projects.findAll { it.businessKey.equals(projectFilter) }
} else {
    log.error "Please specify a project."
    System.exit(1)
}
Long projectID = projects[0]['id']
String projectName = projects[0]['name']
String projectKey = projects[0]['businessKey']

log.info "Working on Project $projectName (Key: $projectKey, ID: $projectID)"

// For more convenient method calls on client, you may use the standard Groovy .with {}


log.info "The following models and nodes are found in the project"

client.with {
    getObjects('models',['project':projectID ]).each { model ->
        log.info  model['name']
        log.info "Status: "
        log.info client.getPath("models/${model['id']}/validate").isEmpty() ? '  Valid' : "  Invalid: ${client.getPath("models/${model['id']}/validate").toString()}"
        model['nodes'].each { nodeId ->
            log.info "  " + getObject('nodes', nodeId)['name']
        }
    }
    log.info "The following datasources are available"

    getObjects('externalDataSources',['project':projectID ]).each { ds ->
        log.info "  ${ds['name']}  (${ds['id']})"
        log.info "Status: " + client.getPath("externalDataSources/${ds['id']}/status").toString()
    }

}







JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.