By using AWS re:Post, you agree to the AWS re:Post Terms of Use

GetMetricDataV2 - "API contacts handled" metric, not giving the same results as in the Historical Metrics UI

0

I'm looking to automate reports by creating a custom dashboard on our web app. For this, I'm testing with the GetMetricDataV2 API. Every metric data I receive coincides with the data I see on the Historical Metrics page, except when I try to get the API Contacts Handled metric.

The request looks like this:

const metricsInput: GetMetricDataV2CommandInput = {
    ResourceArn: "arn:aws:connect:us-east-1:<user_id>:instance/<same_instance_used_in_historical_metrics>",
    StartTime: "2024-03-14T07:00:00.000Z",
    EndTime: "2024-03-15T06:59:59.999Z",
    Interval: {
      TimeZone: 'America/Los_Angeles',
      IntervalPeriod: 'TOTAL',
    },
    Filters: [{ FilterKey: "AGENT", FilterValues: ['98c729e7-d5b1-4baf-9fc4-d178a1f1d937','23908fb5-33a5-48c5-adda-a5fa82bf2761']}], // agent ids
    Groupings: ["AGENT"],
    Metrics: [
      // API Contacts Handled
      {
        Name: 'CONTACTS_HANDLED',
        MetricFilters: [
          {
            MetricFilterKey: 'INITIATION_METHOD',
            MetricFilterValues: ['API'],
          },
        ],
      },
    ],
    // NextToken: nextToken, // logic to handle nextToken
  };
const command = new GetMetricDataV2Command(metricsInput);
const response = await connectClient.send(command);

I receive a response like this, an array of metrics saying that the agents have not handled any API call during the specified period:

[
...
  {
    "Collections": [
      {
        "Metric": {
          "MetricFilters": [
            {
              "MetricFilterKey": "INITIATION_METHOD",
              "MetricFilterValues": [
                "API"
              ],
              "Negate": false
            }
          ],
          "Name": "CONTACTS_HANDLED"
        },
        "Value": 0
      }
    ],
    "Dimensions": {
      "AGENT": "98c729e7-d5b1-4baf-9fc4-d178a1f1d937", // amys
      "AGENT_ARN": "arn:aws:connect:us-east-1:<user_id>:instance/<same_instance_used_in_historical_metrics>/agent/98c729e7-d5b1-4baf-9fc4-d178a1f1d937"
    },
    "MetricInterval": {
      "EndTime": "2024-03-15T07:00:00.000Z",
      "Interval": "TOTAL",
      "StartTime": "2024-03-14T07:00:00.000Z"
    }
  },
...
]

But when I go to the Historical Metrics UI and search for all the agents, I see that the agent I included in the SDK code handled 254 API calls during the same period. Enter image description here

Is there something I'm missing? It's the last step before automating the reports for us.

Many thanks, Lautaro

asked 8 months ago517 views
3 Answers
0
Accepted Answer

I contacted AWS Support, and after some days, the person told me that the Connect technical team told him that API Metrics (API Contacts & API Contacts Handled) on the agent level are not yet supported on the GetMetricDataV2 API. So that's why I was getting 0 for those metrics.

I was also told that they would change the documentation to reflect this (so that nobody else has to spend days figuring out this :/) and that they are working so that the API supports these metrics.

answered 7 months ago
0

What do you get if you change your filter setting from AGENT to the different CHANNEL that you have like CHAT (and others that you are trying to pull report for). Keep the groups value of AGENT and let us know.

profile pictureAWS
answered 8 months ago
  • Adding the filter key CHANNEL with the values CHAT and/or TASK I get an empty MetricResults value.

    When I include the VOICE channel I get that 0 calls were handled via API.

    Just made some API calls using the startOutboundVoiceContact with my own agent queue, but for the period it happened, it says no API calls were handled for my user :/

0

Hello lautaroef,

I have re-replicated the GetMetricDataV2 - "API setup and initially encountered a scenario where the API returned no output, similar to your experience. However after further investigation , I managed to resolve the issue by making some additions to the code. This is the final edited code :


// Import required modules
import { ConnectClient, GetMetricDataV2Command } from "@aws-sdk/client-connect";

// Lambda handler function
export async function handler(event, context) {
    try {
        // Create AWS Connect client
        const connectClient = new ConnectClient({ region: "us-east-1" }); // Change the region as needed

        // Define input parameters for the GetMetricDataV2 command
        const metricsInput = {
            ResourceArn: "arn:aws:connect:us-east-1:<user_id>:instance/<same_instance_used_in_historical_metrics>",
            StartTime: new Date("2024-03-26T07:00:00.000Z"),
            EndTime: new Date("2024-03-28T06:59:59.999Z"),
            Interval: {
                TimeZone: 'America/Los_Angeles',
                IntervalPeriod: 'TOTAL',
            },
            Filters: [{ FilterKey: "AGENT", FilterValues: ['<AGENT ID>'] }], // agent ids
            Groupings: ["QUEUE"],
            Metrics: [
                // API Contacts Handled
                {
                    Name: 'CONTACTS_HANDLED',
                    MetricFilters: [
                        {
                            MetricFilterKey: 'INITIATION_METHOD',
                            MetricFilterValues: ['API'],
                        },
                    ],
                },
            ],
        };
       
        // Create GetMetricDataV2Command with the metrics input
        const command = new GetMetricDataV2Command(metricsInput);

        // Send the command to AWS Connect service and await response
        const response = await connectClient.send(command);

      // Log the response for debugging (optional)
        console.log(response);

        // Return response (or process it further)
        return response;

    } catch (error) {
        // Handle errors
        console.error("Error:", error);
        throw error; // Rethrow the error for Lambda to handle
    }
};

When I was running your original code, I noticed that your code had the line Name: 'CONTACTS_HANDLED' placed inside the Metrics array, where metric filters are typically specified. However, this caused confusion as it implied that 'CONTACTS_HANDLED' was a filter, when its actual purpose was to represent the metric we wanted to retrieve. Recognizing this, I moved Name: 'CONTACTS_HANDLED' outside of the MetricFilters array in my modified version of the code, and this is the output I got:

Response { "$metadata": { "httpStatusCode": 200, "requestId": "<REQUEST ID>", "attempts": 1, "totalRetryDelay": 0 }, "MetricResults": [ { "Collections": [ { "Metric": { "MetricFilters": [ { "MetricFilterKey": "INITIATION_METHOD", "MetricFilterValues": [ "API" ], "Negate": false } ], "Name": "CONTACTS_HANDLED" }, "Value": 4 } ], "Dimensions": { "QUEUE": "<QUEUE ID>", "QUEUE_ARN": "QUEUE ARN" }, "MetricInterval": { "EndTime": "2024-03-28T07:00:00.000Z", "Interval": "TOTAL", "StartTime": "2024-03-26T07:00:00.000Z" } } ] }

I observed that the data retrieved correlated with the test calls I had previously placed via the API. This suggests that the code is now accurately fetching the desired metric data.

profile pictureAWS
answered 8 months ago
profile picture
EXPERT
reviewed 8 months ago
  • Hello, thank you for providing help on this. Yes, the request had a formatting error. A bracket was missing, so I just edited that. But even if I change the Groupings to QUEUE, I get various MetricResults for each queue the agent is in, but still get that the agent handled 0 API Contacts :( same period as the Historical Metrics UI which tells me it handled 254 calls.

    I have already contacted AWS Technical Support, as it seems to be something on the account level. So as soon as I resolve this, I will publish it here.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions