# Access application metrics and company user data with Kinsta API

**URL:** https://community.kinsta.com/t/access-application-metrics-and-company-user-data-with-kinsta-api/3390
**Category:** News and Announcements
**Created:** [May 3, 2024, 9:27am UTC](https://community.kinsta.com/t/access-application-metrics-and-company-user-data-with-kinsta-api/3390 "2024-05-03T09:27:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jeff](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jeff/32/16_2.png) [@jeff](https://community.kinsta.com/u/jeff)
#### Post date: [May 3, 2024, 9:27am UTC](https://community.kinsta.com/t/access-application-metrics-and-company-user-data-with-kinsta-api/3390/1 "2024-05-03T09:27:21Z")

</div>

We’re excited to announce the release of new endpoints on the [Kinsta API](https://kinsta.com/docs/kinsta-api/)&nbsp;that allow you to [access detailed analytics about your applications](https://api-docs.kinsta.com/tag/Application-Metrics)&nbsp;and [retrieve information about your company users](https://api-docs.kinsta.com/tag/Company-Users#operation/getCompanyUsers)&nbsp;on Kinsta.

Since launching our [Application Hosting](https://kinsta.com/application-hosting/)&nbsp;service, we have provided application-level analytics that detail your application’s bandwidth, build time, runtime, CPU and memory usage, average response time, HTTP requests, and slowest requests via the [MyKinsta](https://my.kinsta.com/)&nbsp;dashboard ( **Applications** &nbsp;\> **appname** &nbsp;\> **Analytics** ).

 ![Access analytics information for each application in MyKinsta dashboard](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/e/e7f19171ca5bc631dbd1dc5a21d8c3ec2be843de.png)Access analytics information for each application in the MyKinsta dashboard.

Now, these metrics can be accessed programmatically via the Kinsta API.

### Info

Kinsta’s API is available to all customers, but it remains in public beta as we continue to develop it and release more endpoints.

## New metrics endpoints for your applications

You can now access the following analytics information via the Kinsta API:

- [Bandwidth](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationBandwidth)&nbsp;— Total data transmitted in the selected time period.
- [Build time](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationBuildTime)&nbsp;— Total time it took to build your application.
- [Run time](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationRunTime)&nbsp;— Total time the application runs after being built and deployed.
- [HTTP requests per minute](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationHttpRequests)&nbsp;— Total average requests per minute.
- [Average response time](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationAverageResponseTime)&nbsp;— The average request response time. (If the response time query includes the `percent` parameter with values of 95 or 50, the [P95 latency](https://kinsta.com/docs/application-hosting/application-analytics/#http-p-95-latency)&nbsp;or [P50 latency](https://kinsta.com/docs/application-hosting/application-analytics/#http-p-50-latency)&nbsp;response times will be returned).
- [Slowest requests](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationSlowestRequests)&nbsp;— This shows you exactly which responses are the slowest within your application.
- [CPU usage](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationCpuUsage)&nbsp;—The average of the total CPU usage for the selected time period, as a percentage of the instance’s CPU resources.
- [Memory usage](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationMemoryUsage)&nbsp;— An average of the total memory (RAM) usage for the selected time period.

The [Kinsta API documentation](https://api-docs.kinsta.com/tag/Application-Metrics)&nbsp;provides the necessary path and query parameters for accessing these metrics. For example, to retrieve daily bandwidth usage data, send a GET request to:

```
https://api.kinsta.com/v2/applications/{id}/metrics/bandwidth
```

 ![Kinsta API documentation showing various parameters to retrieve bandwidth metrics information](https://us1.discourse-cdn.com/flex020/uploads/kinsta/original/2X/e/e54e1cced95559bc7c566aa30a95cf8527b6fc0e.png)Kinsta API documentation showing various parameters to retrieve bandwidth metrics information.

This request will require the following parameters:

- **Path parameter:**
  - `id` — This is the application ID and will be added to the API URL.

- **Query parameters:**
  - `interval_in_seconds` — This is required and measured in seconds, If you want the interval between the returned values to be 24 hours, then you’d convert 24 hours to seconds, which is 86400.
  - `timeframe_start` and `timeframe_end` — These parameters are required, and the ISO 8601 date time format is used. It has a general format of `YYYY-MM-DDThh:mm:ss.sssZ`.

Here’s a detailed breakdown of the ISO 8601 date and time format:

- **YYYY-MM-DD** &nbsp;— Represents the date:
  - **YYYY** &nbsp;— Four-digit year
  - **MM** &nbsp;— Two-digit month (01 to 12)
  - **DD** &nbsp;— Two-digit day of the month (01 to 31)

- **T** &nbsp;— The letter T is used as a separator to distinguish clearly between the date and time parts.
- **hh:mm:ss.sss** &nbsp;— Represents the time:
  - **hh** &nbsp;— Two-digit hour (00 to 23)
  - **mm** &nbsp;— Two-digit minute (00 to 59)
  - **ss** &nbsp;— Two-digit second (00 to 59)
  - **.sss** &nbsp;— Milliseconds, which can be one to three digits, representing a fractional part of a second

- **Z** &nbsp;— Indicates that the time is set to UTC (Coordinated Universal Time). If the time is not in UTC, a time offset can also be included in place of “Z,” formatted as ±hh:mm, where “hh” represents the hour difference and “mm” represents the minute difference from UTC.

Back to our example, you can send a GET request to retrieve daily data between April 20, 2024, and April 28, 2024:

```
curl -i -X GET \
'https://api.kinsta.com/v2/applications/{application_id}/metrics/bandwidth?interval_in_seconds=86400&timeframe_start=2024-04-20T18%3A10%3A45.511Z&timeframe_end=2024-04-28T18%3A10%3A45.511Z' \
  -H 'Authorization: Bearer '
```

Replace `{application_id}` and `` with your application ID and API token, respectively. When you send this request, the following data format is returned:

```
{
  "app": {
    "id": "MY_APP_ID",
    "display_name": "Kinsta-developer-portfolio",
    "metrics": {
      "timeframe": {
        "start": "1713571200000",
        "end": "1714262400000"
      },
      "bandwidth": [
        {
          "time": "1713571200000",
          "value": "18205"
        },
        {
          "time": "1713657600000",
          "value": "834750"
        },
        {
          "time": "1713744000000",
          "value": "146959"
        },
        {
          "time": "1713830400000",
          "value": "142413"
        },
        {
          "time": "1713916800000",
          "value": "165352"
        },
        {
          "time": "1714089600000",
          "value": "109015"
        },
        {
          "time": "1714176000000",
          "value": "628641"
        }
      ]
    }
  }
}
```

The response specifies the timeframe’s start and end based on what was sent via the request. If you put it into the `new Date()` constructor, you get the date/time object. Also, the bandwidth returns an array of objects containing the time (timestamp given for each day — based on the interval set) and the value in bytes.

When you convert each of these data accordingly, it means the following:

**Timeframe**

- Start: 2024-04-20 00:00:00
- End: 2024-04-29 00:00:00

**Bandwidth (converted to MB)**

- Time: 2024-04-20 00:00:00, Value: 0.0174 MB
- Time: 2024-04-21 00:00:00, Value: 0.7961 MB
- Time: 2024-04-22 00:00:00, Value: 0.1402 MB
- Time: 2024-04-23 00:00:00, Value: 0.1358 MB
- Time: 2024-04-24 00:00:00, Value: 0.1577 MB
- Time: 2024-04-26 00:00:00, Value: 0.1040 MB
- Time: 2024-04-27 00:00:00, Value: 0.5995 MB
- Time: 2024-04-28 00:00:00, Value: 5.8086 MB

This means you can programmatically get information about each of these analytic information into another platform without needing to navigate the MyKinsta dashboard for each application.

For example, you can [create a Slackbot that uses Slack’s Slash command](https://kinsta.com/blog/create-slackbot-site-management/)&nbsp;to access this information from [Slack](https://kinsta.com/blog/how-to-use-slack/)&nbsp;or create a reminder to inform you when the daily bandwidth, CPU, or memory usage crosses a particular threshold.

### Info

It’s important to know that the endpoints for average response time and the slowest request have an extra query parameter, which is not required but can help enhance the response. For example, for the slowest requests, you can add a `limit` to set the number of responses you want. Ensure to [check the API documentation](https://api-docs.kinsta.com/tag/Application-Metrics#operation/getApplicationSlowestRequests).

## Access company users with Kinsta API

In response to client requests, we’ve added an endpoint for retrieving details about Kinsta account company users, including their full name, email, and gravatar image URL.

This aligns with our commitment to prioritize features based on user feedback. If you believe a specific tool or endpoint should be included in the Kinsta API, feel free to [send your feedback](https://kinsta.com/docs/service-information/kinsta-research-program#how-to-join).

To access this data, send a GET request to: `https://api.kinsta.com/v2/company/{company_id}/users`. Ensure to replace `{company_id}` with your company ID. This will return a response like:

```
{
  "company": {
    "users": [
      {
        "user": {
          "id": "54fb80af-576c-4fdc-ba4f-b596c83f15a1",
          "email": "example@exmample.com",
          "image": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50",
          "full_name": "John Doe"
        }
      }
    ]
  }
}
```

## Get started with Kinsta API today

To use the Kinsta API, you need an active Kinsta account with at least one WordPress site, application, or database in MyKinsta. Here’s how to generate an API key:

1. Go to your [MyKinsta](https://my.kinsta.com/)&nbsp;dashboard.
2. Navigate to the API Keys page ( **Your name** &nbsp;\> **Company settings** &nbsp;\> **API Keys** ).
3. Click **Create API Key**.
4. Choose an expiration or set a custom start date and number of hours for the key to expire.
5. Give the key a unique name.
6. Click Generate.

When the API key is created, make sure you copy it and store it somewhere safe, as this is the only time you can see it. We recommend using a [password manager](https://kinsta.com/blog/password-managers/)&nbsp;like 1Password to share it securely.

There is a lot that can be done with the Kinsta API. Feel free to check out our [documentation](https://kinsta.com/docs/kinsta-api)&nbsp;to understand [what’s possible](https://kinsta.com/docs/kinsta-api#common-use-cases)&nbsp;with the API, how to get started, and the various [permission levels](https://kinsta.com/docs/kinsta-api#authentication-and-user-access)&nbsp;and [limits to the API](https://kinsta.com/docs/kinsta-api#rate-limit).

You can also check out our previous changelogs for the Kinsta API:

- [Introducing Kinsta API: The Power of Automation for Site Management](https://kinsta.com/changelog/kinsta-api/)
- [Introducing New Kinsta API Endpoints: Environment CRUD, Edge Caching, Application Deployment](https://kinsta.com/changelog/kinsta-api-aug-2023/)
- [New Kinsta API Endpoints: Clear CDN Cache and Push Environment](https://kinsta.com/changelog/kinsta-api-sept-2023/)
- [New Kinsta API endpoints enhance WordPress site management](https://kinsta.com/changelog/kinsta-api-feb-2024/)
- [3 new Kinsta API endpoints for Application Hosting (CDN, Edge Caching, & clear cache)](https://kinsta.com/changelog/kinsta-api-mar-2024/)

The post [Access application metrics and company user data with Kinsta API](https://kinsta.com/changelog/kinsta-api-may-2024/) appeared first on [Kinsta®](https://kinsta.com).

* * *
This is a companion discussion topic for the original entry at [https://kinsta.com/changelog/kinsta-api-may-2024/](https://kinsta.com/changelog/kinsta-api-may-2024/)
