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
.
{ "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.
{ "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.
{ "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:
Calls the
/config/apps
endpoint to create the application, using the contents of the file app-definition.json.curl -s -X POST -H "Content-Type:application/json" \ "http://example.company.com/config/apps?token=566af08d0d6ca7436c9117f09571cadc" \ --data @app-definition.json
Calls the
/config/folders
endpoint to associate the new application with a specified folder, using the contents of the file app-folder-binding.json.curl -s -X POST -H "Content-Type:application/json" \ "http:///example.company.com/config/folders?token=566af08d0d6ca7436c9117f09571cadc" \ --data @app-folder-binding.json
Calls the
/appedit
endpoint to upload the configuration of the application, using the contents of the file app-configuration-sample.json.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
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.