Report API - through NuGet package C#
The following article describes how to access the Meridix Report API with the use of the NuGet package MeridixStudioWebAPI
Prerequisite
An advanced Meridix subscription and an API ticket with report right. The ticket consists of a token and secret and is added and viewed in the web portal.
Download the NuGet package https://www.nuget.org/packages/MeridixStudioWebAPI/
Create the client using the URL and the API ticket
Create the client
string url = "https://myWebPortalAdress.com"; string token = "myApiTicketToken"; string secret = "myApiTicketSecret"; var meridixClient = MeridixStudioClient.Create(url, token, secret);
Retrieve the data needed to create the parameter object that is used to generate the report
Example code
/* * Retrieves the data needed to create the ReportV11ParametersDto object that is being sent to generate the report */ // Retrieves the customer id from the ticket var customerId = meridixClient.GetTicketCustomerId(); // Retrieves the modules names activated var modules = meridixClient.ReportApiV11().GetAvailableModules(); // Retrieves the report name identifier var reportNames = meridixClient.ReportApiV11().GetAvailableReports(modules["theModuleIWantReportsFrom"]); // Optional // Retrieves the different types of measurement objects var measurementObjectTypes = meridixClient.ReportApiV11().GetAvailableMeasurementObjectTypes(modules["theModuleIWantReportsFrom"], reportNames["theNameOfTheReport"]); // Retrieves the measurement objects that the report should be based on // The argument is the key in the measurementObjectTypes var listOfMeasurementObjects = meridixClient.ReportApiV11().GetAvailableMeasurementObjects(measurementObjectTypes.Keys.First()); // Optional // Retrieves the groups the measurement objects might belong to var listOfGroups = meridixClient.ReportApiV11().GetAvailableGroups(); // There are to types of groupings result and interval and they are both used indifferently of each other // Result grouping groups the result based on measurement objects or the groups the measurement objects belong to // Is a list containing [Total|Objects|Groups|GroupsObjects] var resultGroupings = meridixClient.ReportApiV11().GetAvailableResultGroupings(); // Optional // Interval grouping sets the time grouping [Time|Weekday|Month|Date|Week|YearMonth|Quarter|Year|Period] var intervalGrouping = meridixClient.ReportApiV11().GetAvailableIntervalGroupings(); // Retrieves any custom parameters on the report if they exist var customParameters = meridixClient.ReportApiV11() .GetAvailableCustomParameters(modules["theModuleIWantReportsFrom"], reportNames["theNameOfTheReport"]); /* * Create the ReportV11ParametersDto object */ var parameters = new ReportV11ParametersDto() { CustomerId = customerId, ModuleName = modules["theModuleIWantReportsFrom"], ReportName = reportNames["theNameOfTheReport"], FromDate = "20190415", ToDate = "20190419", Dates = null, // OPTIONAL: Used to create report for specific dates, is an array of date-strings FromMinute = 420, // The time of day to start measure in minutes from 00:00 in the morning ToMinute = 1019, // The time of day to stop measure in minutes from 00:00 in the morning IntervalMinutes = 30, TimeFormat = "hhmmss", // OPTIONAL ResultGrouping = "GroupsObjects", CollectionPointIdentifier = "CollectionPointIdentifier", // OPTIONAL: Can be excluded if there is only one and you are not using a system ticket. Can be found in the web portal Administration => Collection Points MeasurementObjectType = measurementObjectTypes.Keys.First(), // OPTIONAL MeasurementObjectIdentifiers = new List<string>() // Specifies the measurement object that the report is based on. { listOfMeasurementObjects[0].ObjectIdentifier, listOfMeasurementObjects[1].ObjectIdentifier // And so on }, MeasurementObjectGroupIdentifiers = new List<string>() // OPTIONAL: The group identifiers { listOfGroups[0].Name, listOfGroups[1].Name }, CustomParameters = { }, // OPTIONAL: Custom parameters are defined here if they exist IgnoreNonExistingMeasurementObjectIdentifiers = false, // OPTIONAL: Specifies if the API should ignore any exceptions thrown if a measurement object is specified but does not exist or is accessible IncludeColumns = new List<string>() // OPTIONAL: An array of strings with the column names that you would like to return in the result. Leave empty or skip to include all. { "Incoming", "IncFromExternal", "IncFromInternal", "IncFromQueues", "IncAnswered", "IncAbandoned", "Outgoing", "OutToExternal", "OutToInternal", "OutAnswered", "OutAbandoned", }, IncludeGroupings = new List<string>() // OPTIONAL: An array of strings with the interval grouping that you would like to return in the result. Leave empty or skip to include all. { "Time", "Weekday", "Month", "Date", "Week", "YearMonth", "Quarter", "Year", "Period" }, IncludeSpecificationLists = true // OPTIONAL: A boolean value specifying if a the call specification should be included (if possible). Note that there are a max limit of items configured on the system level that cannot be overridden through the API. }; /* * Generate the report using the ReportV11ParametersDto */ ReportV11ResultDto result = meridixClient.ReportApiV11().Generate(parameters, new CultureInfo("en-GB")); /* * Extract data from the report */ var totalPeriod = result.Presentations.Groupings["period"]; // Gets the data from the period grouping var columns = result.Presentations.Columns; // Gets metadata about the columns (name and description)
Async report generation
Async
ReportV11ExecutionIdHandleDto asyncResult = meridixClient.ReportApiV11().BeginGenerate(parameters, new CultureInfo("en-GB")); while (!asyncResult.IsCompleted) { System.Threading.Thread.Sleep(3000); asyncResult = meridixClient.ReportApiV11().UpdateHandle(asyncResult.executionId, new CultureInfo("en-GB")); }
Webpage: www.meridix.se
Email: support@meridix.se
Tel: +46 (0) 21 38 30 32