V-Spark Online Help

Creating and Populating an Application Using cURL

While the /appedit API only enables you to download or upload the configuration of an existing application, you can combine JSON configuration data and calls to the /config/apps, /appedit, and /config/folders APIs to create an application, upload its configuration, and associate it with a folder. The following sample JSON defines an application named New AppEdit Test.

Figure 1. Sample JSON that defines an Application
{
    "Technologies": {
        "Technologies-RD": {
            "New AppEdit Test": {
                "created": "2017-10-10",
                "defaultscoretype": "Hit/Miss",
                "enabled": "on",
                "folders": [
                    "AutoTests"
                ],
                "template": "custom"
            }
        }
    }
}


When programmatically creating an application, populating it, and binding it to a folder, you must create the application before you can do either of the other two tasks. The next sample shows the JSON that associates a folder with the application that was defined previously.

Figure 2. Sample JSON that Associates an Application with a Folder
{
    "Technologies": {
        "Technologies-RD": {
            "AutoTests": {
                "apps": [
                    "New AppEdit Test"
                ],
                "custom_meta": [],
                "modelchan0": "eng1:callcenter",
                "modelchan1": "spa1:callcenter",
                "nspeakers": 2,
                "servers": [
                    "asrsrvr1",
                    "asrsrvr8"
                ]
            }
        }
    }
}


The next sample shows an abbreviated version of the JSON configuration of an application.

Figure 3. Sample JSON for an Application
{
    "Sample Top Level Category": {
        "phrases": {
            "+": {
                "all": [
                    "phrase usually found in all calls of this category"
                ]
            },
            "-": {
                "all": [
                    "phrase that shouldn't occur in calls of this category"
                ]
            }
        },
        "subcategories": {
            "Sample 2nd Level Category": {
              ...
            },
            "Sample 2nd Level Leaf Category": {
            ...
            }
        }
    },
    "Sample Top Level Leaf Category": {
        "phrases": {
           ...
        },
        "subcategories": {}
    }
}


Once you have JSON that provides information about these three aspects of an application, you can create the application, bind it to a folder, and define its configuration with three cURL calls like the following:

1
curl -s -X POST -H "Content-Type:application/json" \
    "http://example.company.com/config/apps?token=566af08d0d6ca7436c9117f09571cadc" \
     --data @app-definition.json

2
curl -s -X POST -H "Content-Type:application/json" \
    "http:///example.company.com/config/folders?token=566af08d0d6ca7436c9117f09571cadc" \
    --data @app-folder-binding.json 

3
curl -s -X POST -H "Content-Type:application/json" \
    "http:///example.company.com/appedit/Technologies/Technologies-RD/AppEdit%20Test?token=566af08d0d6ca7436c9117f09571cadc" \
    --data @app-configuration-sample.json        

The cURL commands in this example use the three sample JSON files shown previously to perform the following actions:

1

Calls the /config/apps API to create the application, using the contents of the file app-definition.json

2

Calls the /config/folders API to associate the new application with a specified folder, using the contents of the file app-folder-binding.json

3

Calls the /appedit API to upload the configuration of the application, using the contents of the file app-configuration-sample.json

While cURL provides a quick way to use and test REST APIs, and shell scripts are a quick and convenient way of automating many tasks, it is typically faster in the long run to call APIs from applications. The next topic discusses how to use the /appedit API from within applications that are written in the Python programming language.