Skip to content

Quick Start in Javascript

Start up with the TACTIC API quickly

For the purposes of this documentation, we will be using the TACTIC Portal. The URL to access any project in this server will be the of the following format:

Project URL:

https://portal.southpawtech.com/<MY_SITE>/<MY_PROJECT>

where:

  <MY_SITE> will be replaced by your organization code
  <My_PROJECT> will be replaced by the project you wish to access

In this tutorial, we will be using trial site and api_test project. The URL will be:

https://portal.southpawtech.com/trial/api_test/

Quick start example in REST

The example in this tutorial uses Javascript API. Here is the same example using REST API.

Start an HTML page

Start a simple HTML page:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Test App</title>
</head>

<body>
    <div id="jobs">Hello, no jobs yet!</div>
</body>

</html>

Importing the API file

The first step is to import the tactic.js file:

<script src="https://portal.southpawtech.com/context/spt_js/tactic.js"></script>

Our HTML file looks like this now:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Test App</title>
</head>

<body>
    <div id="jobs">Hello, no jobs yet!</div>
    <script src="https://portal.southpawtech.com/context/spt_js/tactic.js"></script>
</body>

</html>

Initialize the server stub

We will initialize the server stub using the following information:

let server_url = "https://portal.southpawtech.com"
let site = "trial"
let project = "api_test"
let user = 'trial_api'
let password = 'tactic123'

let server = TACTIC.get();
server.set_server(server_url)
server.set_site(site)
server.set_project(project)

Our HTML file:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Test App</title>
</head>

<body>
    <div id="jobs">Hello, no jobs yet!</div>

    <script src="https://portal.southpawtech.com/context/spt_js/tactic.js"></script>
    <script>

        let server_url = "https://portal.southpawtech.com"
        let site = "trial"
        let project = "api_test"
        let user = 'trial_api'
        let password = 'tactic123'

        let server = TACTIC.get();
        server.set_server(server_url)
        server.set_site(site)
        server.set_project(project)

    </script>

</body>

</html>

Generate API ticket

In order to access TACTIC, you must have an access ticket. This token is required for any access to a TACTIC server and is issued by the server upon successful authentication.

As a first step, we have to generate an API ticket which will be attached to a user. This API ticket will have the same execute permissions on the TACTIC server as the user. You can either pre-create the ticket on the TACTIC server or you can use the API to generate one:

With the API command, get_ticket, you can generate a new ticket:

// Add API Ticket
let ticket = server.get_ticket(login, password)

This method is useful for login screen when a user is asked to authenticate.

This ticket should be stored somewhere safe. For a browser, it is typical to store this in a cookie or local storage object.

Please test this function in the HTML file we created above. You can print out the ticket in the console.

Test the connection

alert(server.ping())

An alert popup with the message "OK" should appear. If you see this popup, then, congratualtions, you have successully connected and are authenticated on the TACTIC server. This means that the server stub is ready to relay commands.

You can test this in the HTML file we created above.

Simple query

The query method will select all the sobjects of the given type:

let jobs = server.query("workflow/job")

This will return a list of dictionaries containing the information for each searchable object (sObject). You can test this command in displaying the jobs from the TACTIC server in the following section.

Displaying the jobs

We will display the jobs in our HTML page. We will only display the code of each job for now. Please note that in this example, we are using query expression to retrieve jobs. You could also use the query method described above in the previous section.

let jobs = server.query("workflow/job")

OR

let expr = "@SOBJECT(workflow/job)";
let jobs = server.eval(expr);

Note that the above commands will retrieve all the jobs from the server.

Here is the whole HTML file:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Test App</title>
</head>

<body>
    <div id="jobs">Hello, no jobs yet!</div>

    <script src="https://portal.southpawtech.com/context/spt_js/tactic.js"></script>
    <script>

        let server_url = "https://portal.southpawtech.com"
        let site = "trial"
        let project = "api_test"
        let user = 'trial_api'
        let password = 'tactic123'

        let server = TACTIC.get();
        server.set_server(server_url)
        server.set_site(site)
        server.set_project(project)

        try {
            let ticket = server.get_ticket(user, password);
        } catch(e) {
            alert("Error:", e)
        }

        let expr = "@SOBJECT(workflow/job)";
        let jobs = server.eval(expr);
        console.log(jobs);
        let results = "";
        for (i = 0; i < jobs.length; i++) {
            var currJob=  jobs[i];
            results += "job code: " + currJob['code'] + '<br/>'
        }
        document.getElementById('jobs').innerHTML = results;
    </script>

</body>

</html>

Note

You can try it in jsfiddle

This example uses the expression language to easily query TACTIC. The expression is a simple language that allows you to do complex queries without having to know how tables relate to each other.

Congratulations.

You have created your first web app that uses TACTIC as a backend server. At this point, you have the full TACTIC API at your disposal to run workflows and manage digital assets.