Accessing CallConversation immediately after posting a call

Hello,

I'm currently using version com.mypurecloud:platform-client:0.38.3.110 of the java sdk.
I have a problem where after creating a new conversation with the ConversationsAPI, I'm unable to retrieve the call conversation object by ID. I need to do this in order to get the conversation's participant list. I'm currently getting a 404 error on the getCallsCallId() line.

// Import classes:
//import com.mypurecloud.sdk.ApiClient;
//import com.mypurecloud.sdk.ApiException;
//import com.mypurecloud.sdk.Configuration;
//import com.mypurecloud.sdk.auth.*;
//import com.mypurecloud.sdk.api.ConversationsApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: PureCloud Auth
OAuth PureCloud Auth = (OAuth) defaultClient.getAuthentication("PureCloud Auth");
PureCloud Auth.setAccessToken("YOUR ACCESS TOKEN");
List<CallMediaParticipant> participantList = null;
ConversationsApi apiInstance = new ConversationsApi();
CreateCallRequest body = new CreateCallRequest(); // CreateCallRequest | Call request
try {
    CreateCallResponse result = apiInstance.postCalls(body);
    System.out.println(result);
    callId = result.getId();
    CallConversation result = apiInstance.getCallsCallId(callId);
    participantList = result.getParticipants();
} catch (ApiException e) {
    System.err.println("Exception when calling ConversationsApi#postCalls");
    e.printStackTrace();
}

Response

{"status":404, "code":"conversation.error.conversation.not.found", "message":"Conversation ab64a332-e4d5-4e46-bf42-41703ce0843a not found.", "messageWithParams":"Conversation {conversationId} not found.", "messageParams":{"conversationId":"ab64a332-e4d5-4e46-bf42-41703ce0843a"}, "contextId":"e3a899a7-0c4c-43e5-bf46-b879e62c14a9", "details":[], "errors":[]}

Thanks,
Sean Romocki

Try a pause of 1 second+ or a loop...then you will get the list.. We had same problem..There is a little delay

This is correct. You get a conversation ID back from the request, but the conversation object may not exist yet. A 1 second sleep step should generally suffice, or a better solution would be to use notifications to know immediately when the conversation exists so there is no unnecessary delay or race condition.

Thanks! This worked for me.

Sean

Hey Tim,

A 1 second sleep worked well enough for me to obtain the conversation ID. However, the conversation doesn't include the participant ID of the person we are trying to call, it only has the participant model for agent (or person calling). I've also tried to increase the sleep amount. I need the participant ID of the person we are calling because we identify calls based on the participant ID in our application. I've included the request/response below.

Also, we are not able to listen to the websocket notifications for when the conversation is made due to how we have built the integration. We only listen for websocket events in the UI of our application and not in the java service which using the purecloud SDK.

:01-05-2017 13:46:32.280 [http-nio-12090-exec-3] DEBUG c.mypurecloud.sdk.SLF4JInterceptor SEAN.ROMOCKI sid:ef4c5bf3-1796-4a75-82a3-afe3fe535569 tid:13c255ed-5054-4674-8c77-f201f8309414 carrier:rakuten <<<< GET /api/v2/conversations/calls/01bd6a36-b7be-4ff2-bd75-4fc29c4ce0a2 <<<<
 200 OK  (124 ms)
---- HEADERS ----
Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Length: 694
Content-Type: application/json
Date: Thu, 05 Jan 2017 19:46:32 GMT
Expires: 0
ININ-Correlation-Id: 42f0d473-73fa-478e-a11c-853de438e4d6
Pragma: no-cache
inin-ratelimit-allowed: 300
inin-ratelimit-count: 10
inin-ratelimit-reset: 40
---- BODY (694 bytes) ----
{
  "id": "01bd6a36-b7be-4ff2-bd75-4fc29c4ce0a2",
  "participants": [
    {
      "id": "9e9bf548-d757-45f7-9829-4661e053f915",
      "address": "md5[8e1d98d3f19af4bc7cbdca7ecd4501fd]",
      "startTime": "2017-01-05T19:46:29.210Z",
      "purpose": "user",
      "state": "contacting",
      "direction": "outbound",
      "held": false,
      "wrapupRequired": false,
      "user": {
        "id": "55c1a7ae-79d3-48cb-8004-16be6bcebe50",
        "selfUri": "/api/v2/users/55c1a7ae-79d3-48cb-8004-16be6bcebe50"
      },
      "attributes": {},
      "provider": "Edge",
      "muted": false,
      "confined": false,
      "recording": false,
      "recordingState": "none",
      "ani": "sip:sean.romocki@10.2.120.237",
      "dnis": "tel:+md5[32e9d2da328f0d13f5301cd005f81b42]"
    }
  ],
  "otherMediaUris": [],
  "recordingState": "none",
  "selfUri": "/api/v2/conversations/calls/01bd6a36-b7be-4ff2-bd75-4fc29c4ce0a2"
}

You're seeing the data that exists at the exact time you made the request. Setting up a voice call takes time to connect the physical media devices, so there will be some amount of delay between each step of creating a conversation.

Based on the data above, PureCloud was still trying to connect the media to the user. PureCloud requires that the connection to the initiator be established before attempting to connect the dialed party.

I would strongly suggest reconsidering this decision. You're always going to be at risk of running into a race condition with the way you've built your integration.