Defining a web service interaction using XML to retrieve data from and send data to a Web Service

Defining a web service interaction using XML to retrieve data from and send data to a Web Service

Overview

The Web Service interface in a Data Connector applet enables you to retrieve data from and send data to an external web service. You define the interaction by writing XML directly in the Interaction Definition field. To use a pre-built configuration instead, see Using a template to retrieve data from and send data to a Web Service.

When a Data Connector applet uses a Web Service interface, it is sometimes referred to as a Web Service Data Connector (WSDC).

For more information about the Data Connector applet, see Data Connector applet.

JavaScript Engine uses a dedicated experience

The Web Service Data Connector is no longer used to define JavaScript Engine Data Connectors. These have been moved to their own dedicated experience. For more information, see Using the Vonage Contact Center JavaScript Engine.

Defining a web service interaction

  1. Create a Data Connector applet. For more information, see Creating an applet. A new Data Connector applet appears.

  2. In the Interface section, select Web Service. The Action and Web Service Interaction sections appear.

  3. In the Interface Failure list, select the applet to route the call to if the interface fails.

Interface failure vs. HTTP error status codes

An interface failure occurs when the Data Connector does not receive a response, for example, due to a timeout or a DNS lookup failure. This is different from receiving a response with an HTTP error status code.

  1. In the Action section, select Call Web Service. The Web Service Interaction section appears. The Interaction Definition field contains the following template XML:

<ApiInteraction> <Request> <Url></Url> <Method></Method> <Headers> <Header> <Key></Key> <Value></Value> </Header> </Headers> <Body><![CDATA[ ]]></Body> </Request> <Response> <Type></Type> <ResponseCodeDestination></ResponseCodeDestination> <Fields> <Field> <Locator></Locator> <Destination></Destination> <DataType></DataType> </Field> </Fields> </Response> </ApiInteraction>

For a complete example of a configured web service interaction, see Example web service interface.

  1. Define the request. Use the template XML as a basis and complete the following elements:

Request elements

XML element

Required or optional

Description

Example

XML element

Required or optional

Description

Example

Url

Required

The address of the web service. Must include the protocol (HTTP:// or HTTPS://).

<Url>http://myWebService.net/getData</Url>

Method

Required

The HTTP method. Supported values: GET, POST, DELETE, HEAD, PATCH, PUT.

<Method>POST</Method>

Headers

Optional (required if you define one or more Header elements)

All headers defined in this block are added as HTTP headers to the request.

  • Standard HTTP headers are supported, except: Expect, Proxy-Connection, Range, Transfer-Encoding.

  • Custom headers are also supported.

To authenticate with basic access authentication, send Base64-encoded credentials in the Authorization header: <Header><Key>Authorization</Key><Value>Basic EncodedCredentials</Value></Header>. Each Header must include a Key and a Value.

<Headers><Header><Key>Content-Type</Key><Value>application/json</Value></Header></Headers>

Body

Optional (not supported for GET or HEAD methods)

The body of the request. To include XML or JSON content, wrap it in a CDATA section (<![CDATA[ ... ]]>).

<Body><![CDATA[{"key":"value"}]]></Body>

Header elements

Complete the following elements for each Header in the Headers block:

XML element

Required or optional

Description

Example

XML element

Required or optional

Description

Example

Header

Optional (required if Headers is defined)

A single HTTP header, consisting of a Key and a Value.

N/A

Key

Required for each Header

The name of the HTTP header.

<Key>Content-Type</Key>

Value

Required for each Header

The value of the HTTP header.

<Value>application/json</Value>

You can insert Data Source or custom configuration values as placeholders in the Url, Key, Value, and Body elements. For more information, see Using a Data Source value in a Web Service Interface request or Using a custom configuration value in a Web Service Interface request.

  1. Define how to handle the response. Complete the following elements:

Response elements

XML element

Required or optional

Description

Example

XML element

Required or optional

Description

Example

Type

Required

The expected response format. Supported values: XML, JSON, TEXT, NONE.

  • Use TEXT when the response is not valid XML or JSON.

  • Use NONE when the response can be ignored.

When Type is TEXT, the response is stored in the Data Sources named in each field's Destination.

<Type>XML</Type>

ResponseCodeDestination

Required

The name of the Data Source in which to store the HTTP response code returned by the web service. Use this value in a subsequent applet, for example, a Data Router, to determine whether the interaction was successful. Any response code greater than 399 indicates a failure. For more information, see the List of HTTP status codes.

<ResponseCodeDestination>WebServiceResult</ResponseCodeDestination>

Fields

Optional (required if you define one or more Field elements)

Define one Field for each response value to store in a Data Source.

N/A

Field elements

Complete the following elements for each Field in the Fields block:

XML element

Required or optional

Description

Example

XML element

Required or optional

Description

Example

Field

Optional (required if Fields is defined)

A single response value to store in a Data Source, consisting of a Locator, Destination, and DataType.

N/A

Locator

Required for each Field when Type is JSON or XML

The location of the value in the response. For XML responses, use an XPath query. For JSON responses, use JSON dot notation.

For more information, see Defining JSON locators.

XML: <Locator>/response/client[@name="Key"]</Locator> JSON: <Locator>response.client.name</Locator>

Destination

Required for each Field

The name of the Data Source in which to store the returned value.

<Destination>WebServiceResult</Destination>

DataType

Required for each Field

The data type of the returned value. Must be one of: String, Integer, Decimal, Boolean, Time.

<DataType>String</DataType>

  1. Test the interaction before saving. For more information, see Testing your web service interaction definition.

  2. In the Successful Action list, select the applet to route the interaction to next.

Successful action and HTTP error codes

A successful action indicates that the web service returned a response. This includes responses with HTTP error status codes. To handle specific response codes, use the ResponseCodeDestination value in a subsequent Data Router applet.

  1. Click Update to save the configuration. Any configuration errors appear at the top of the page. The applet is not saved until all errors are resolved.

After saving:

  • If the web service returns a response, the interaction routes to the Successful Action applet.

  • If the web service does not return a response, the interaction routes to the Interface Failure applet.

Interaction Definition field: highlighting and autocomplete

The Interaction Definition field includes built-in editing tools to speed up configuration. The following features are available:

  • The field provides XML and JSON syntax highlighting as you type.

  • A list of available XML tags appears when you type <. Press Ctrl+Space to trigger the list manually.

  • Typing <! inserts a CDATA wrapper.

  • Matching XML tags, curly brackets, and square brackets are highlighted automatically.

  • Typing $ displays a list of available Data Sources. Typing # displays a list of available custom configuration keys.

  • The field supports standard text-editing shortcuts: Ctrl+A, Ctrl+C, Ctrl+X, Ctrl+V, Ctrl+Z, Ctrl+Y.

  • Press Ctrl+J to navigate to the closing XML tag of an element.

  • Press Ctrl+D to delete a line.

Support and documentation feedback

For general assistance, please contact Customer Support.

For help using this documentation, please send an email to docs_feedback@vonage.com. We're happy to hear from you. Your contribution helps everyone at Vonage! Please include the name of the page in your email.