Feedback

  • Contents
 

Supported VXML Data Elements

The <data> element enables a VoiceXML application to fetch or post data to a document sever without transitioning to a new VoiceXML document. The VXML2.1 specification defines the attributes supported by the <data> element. The “enctype” attribute represents the encoding or MIME type of the document submitted to the document server.

PureConnect supports two JSON encoding types ("enctype" attributes) to be used with the <data> element: “application/json” and “application/json-inin”. PureConnect also supports using the PUT HTTP request method with the <data> element. The content sent by the VoiceXML interpreter in this context is identical for the POST and PUT methods, which are described together.

JSON Data Elements

The two similar but different JSON enctype data elements provide support for the VoiceXML document to have complete control of the JSON in the body, depending on the requirements of the webservice the application is working with. The primary difference between these two encoding types is the following:

JSON enctype Description
application/json The JSON body is constructed automatically using the ECMAScript variable names specified in namelist attribute, along with the data in those variables. Use this for the simple case where the variable names in the script are also valid for urlencoding and can be passed through to the webservice. If the variable names should not be passed through, use the application/json-inin enctype.
application/json-inin The JSON body consists of the data from the first ECMAScript variable named in the namelist attribute (which is assumed to be a string containing properly formatted JSON). Use this when you want to pass the data but not the script variable names to the webservice. In this case, you must provide the data in well formed JSON format.

Content for the "application/json" enctype

When the interpreter traverses a <data> element with “application/json” encoding type, it creates a single object containing a member for each variable, whether using the POST or PUT method. The member names are the variable names and member values are the corresponding variable values. When the interpreter sends the POST or PUT request, the request body contains that internal object converted to string. Note that variable names in the “namelist” attribute of the <data> element are submitted in this case to the document server.

For example, assume a script defines the following variables:

var person1 = {

    firstName: ”Bob”,

    lastName: ”Smith”,

    age: 32

};

var location1 = {

    city: ”Indianapolis”,

    state: ”Indiana”

};

When the interpreter traverses the following <data> element:

<data src=”http://www.example.org” method=”post” enctype=”application/json” namelist=”person1 location1”/>

the interpreter sends to the server located at URI “http://www.example.org” an HTTP POST request with the following body:

{

    ”person1”: {

        ”firstName”: ”Bob”,

        ”lastName”: ”Smith”,

        ”age”: 32

    },

    ”location1”: {

        ”city”: ”Indianapolis”,

        ”state”: ”Indiana”

    }

}

Content for the "application/json-inin" enctype

When the interpreter traverses a <data> element with “application/json-inin” encoding type, it sends as content of the POST or PUT request the content of the variable specified, with a "namelist" attribute having the name of an ECMAScript variable. Note that the name of the variable in the “namelist” attribute of the <data> element is not submitted in this case to the server.

For example, assume a script defines the following variable:

var person2 = '{ ”firstName”: ”Bob”, ”lastName”: ”Smith”, ”age”: 32}';

When the interpreter traverses the following <data> element:

<data src=”http://www.example.org” name=”response” method=”put” enctype=”application/json-inin” namelist=”person2”/>

the interpreter sends to the server located at URI “http://www.example.org” a PUT request with the body equivalent to:

{ ”firstName”: ”Bob”, ”lastName”: ”Smith”, ”age”:32 }