Quick Start

You can make many types of HTTP requests using Oracle REST APIs. You can easily make requests to view, create, update, or delete information. So, let's first send a REST HTTP request to create a chat engagement.

Step 1: Consider Before You Start

Review the basics. If you're new to REST APIs, make sure you understand the basics of REST and JSON, and scan our list of important terms.

Review roles and privileges: You must have necessary security roles and privileges to use the GET, POST, PATCH, and DELETE methods on your parent and child resources.

Choose a client. REST APIs connect software programs over the HTTP protocol. You need a software client to send the HTTP requests. In our examples, we use cURL. But, cURL isn't the only tool you can use. To help you choose one, see Work with your REST Client.

Step 2: Get Your Oracle B2C Service Account Info

Based on your usage, click on one of the following links:

Gather Account Info for Agent API

To make a REST HTTP request, you need to gather a few bits of information:

  • Server URL. The server on which the agentTokens endpoint is hosted. For example:
    https://service_cloud_server.com
  • User name and password. An Oracle Cloud service user with permissions to access the agentTokens endpoint.

You can find the REST server URL and credentials in the welcome email sent by your Oracle Cloud service administrator.

Gather Account Info for Consumer API

To make a REST HTTP request, you need to gather a few bits of information:

  • Server URL. The server on which the establishSessions endpoint is hosted. For example:
    https://service_cloud_server.com
  • User name and password. An Oracle Cloud service user with permissions to access the establishSessions endpoint.

You can find the REST server URL and credentials in the welcome email sent by your Oracle Cloud service administrator.

Step 3: Authenticate

Based on your usage, click on one of the following links:

Authenticate for Agent API

For creating a chat engagement as an agent, you need a JSON Web Token (JWT) for authentication. You need to specify this JWT as a Bearer Authorization header in your request to create a chat engagement as an agent.

You can determine this JWT by invoking the agentTokens endpoint in B2C Service using the Basic Authorization header to specify the credentials (from Step 2). The JWT is returned in the response of the agentTokens call. To know more about the agentTokens endpoint, see About Agent Tokens.

The cURL command to establish a session and retrieve the JWT is as follows:

curl -X POST https://service_cloud_server.com/services/rest/crossChannelServices/latest/agentTokens -u '<username>:<password>' -H 'OSvC-CREST-Application-Context: For testing api' -d '{}'

In a client such as Postman, you enter the user name and password in the Authorization tab. This screenshot shows how to specify this information in Postman:

Postman example with basic authentication for Agent API

If the authentication is successful, the JWT (sessionToken) is returned in the response as follows:

{
"sessionToken": "eyJhbGciOiJSU...Wst7gbQ6Nqs",
    "links": [
        {
            "rel": "describedby",
            "href": "https://service_cloud_server.com/services/rest/crossChannelServices/latest/metadata-catalog/agentTokens",
            "mediaType": "application/schema+json"
        }
    ]
}

Authenticate for Consumer API

For creating a chat engagement, you need a JSON Web Token (JWT) for authentication. You need to specify this JWT as a Bearer Authorization header in your request to create a chat engagement.

You can determine this JWT by invoking the establishSessions endpoint in B2C Service using the Basic Authorization header to specify the credentials (from Step 2). The JWT is returned in the response of the establishSessions call. To know more about the establishSessions endpoint, see About Establish Sessions.

The establishSessions response also returns the following values that are required in the request for creating a chat engagement:

  • Domain. The domain URL of your Oracle B2C Service Chat service. For example, https://chat_rest_server_domain.com.
  • Site Name. The name of the site returned in the response of the establishSessions call.
  • Port. The port value is returned only if the port is not a default port, such as 80 or 443.
  • Pool ID. The pool ID that is configured for the site. The pool ID indicates the ID of the cluster where the chat service is running. Oracle may alter the pool ID during scheduled/un-scheduled maintenance.

The cURL command to establish a session and retrieve the JWT is as follows:

curl -X POST https://service_cloud_server.com/services/rest/crossChannelServices/latest/establishSessions -u '<username>:<password>' -H 'OSvC-CREST-Application-Context: For testing api' -d '{"sessionInformation": "{\"emailAddress\" : \" john.smith@vision.com\", \"firstName\" : \" John\", \"lastName\": \" Smith\", \"customFields\" : [{\"name\" : \"location\", \"type\" : \"string\", \"value\" : \" 401 Island Parkway Redwood Shores CA 94065 USA\"}], \"question\" : \"Refunds Issues\", \"auxiliaryData\" : {\"BROWSER\" : \"Mobile Safari 11.0\", \"OPERATING_SYSTEM\" : \"iPhone OS\", \"USER_AGENT\" : \"Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1\"} }"}'

Note:

  • The customer metadata is specified using -d option in the cURL command.
  • The auxiliaryData metadata field is a map of key-value pairs and the following are the permitted keys:
    • BROWSER. The corresponding value indicates the browser used by the end user.
    • OPERATING_SYSTEM. The corresponding value indicates the operating system used by the end user.
    • USER_AGENT. The corresponding value indicates the user agent of the browser used to make the HTTP request.

In a client such as Postman, you enter the user name and password in the Authorization tab. This screenshot shows how to specify this information in Postman:

Postman example with basic authentication for Consumer API

If the authentication is successful, the JWT (channelToken), domain, site name, port, and pool ID are returned, as applicable, in the response as follows:

{
"channelToken": "eyJhbGciOiJSU...Wst7gbQ6Nqs",
    "sessionServerResponse": "{\"domain\":\"chat_rest_server_domain.com\" ,\"pool\":\"297:1\"}",
    "siteName": "day119_181100_sql_238h",
    "links": [
        {
            "rel": "describedby",
            "href": "https://service_cloud_server.com/services/rest/crossChannelServices/latest/metadata-catalog/establishSessions",
            "mediaType": "application/schema+json"
        }
    ]
}

Step 4: Configure Your Client

With the information gathered so far, you're ready to configure your client to send a REST HTTP request.

  1. Construct the request URL. The URL consists of the domain name and the endpoint path:
    https://<domain>/<endpoint-path>

    The <domain> is the REST server domain from Step 3, as in:

    https://chat_rest_server_domain.com

    The <endpoint-path> is the relative path to the REST endpoint you're working with. You can pick any endpoint in All REST Endpoints. For example, we're interested in the requestEngagement endpoint:

    /engagement/api/consumer/{fqSiteName}/v1/requestEngagement

    Where fqSiteName value is 'day119_181100_sql_238h' as determined in Step 3.

    Combine the domain name and, in this example, the requestEngagement REST endpoint path and your request URL is complete. For more information, see URL Path.

    https://chat_rest_server_domain.com/engagement/api/consumer/day119_181100_sql_238h/v1/requestEngagement
  2. Determine the HTTP verb. The HTTP verb depends on the type of CRUD operation you are going to perform. In this case, the HTTP verb will be POST as we are going to create a chat engagement.
  3. Set the media type. The media type defines the structure of the HTTP payloads exchanged between the server and the client. If you're using cURL, you can specify a media type using the header -H option. In this case, as it is a POST request, the media type will be application/json. For more on media types, see Supported Media Types.
  4. Specify an empty request body. Use the -d option to specify the request body as follows:
    -d '{}'
  5. Provide the pool ID. Include the pool ID value (from Step 3) as follows:
    https://chat_rest_server_domain.com/engagement/api/consumer/day119_181100_sql_238h/v1/requestEngagement?pool=297:1

When you're done, the complete cURL command should look like this:

curl -X POST https://chat_rest_server_domain.com/engagement/api/consumer/day119_181100_sql_238h/v1/requestEngagement?pool=297:1 -H 'Content-Type: application/json; charset=utf-8' -d '{}'

If you're not familiar with any of the syntax used in the example, check out Work with your REST Client.

If you're an advanced REST user, but are reading our Quick Start anyway, you might want to Configure Cross-Origin Resource Sharing now. Otherwise, you're ready to move on to Step 5.

Step 5: Authorize

Now that you've configured the client with a complete request URL and fetched the authentication JWT, you can proceed to authorization. While authentication proves that your credentials are genuine, authorization allows you to apply your access privileges.

To get authorized access to create a chat engagement, you need to include the JWT from Step 3 in your request using the Bearer Authorization header, as follows:

curl -X POST https://chat_rest_server_domain.com/engagement/api/consumer/day119_181100_sql_238h/v1/requestEngagement?pool=297:1 -H 'Content-Type: application/json; charset=utf-8' -d '{}' -H 'Authorization: Bearer eyJhbGciOiJSU...Wst7gbQ6Nqs'

In a client such as Postman, you specify the JWT as a Bearer Authorization Header. This screenshot shows how this information is specified in Postman:

Passing of the authorization and authentication information in Postman

Step 6: Send an HTTP Request

You're almost done. Now that your authentication and authorization are set, you're ready to send a test HTTP request. Continuing with our example, we want to create a chat engagement. You can do this using the following command in cURL:

curl -X POST https://chat_rest_server_domain.com/engagement/api/consumer/day119_181100_sql_238h/v1/requestEngagement?pool=297:1 -H 'Content-Type: application/json; charset=utf-8' -d '{}' -H 'Authorization: Bearer eyJhbGciOiJSU...Wst7gbQ6Nqs'

This is how the request looks in Postman:

Example of a request in Postman

If your request to create a chat engagement is successful, you receive a response with a body similar to the following example. If your request fails, and you're using cURL, review the response comments, adjust your request, and then try again. If you're using other clients, review the failure Status Codes, and then try again.

{
"engagementId":34,
"engagementIdString":"34",
"cancelledSurveyId":0,
"cancelledSurveyIdString":"0",
"completedSurveyId":0,
"completedSurveyIdString":"0",
"cancelledSurveyAuth":"",
"completedSurveyAuth":"",
"resultType":"SUCCESS",
"sessionId":"192hyto5qomm8r8rpzzmuzsa6",
"sneakPreviewState":"DISABLED",
"sneakPreviewInterval":3000,
"clientRequestTime":null,
"clientTransactionId":0,
"clientTransactionIdString":"0",
"serviceStartTime":"2018-10-16T12:28:46.544Z",
"serviceFinishTime":"2018-10-16T12:28:46.688Z",
"clientId":34,
"clientIdString":"34"
}

In a client such as Postman, the results are formatted and displayed in the Response section. For example, Postman lets you view the output in multiple formats. This screenshot shows the response in JSON:

Example of a response in Postman

Congratulations! Now you're ready to do more with your REST APIs.