Abhijeet | 2020-08-10 14:27:39 UTC | #1
Hi Team,
I was looking to get count of records present in the tool from the api end point for given time frame.
For Ex. if I read data from 2020-08-05 00:00:00.000 to 2020-08-06 00:00:00.000 from the detail and aggregate endpoint . How can I confirm I have read all the records and how can i get the total record count i suppose to read.
Thanks,
Abhijeet Hivarkar
anon11147534 | 2020-08-11 08:15:41 UTC | #2
Hi Abhijeet,
For the /api/v2/analytics/conversations/aggregates/query endpoint you simply get the length of the results array returned by the API and this will give you the total record count for the interval.
The /api/v2/analytics/conversations/details/query endpoint is a little more complicated. The conversations array will give you the amount of records but this endpoint implements pagination so you'll need to send requests with the pageNumber value starting at 1 and incrementing until the request returns an empty JSON object indicating there are no more records. You'll have to add the length of the conversations array to a total value after each request to get the total number of records for the interval.
Abhijeet | 2020-09-02 12:48:45 UTC | #3
Hi Ronan,
Is there any easy way of doing it. Because when I try to read the length of response it only gives for that time period I am calling to and i cant validate the number with tool.Also what if i want to know entire set of record as well.
Thanks,
Abhijeet Hivarkar
anon11147534 | 2020-09-02 13:55:43 UTC | #4
Usually people use these APIs in software applications so getting a count of total records and pagination is easily achieved. The tool is there to help people build the query that their application will use. The only way to make this easier is to write an application or script that uses the API to make these requests and operate on the received data. We have made a number of Platform SDKs to help people build applications consuming our API.
John_Carnell | 2020-09-02 14:48:38 UTC | #5
Hi Abhijeet,
I actually just worked on some code where I had to use pagination to aggregate all my data together and then returned. In most API calls that use pagination, you are going to get back the total number of items in the page, the total number of pages, the page number you are on and the total number of records (totalCount).
So for instance, I had to get a list of all of the groups in our, I had to paginate through all of them and then aggregate all of the results. I used our JavaScript API. Here is the example code, I used. Hope it helps.
Thanks, John Carnell
const platformClient = require('purecloud-platform-client-v2'); const retry = require('@lifeomic/attempt').retry;
let groupsMap = new Map(); /* The getGroup() function will make a call to the platformClient.getGroups() call passing in target page number. */ async function getGroup(pageNum) { let opts = { pageSize: 50, pageNumber: pageNum, };
let apiInstance = new platformClient.GroupsApi();
try { results = await apiInstance.getGroups(opts); return results; } catch (e) { console.log( Error while retrieving group for page number: ${pageNum}: ${JSON.stringify( e )} ); return null; } }
/* The getGroups() call is going to retrieve all of the groups within the org and then map the logical name (e.g. the human readable name) to the Genesys Cloud Group GUID. Later when we have to add a user to a group we are going to look up the Genesys Cloud GUID for the group by is logical name. Note: You have to be aware of whether or not the API call might expect to returns the results using pagination and code accordingly to. In the code below, I paginate over each page, looking up the values for all pages. I flatten the results into 1 big list and then build a map containing just the logical name for the group and the GUID. */ async function getGroups() { let groups = [];
//Do the first call and push the results to an array group = await getGroup(1); groups.push(group.entities);
//If the count is greater then 1 then go through and look up the result of the pages. if (group.pageCount > 1) { for (let i = 2; i <= pageCount; i += 1) { group = await getGroup(i); group != null ? groups.push(group) : ''; } }
groups = groups .flat(1) //Each result contains an array of records. flat(1) will flatten this array of arrays one level deep .map((value) => { //Map through each result and extrace the logical name and the guid into a map groupsMap[value.name] = value.id; });
//Cloning the internal representation to keep the data immutable return {...groupsMap}; }
system | 2020-10-03 14:48:41 UTC | #6
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 8533