Feedback

  • Contents
 

REST API Tools

As REST API uses standardized commands over a network connection using HTTP, there are many different tools you can use.

As with any feature in a CIC environment, Genesys recommends that you do adequate testing in a development instance to ensure that your implementation and method of using the REST API cover all necessary use cases.

Web browser extensions and plug-ins

Most modern web browsers have extensions or plug-ins that enable you to use REST APIs. Some of these items may not provide enough features, such as Digest Authentication or setting header content types, to be useful with Interaction Media Server REST API.

Search the repositories or stores of your specific web browser for available REST API client extensions or plug-ins.

Most web browser REST API tools prompt you for the REST API credentials when you send the request. As such, you do not have to generate an encrypted credentials token in the header of the request.

cURL command-line tool and library

The cURL command-line tool and library is an open-source project that enables you to transfer data using URL syntax. cURL is available for a wide variety of operating systems.

For more information about cURL and to download it, use the following website: http://curl.haxx.se/.

Windows PowerShell

Microsoft Windows PowerShell is an advanced terminal that uses the .NET Framework to provide advanced capabilities and functionality compared to the Command Prompt. You can create scripts and run commands from the terminal.

Important!

The Invoke-RestMethod command requires Windows PowerShell 3.0 or later. You can download the latest version of Windows PowerShell as part of the Windows Management Framework from http://www.microsoft.com.


Important!

In the following Windows PowerShell examples, you must substitute the text instances in bold italic font (username, password, uri) with information specific for your Interaction Media Server implementation and configuration, such as the configured REST API user name/password and the Fully Qualified Domain Name (FQDN) or IP address of the Interaction Media Server.

Sample GET script for Windows PowerShell

$cred = New-Object System.Management.Automation.PSCredential ("username", 
 
 
(ConvertToSecureString "password"  -AsPlainText -Force))
 
Invoke-RestMethod  http://uri:8102/api/v1/server/about -Method  Get -Credential $cred

Sample POST script for Windows PowerShell

$body = ConvertTo-Json @{ "TestProperty" = "TestValue" 
 
 }
$cred = New-Object System.Management.Automation.PSCredential ("username",
(ConvertToSecureString "password"  -AsPlainText -Force))
 
Invoke-RestMethod  http://uri:8102/api/v1/server/properties -Method  Patch - ContentType "application/json" -Credential $cred -Body $body

Programming languages

  • You can use compiled programming languages like C, C++, C#, Java, and others to create programs that communicate with the Interaction Media Server REST API.

  • You can use interpreted programming languages such as JavaScript, Python, and Ruby to create programs that communicate with the Interaction Media Server REST API.

  • You can integrate communication with the Interaction Media Server REST API in existing applications for which you have source code.

Python version 3.4 example for various GET requests

# Python 3.4
# ms-get.py
# This Python example uses the Requests HTTP library, which is documentedat
# http://docs.python-requests.org
# To install the Requests HTTP library for Python, execute
# 'pip install requests'
# Note: You must have an Internet connection to download and install the
# Requests library for Python.
import requests
from requests.auth import HTTPDigestAuth
import json
# This example uses the Colorama library to provide colors in the terminal,
# which is documented at https://pypi.python.org/pypi/colorama. To install 
 
 
the
# Colorama library for Python, execute 'pip install colorama'
from colorama import init, Fore, Back, Style
init()
# GET REST API URIs for Interaction Media Server about = "/api/v1/server/about" engstat = "/api/v1/server/enginestatus" props = "/api/v1/server/properties" parms = "/api/v1/server/parameters" cmdservs = "/api/v1/commandservers" deact = "/api/v1/server/deactivationstatus"
print(Style.BRIGHT + Fore.YELLOW + "---------------") print("Enter the FQDN or IP address of the Interaction Media Server   to query:") url = input("Interaction Media Server address: ")
print("") print("---------------") print("Enter the port number to use for the REST API call") print("Entering no value will use the default port 8102") port = input("Port: ") if ( port == "" ): port = "8102"
url = "http://" + url + ":" + port
print("---------------") print("Enter the number of the GET request that you want to execute:   ") print ("") print("1 - About") print("2 - Media engine statuses") print("3 - All properties") print("4 - All parameters") print("5 - Defined command (CIC) servers") print("6 - Deactivation status") print("") gettype = input("GET request: ")
list = ["1","2","3","4","5","6"] if (gettype not in list): print(Fore.RED + "ERROR: You must enter a valid   selection number!") quit() else: if ( gettype == "1" ): url = url + about if (gettype == "2"): url = url + engstat if (gettype == "3"): url = url + props if (gettype == "4"): url = url + parms if (gettype == "5"): url = url + cmdservs if (gettype == "6"): url = url + deact
print("---------------") # Prompt user to supply REST API user name and password myResponse = requests.get(url,auth=HTTPDigestAuth(input("Enter the   REST API user name: "), input("Enter the REST API password: ")), verify=True)
# For a successful Interaction Media Server REST API call, the response   code # will be 200 (OK). if(myResponse.ok):
print(Fore.GREEN + "---------------") print("Received information:") print("") print(json.dumps(myResponse.json(), indent=4))
else: # If response code is not ok (200), print the resulting http   error code with description myResponse.raise_for_status() # Reset colors and style of output terminal print('\033[30m')