Work with your REST Client

Because REST APIs use HTTP methods to send and receive content, you can work with them using any programming language or tool that supports sending and receiving HTTP messages. So, let's first choose a tool for making HTTP requests.

Considerations for Choosing a REST Client

You can choose among many clients that interact with Fusion Applications, such as:

  • A third-party standalone client, such as Postman or Advanced REST Client.
  • Your own custom standalone client. To implement a custom standalone client, see the sample implementation OracleMobileChat.
  • Your connecting application's client.
  • The cURL command-line utility.

You can use the client to do the following task:

  • Test the username, password, and request URL for your REST API account.
  • Construct and send various types of HTTP requests.

How You Send HTTP Requests Using cURL

In our examples, we use cURL, a popular command-line utility for transferring data using URL syntax, to send requests to REST services. cURL is available in most UNIX, Windows, and Macintosh environments. For details, see Installing the cURL Command-Line Tool on Windows.

The following table describes commonly used cURL options that you can use for REST services.

Option Description

-u

username:password

Specifies the user name and password for server authentication.

-d

Sends the specified data (a JSON request body) to the server. If you begin the data with the at sign (@), it must be followed by the file name to read the data from. For example, -d@example_request_payload.json

-H

Specifies an extra HTTP header in the request. To specify multiple headers, precede each header with the -H option.

Examples:
  • Authorization: Authentication Token
  • Content-Type: Format of Request Body (for example, with POST)
  • Accept: Format of Response Body

-o

<file>

Writes the output to a file instead of to standard output.

-X

Specifies the request method to use when communicating with the HTTP server. The default method is GET.

The following table includes Fusion Applications examples of REST API operations using cURL.

Operation cURL Command Example

Use POST to post a chat message to the agent

curl -X POST "https://chat_rest_server_domain.com/engagement/api/consumer/sdi_11_20_18_2022_21-3586727808788512-Fusion/v1/postMessage?pool=353:2" -H "Accept: application/json;charset=utf-8" -H "Content-Type: application/json" -H "SessionId: 170c233dfi4gy1vkwyw6yxdq1a" -d "{\"clientRequestTime\" : \"2019-01-14T14:35:14.226Z\",\"clientTransactionId\" : 1,\"body\" : \"This is a test message.\",\"offTheRecord\" : false}"

Use POST to retrieve the statistics of the engagement queue

curl -X POST "https://chat_rest_server_domain.com/engagement/api/consumer/sdi_11_20_18_2022_21-3586727808788512-Fusion/v1/getQueueStats?pool=353:2" -H "Accept: application/json;charset=utf-8" -H "Content-Type: application/json" -d "{\"queueId\" : 1,\"chatProactiveAvailableType\" : \"AGENTS\"}"

How You Send HTTP Requests Using Clients

You can use standalone clients, third-party browser extensions, or add-ons, such as the Advanced REST Client, to send HTTP requests.

The following table includes Fusion Applications examples of REST API operations using a client.

Operation Response/Payload Example

POST: Post a message.

Use POST with the following request URI and request body to post a chat message to the agent:

Request URL:

https://chat_rest_server_domain.com/engagement/api/consumer/sdi_11_20_18_2022_21-3586727808788512-Fusion/v1/postMessage?pool=353:2

Request Headers:

  • Accept: application/json;charset=utf-8
  • Content-Type: application/json; charset=UTF-8
  • SessionId: 170c233dfi4gy1vkwyw6yxdq1a

Request Body:

{
   "clientRequestTime" : "2019-01-14T14:35:14.226Z",
   "clientTransactionId" : 1,
   "body" : "This is a test message.",
   "offTheRecord" : false
}
{
    "clientRequestTime": "2019-01-14T14:35:14.226Z",
    "serviceStartTime": "2019-01-11T10:12:41.806Z",
    "serviceFinishTime": "2019-01-11T10:12:41.819Z",
    "clientId": 246,
    "clientIdString": "246",
    "clientTransactionId": 1,
    "clientTransactionIdString": "1"
}

POST: Retrieve queue statistics.

Use POST with the following request URI and request body to retrieve engagement queue statistics:

Request URL:

https://chat_rest_server_domain.com/engagement/api/consumer/sdi_11_20_18_2022_21-3586727808788512-Fusion/v1/getQueueStats?pool=353:2

Request Headers:

  • Accept: application/json;charset=utf-8
  • Content-Type: application/json; charset=UTF-8

Request Body:

{
   "queueId" : 1,
   "chatProactiveAvailableType" : "AGENTS"
}
{
    "clientRequestTime": null,
    "serviceStartTime": "2019-01-29T10:22:31.139Z",
    "serviceFinishTime": "2019-01-29T10:22:31.140Z",
    "clientTransactionId": 0,
    "clientTransactionIdString": "0",
    "queueId": 1,
    "queueIdString": "1",
    "expectedWaitSeconds": 0,
    "expectedWaitSecondsString": "0",
    "availableAgentSessions": 5
}