Legacy Dev Forum Posts

 View Only

Sign Up

C# User Call\Conversation List

  • 1.  C# User Call\Conversation List

    Posted 06-05-2025 18:29

    corcoranj | 2024-01-23 10:08:11 UTC | #1

    I am very new to Genesys and basically I have been tasked with obtaining call transcripts for all users in my company and thus far I have been able to complete the following using C#:

    • Create an oAuth set of credentials
    • Use the credential to authenticate to the API and return a access_token
    • I have been able to use that access token to obtain a list of all users using endpint /api/v2/users.
    • I now have access to the UserIds

    What I need help with now is using those userids to call and endpoint to get a listing of user conversations (phone calls) for the last 30 days.

    However, when I look at the conversations endpoint I only see how to get conversations for the current logged in user or via conversation id.

    How do I go about getting either a list of users conversation ids for the last 30 days?

    Here is what I have so far:

    private string GetAuthenticationToken()
            {
                //Local Variable Declaration
                var returnValue = string.Empty;
                var jsonStr = string.Empty;
                var byteArray = default(byte[]);
                var dataStream = default(System.IO.Stream);
                var response = default(WebResponse);
                var request = default(WebRequest);
    
                //specify to use TLS 1.2 as default connection
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    
                //Init the Web Request to the authentication service
                request = WebRequest.Create("https://login.usw2.pure.cloud/oauth/token");
                //request = WebRequest.Create("https://login.mypurecloud.com/oauth/token");
    
                //Build The JSON Body
                jsonStr = "grant_type=client_credentials&client_id=<clientid>&client_secret=<secret>";
    
                //Convert the JSON string into a byte array
                byteArray = Encoding.UTF8.GetBytes(jsonStr);
    
                //Set Sender Properties
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
    
                //Init the request stream
                dataStream = request.GetRequestStream();
    
                //Write the JSON data to the server
                dataStream.Write(byteArray, 0, byteArray.Length);
    
                //Retrieve the response
                response = request.GetResponse();
    
                //Read the response
                using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    returnValue = reader.ReadToEnd();
                }
    
                if (!string.IsNullOrEmpty(returnValue))
                {
                    var jsonObj = Newtonsoft.Json.Linq.JObject.Parse(returnValue);
                    returnValue = jsonObj.Property("access_token").Value.ToObject<string>();
                }
    
    
                return returnValue;
            }
    
           private List<Newtonsoft.Json.Linq.JObject> FetchUserList(string code)
            {
                var client = new HttpClient();
                var results = new List<Newtonsoft.Json.Linq.JObject>();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", code);
    
                //Fetch User List
                var response = client.GetAsync($"https://api.usw2.pure.cloud/api/v2/users").Result;
    
                var content = response.Content.ReadAsStringAsync().Result;
    
                var jsonObj = Newtonsoft.Json.Linq.JObject.Parse(content);
    
                if ((jsonObj.Property("entities").Value as Newtonsoft.Json.Linq.JArray).Count > 0)
                {
                    results.AddRange(jsonObj.Property("entities").Value.ToObject<Newtonsoft.Json.Linq.JObject[]>());
                }
    
                var pageNo = jsonObj.Property("pageNumber").Value.ToObject<int>() + 1;
                var maxPage = jsonObj.Property("pageCount").Value.ToObject<int>();
    
                while (pageNo <= maxPage)
                {
                    response = client.GetAsync($"https://api.usw2.pure.cloud/api/v2/users?pageSize=25&pageNumber=" + pageNo).Result;
                    content = response.Content.ReadAsStringAsync().Result;
                    jsonObj = Newtonsoft.Json.Linq.JObject.Parse(content);
    
                    if ((jsonObj.Property("entities").Value as Newtonsoft.Json.Linq.JArray).Count > 0)
                    {
                        results.AddRange(jsonObj.Property("entities").Value.ToObject<Newtonsoft.Json.Linq.JObject[]>());
                    }
    
                    pageNo = jsonObj.Property("pageNumber").Value.ToObject<int>()+1;
                }
    
                return results;
            }

    Eos_Rios | 2024-01-23 13:42:35 UTC | #2

    You would do yourself a massive favor if you just use the Genesys dotnet SDK rather than try to write your own API interfaces and objects from scratch;

    https://developer.genesys.cloud/devapps/sdk/dotnet

    You'll note all the API links include examples of how to run them with each of the language libraries they publish.

    Refer to the following APIs in the Developer center for getting conversations by criteria in bulk

    POST /api/v2/analytics/conversations/details/jobs

    GET /api/v2/analytics/conversations/details/jobs/{jobId}/results

    If all you want are transcripts you may be able to just run this directly for users and skip finding the conversations -

    POST /api/v2/speechandtextanalytics/transcripts/search


    system | 2024-02-22 13:42:04 UTC | #3

    This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 24241