V-Spark Online Help

Using DELETE with Python and the /config API

Use the /config API to delete information about companies, organizations, folders, applications, and users.

This section provides sample Python code that shows how to delete all configuration information at a certain level of the product or a specific company, organization, folder, or application by specifying the full hierarchy of that object as part of the API that you specify on the command line for this application. You do not need to provide a JSON file as one of the arguments to the delete operation. Only the full path to the object that you want to delete is required.

Figure 1. Sample Python code to delete data using the /config API
#!/usr/bin/env python

# Copyright 2017 Voci Technologies All rights reserved.
# Contains confidential company information.
# Unsupported example code - Not for production use.

import sys
import requests

# default values
PROTOCOL =  "http://"
PORT =  "3000"

if ( len(sys.argv) != 6 ): 1
    print "  Usage:", sys.argv[0], "HOST ROOT_TOKEN API_TO_CALL TARGET_HTTP_CODE EXTRA_PARAMS"
    sys.exit(-1)
else:
    # get cmdline params
    HOST, ROOT_TOKEN, API_TO_CALL, TARGET_HTTP_CODE, EXTRA_PARAMS = sys.argv[1:]

# Define the URL in a single variable for JSON load 2
url =  "%s%s:%s%s?token=%s%s" % (PROTOCOL, HOST, PORT, API_TO_CALL, ROOT_TOKEN, EXTRA_PARAMS )

print "Deleting based on " + API_TO_CALL
print "  URL is ", url

response = requests.delete(url) 3
print '  SUMMARY (DELETE): ' + API_TO_CALL, ': HTTP message: ', response.reason, ' HTTP return code: ', str(response.status_code), ' expected ' + TARGET_HTTP_CODE    


The sample code shown previously is one of the applications that are used to help test the /config API that is discussed in this section. Therefore, its focus is on providing simple, linear code that shows how to delete data to a specified host. The major steps in this sample Python application are the following:

1

Check if the right number of command-line arguments have been provided, assign them to appropriate variables if so and identifying the expected arguments if not.

2

Assemble the URL that you will use to call the specified API. Remember that you have to pass the &multi=true parameter if you are trying to delete an object that contains multiple other objects, the &tree=true option if you are trying to delete an object that has one or more descendants, or both parameters if both of these are true.

3

Call the specified URL, and print a summary that identifies the API that the program called, the HTTP message and return code that the call returned, and prints the expected return code that you provided as a parameter.

Some examples of calling this Python script from the command-line are the following:

  • config-delete-tests.py example.company.com 123456789012345678901234567890123 /config/orgs 200 \
        "&multi=true&tree=true"          

    Enables you to delete the organizations from the V‑Spark installation of the host example.company.com using the root token 123456789012345678901234567890123, and also says that you expect that command to return success (HTTP error code 200). (The extra parameters are passed correctly to the Python script, which just appends them to the ?token parameter.)

  • config-put-tests.py example.company.com 123456789012345678901234567890123 \
        /config/DocTestCo/DocTestCo-DocTesting/Test01 200 ""

    Enables you to delete the folder Test01 from the docTestCo-DocTesting organization under the DocTestCo from the V‑Spark installation of the host example.company.com using the root token 123456789012345678901234567890123. The command also says that you expect that command to return success (HTTP error code 200).