webCOMAND

Web Services Tutorial

This tutorial builds on the Content Types tutorial to illustrate how to get, put and delete objects in a COMAND repository from remote code and applications.

Getting Started

In order to access and update a COMAND repository from remote code, the Web Services Login Policy must be installed and a valid User Token added.

Install Web Services Login Policy

The Web Services Login Policy must be installed before a User can be assigned access to Web Services and associated with a User Token.

The Web Services Login Policy is preinstalled on webcomand.com accounts, but it won't hurt to reinstall it.
  1. Launch the Content Manager (CMS) App.
  2. In the folder tree on the left, click the System folder.
  3. Click import (Import Button) in the toolbar at the top of the right panel.
  4. Click "From URL" and enter:
    file:///var/www/webcomand/packages/io_comand_webservice/install/login.js
  5. Click Import.

Add a Web Service User and Token

Once the Web Services Login Policy is installed, a User and User Token can be created to provide controlled access to the repository.

  1. Launch the Users App.
  2. Add a new User with the authorizations required to access and update content as needed.
    • Click Add (New Option) in the top-left.
    • Enter a Username like: ws_user
    • Enter your Email.
    • Click the Manage tab.
      • Check "Active"
      • For the Login Policy, uncheck "webCOMAND Login Policy" and check "Web Services Token Authentication Policy".
    • Click the Authorizations tab.
      • If this is just a test account, simply check System Administrator.
      • If security is a concern, select appropriate User Roles, or assign specific Content Access and Privileges.  For this tutorial, make sure the user has the following authorizations.
        User Content Access
      • Read Folder Access to the root folder.
      • View, Edit, Add, Unlink and Inherit Content Type Access to desired content types within the root folder.  Inherit applies access to content in all subfolders, as well as content not in a folder.  For this tutorial, we will provide access to Presidents.
        User Privileges
      • Capabilities, Delete, Get and Put Services for COMAND Core Web Services Call Privileges.
    • Click Approve.
  3. Add a User Token for the new user.
    • Launch the API App.
    • Open a new Web API Call > Get Service.
    • Create TokenClick the Create button to the right of the Token option.
    • Select the User created in the previous step.
    • Click Create.

Get Web Service

The Get Web Service is used to query a repository and access content.  You can use the API App or Postman to easily test the Get Web Service.

API App

  1. Enter the Query:
    FROM President
  2. Click Process.

The web service response JSON will be displayed to the right.  Notice the default (non-image and file) fields and metadata in the results.

API App - President Query

To refine the results, add a SELECT clause to the query.

  1. Update the Query:
    SELECT Number, Name, Photo FROM President
  2. Click Process.

Notice only the selected fields are included in the results.

API App - President Query 2

Postman

To query the Get Web Service from your local computer, you can use any programming language, front-end framework, wget, curl  or an app like Postman .  We'll use Postman for a more visual example here, but the same information applies to all options.

  1. Launch Postman.
  2. Open a request tab.
  3. Enter the GET URL (replace <account> with your account):
    https://<account>.webcomand.com/ws/get
  4. Enter the Query Parameter Key:
    query
  5. Enter the Query Parameter Value:
    SELECT Number, Name, Photo FROM President
  6. Click the Headers tab.
  7. Enter the Header Key:
    Authorization
  8. Enter the Header Value (replace <token> with your token):
    Token <token>
  9. Click "Send".

Postman - President Query

For more information, see the Get Web Service.

Put Web Service

Use the Put Web Service to add and update content to the repository.  We will use the API App here, but you can use any tools described above here as well.

  1. Switch back to webCOMAND in your web browser.
  2. Click New Tab and select Web Service > Put Service
  3. Enter cJSON into the Data field.  For example:
    {
        "type": "COMAND",
        "version": "1.0",
        "contents": [{
            "Type": "President",
            "Number": "45",
            "Name": "<Your Name>",
            "Photo": {
                "type": "url",
                "value": "https://www.webcomand.com/docs/img/help/profile.png"
            }
        }]
    }
    
  4. Select the Token created in the previous section.
  5. Click Options and enter the Parent "/Bases/Presidents".
  6. Click Process.

The response JSON will be displayed to the right.  Notice the OID of the new President is included in the response.

For more information, see Put Web Service.

Delete Web Service

Use the Delete Web Service to remove content from the repository.  We will use the API App here, but you can use any tools described above here as well.

  1. Click New Tab and select Web Service > Delete Service.
  2. Enter the Query:
    FROM President WHERE Number=45
  3. Select the Token created in the previous section.
  4. Click Process.

The response JSON will be displayed to the right.

For more information, see Delete Web Service.