Salesforce Messaging REST API Guide: How to Retrieve Estimated Wait Time (EWT)?

Salesforce Messaging REST API Guide: How to Retrieve Estimated Wait Time (EWT)?

Prerequisites:

Setup Salesforce Messaging for In-App and Web REST API.

When building a custom web chat client using the Salesforce Messaging for Web REST API, providing an accurate Estimated Wait Time (EWT) is one of the most effective ways to improve customer satisfaction. Letting a customer know how long they can expect to wait manages expectations and reduces chat abandonment rates.

While the standard out-of-the-box Salesforce web chat component often handles this automatically, custom implementations require developers to fetch this information manually. Fortunately, Salesforce makes this data available through a specific endpoint immediately after a conversation begins routing.

This guide will walk you through the exact steps to retrieve the EWT using the Messaging for Web REST API.


Prerequisites

Before you can retrieve the EWT, you must have a working implementation of the Salesforce Messaging for Web REST API. This guide assumes you have already:

  1. Configured Messaging for In-App and Web: Set up your Messaging Channel, linked it to a queue via Omni-Channel flow or routing configuration, and enabled the REST API features.
  2. Obtained API Credentials: Successfully authenticated and retrieved your Salesforce Core Runtime (SCRT) base URL and authorization token.
  3. Initiated a Conversation: Successfully used the conversation endpoint to create a new messaging session and have received a unique conversationId.

For a detailed guide on setting up the initial connection, refer to this resource: Salesforce Messaging for In-App and Web REST API Setup Guide.

Enable Estimated Wait Time:

Kindly enable the “Show estimated wait time” in the Salesforce Messaging Channel created for the Embedded Service Deployment.


Solution: Retrieving the Estimated Wait Time

The key to finding the EWT is to understand that it isn’t retrieved from a dedicated EWT endpoint. Instead, the EWT information is pushed as one of the first entries into the conversation log by the routing system.

You can access this information by querying the “List conversation entries” endpoint immediately after creating the conversation.

Step 1: Understand the API Endpoint

Once a customer initiates a chat and a conversationId is generated, make a GET request to the following endpoint:

Endpoint URL: GET https://{SCRT-URL}/iamessage/api/v2/conversation/{Messaging-Conversation-Id}/entries

  • {SCRT-URL}: Your organization-specific Salesforce SCRT Runtime URL. You will get this information from the Embedded Service Deployment Code Snippet.
  • {Messaging-Conversation-Id}: The unique ID generated when you first created the conversation session.

Step 2: Parse the API Response for EWT

When you call this endpoint, you will receive a JSON response containing an array of conversationEntries. The entry containing the wait time details has an entryType of RoutingResult.

You need to parse this response to find the estimatedWaitTimeInSeconds object.

Sample JSON Response:

{
    "conversationEntries": [
        {
            "entryType": "RoutingResult",
            "entryPayload": {
                "entryType": "RoutingResult",
                "id": "aea3c90c-0409-44c8-a5ee-de1ca84248f9",
                "recordId": "0MwHo000001NH8b",
                "errorMessages": [],
                "pendingServiceRoutingId": "0JRHo00000HjzVg",
                "routingType": "Initial",
                "estimatedWaitTime": {
                    "estimatedWaitTimeInSeconds": -1,
                    "isEWTRequested": true
                },
                "failureReason": "",
                "failureType": "None",
                "isExternallyRouted": false,
                "routingConfigurationDetails": {
                    "routingConfigurationType": "QueueRoutingType",
                    "queueId": "00GHo000002o3l0"
                }
            },
            "transcriptedTimestamp": 1757343692529,
            "sender": {
                "role": "System",
                "subject": "005Ho00000B44Ht"
            },
            "clientTimestamp": 1757343692358,
            "identifier": "aea3c90c-0409-44c8-a5ee-de1ca84248f9",
            "senderDisplayName": "Automated Process"
        }
        // Other entries like "ConversationLine" might appear here later
    ]
}

Step 3: Extract and Implement the Value

In your application code, navigate through the JSON structure to extract the value from: conversationEntries[n].entryPayload.estimatedWaitTime.estimatedWaitTimeInSeconds

Key Value to Extract: estimatedWaitTimeInSeconds: This field provides the wait time in seconds.

Example Implementation Logic:

  1. Retrieve the Value: Get the integer from estimatedWaitTimeInSeconds.
  2. Convert to Minutes/Seconds: Convert the total seconds into a user-friendly format (e.g., divide by 60 to get minutes).
  3. Display to User: Show a message in your chat interface like: “Your estimated wait time is approximately {minutes} minutes.”

Important Consideration: Handling the “-1” Value

In the sample response provided, estimatedWaitTimeInSeconds has a value of -1. This typically indicates one of the following scenarios:

  • EWT Calculation Disabled: The Omni-Channel routing configuration does not have Estimated Wait Time calculation enabled for this queue.
  • Immediate Availability: Agents are available for immediate pickup, so a wait time calculation is unnecessary.
  • Calculation Pending: The call was made too quickly before the routing system could populate the value.

Your front-end application should include logic to handle this case gracefully. If the value is -1, display a generic message like “Connecting you to an agent…” rather than “Wait time: -1 seconds.”


Conclusion

By leveraging the “List conversation entries” endpoint in the Salesforce Messaging for Web REST API, you can gain powerful insights into the customer’s journey before they even connect with an agent. Displaying an accurate Estimated Wait Time (EWT) is a simple but highly effective method for managing customer expectations, building trust, and creating a more professional custom chat solution.

Salesforce Article:

https://developer.salesforce.com/docs/service/messaging-api/references/miaw-api-reference?meta=listConversationEntries

Leave a Reply