webCOMAND

repo.get()

Makes a Get Web Service request and returns the results or full response, depending on the specified options.

Prototype

mixed get(mixed data = null, function callback = null)

Parameters

  • data - A cPath, cQL or cQuery string or object with the same optional property/value pairs accepted by the Get Web Service.  The most common two are:
    • query - cPath, cQL or cQuery string, provide here as the main data parameter, so other optional properties can be specified.
    • token - The authorization token to make requests to the server.  This is not necessary if the token was specified when creating the repo object with comand.repo().
  • callback - Optional callback to receive the following two parameters once the response to the asynchronous request is received.  If not specified, the request will be performed synchronously and the response contents will be returned once the response is received, or false on failure.

Synchronous String Example

The following example web page uses the JavaScript API to retrieve and display a list of contacts synchronously.  That is, the call to repo.get() will wait until a response is received and then return the results.

<html>
<head>
    <title>Contacts</title>
</head>
<body>
<h1>Contacts</h1>
<script src="https://<account>.webcomand.com/ws/js/comand.js"></script>
<script>
    // write your inline code here, like:
    var repo = comand.repo({token: '<token>'});
    var contacts = repo.get('FROM Contact ORDER BY LastName, FirstName');
    document.writeln('<ul>'); 
    contacts.forEach(function(contact) {
        document.writeln('<li>' + contact.FullName + '<li>');
    });
    document.writeln('</ul>');
</script>
</body>
</html>

Asynchronous String Example

The following example web page uses the JavaScript API to retrieve and display a list of contacts asynchronously.  That is, repo.get() will immediately return the XMLHttpRequest object, and later call the specified callback function once the response is received (aka AJAX).

<html>
<head>
    <title>Contacts</title>
</head>
<body>
<h1>Contacts</h1>
<script src="https://<account>.webcomand.com/ws/js/comand.js"></script>
<script>
    // write your inline code here, like:
    var repo = comand.repo({token: '<token>'});
    var contacts = repo.get('FROM Contact', function(data){
        data.contents.forEach(function(contact) {
            document.body.insertAdjacentHTML(
                'beforeend',
                contact.FullName + '</br>'
            );
        });
    });
</script>
</body>
</html>

Asynchronous Object Example

Similar to the previous example, except an object is passed as the first parameter to repo.get() to specify a number of options.

In this case, the authorization token is specified in the get request, instead of as an Authorization header, which is how it is sent when provided to comand.repo().  While this is not the recommended approach, it does eliminate the need for a web browser to make an initial CORS preflight request.
<html>
<head>
    <title>Contacts</title>
</head>
<body>
<h1>Contacts</h1>
<script src="https://<account>.webcomand.com/ws/js/comand.js"></script>
<script>
    // write your inline code here, like:
    var repo = comand.repo();
    var contacts = repo.get({
        query: 'SELECT OID, FullName FROM Contact ORDER BY LastName',
        binaryFormat: 'base64',
        token: '<token>'
    }, function(data){
        data.contents.forEach(function(contact) {
            document.body.insertAdjacentHTML(
                'beforeend',
                contact.FullName + '(OID ' + contact.OID + ')</br>'
            );
        });
    });
</script>
</body>
</html>