# Workspace statistics

> Page: https://docs.flung.dev/reference/api/get-v1-stats. Index of every page: https://docs.flung.dev/llms.txt

Posts due in a window by status, publishes per platform by status, and the accounts and stored media now.

`GET /v1/stats`

## TL;DR

| Question | Answer |
|---|---|
| What does it do? | Workspace statistics. |
| What does it need? | An API key or an OAuth access token. |
| What does it take? | `from`, `to` in the query string. |
| What does it return? | Status 200 with a body of type [`Stats`](https://docs.flung.dev/reference/api/schemas.md#stats). |
| In the SDK? | `flung.analytics.stats()` |
| What can go wrong? | `401` Missing, unknown, revoked or expired API key; `422` The request failed validation; `429` Too many requests for this credential; wait for `retry-after` seconds. Every failure has the same [error shape](https://docs.flung.dev/reference/api/errors.md). |

## What it does

Posts due in a window by status, publishes per platform by status, and the accounts and stored media now. The window defaults to the last 30 days.

## Example

**curl**

```bash
curl -X GET 'https://api.flung.dev/v1/stats' \
  --header "Authorization: Bearer $FLUNG_API_KEY"
```

**TypeScript**

```ts
import { Flung } from '@flung.dev/sdk'

const flung = new Flung({ apiKey: process.env.FLUNG_API_KEY! })
const result = await flung.analytics.stats()
```

**fetch**

```js
const response = await fetch('https://api.flung.dev/v1/stats', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${process.env.FLUNG_API_KEY}`,
  },
})
if (!response.ok) throw new Error((await response.json()).error.message)
const result = await response.json()
```

A successful answer looks like this:

```json
{
  "from": "string",
  "to": "string",
  "posts": {
    "published": 40,
    "failed": 2,
    "scheduled": 5
  },
  "platforms": [
    {
      "platform": "x",
      "targets": {}
    }
  ],
  "accounts": [
    {
      "platform": "x",
      "accounts": {}
    }
  ],
  "media": {
    "files": 1,
    "bytes": 1
  }
}
```

## Query parameters

| Field | Type | Required | Description |
|---|---|---|---|
| `from` | `string` | no |  |
| `to` | `string` | no |  |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | The statistics. | [`Stats`](https://docs.flung.dev/reference/api/schemas.md#stats) |
| 401 | Missing, unknown, revoked or expired API key. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 422 | The request failed validation. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 429 | Too many requests for this credential; wait for `retry-after` seconds. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |

## Response body

A 200 answer has the type [`Stats`](https://docs.flung.dev/reference/api/schemas.md#stats).

| Field | Type | Required | Description |
|---|---|---|---|
| `from` | `string` | yes |  |
| `to` | `string` | yes |  |
| `posts` | `object` | yes | Posts due in the window, by status. |
| `platforms` | `object[]` | yes |  |
| `platforms[].platform` | `Platform` | yes |  |
| `platforms[].targets` | `object` | yes | Publishes to accounts on this platform, by status. |
| `accounts` | `object[]` | yes |  |
| `accounts[].platform` | `Platform` | yes |  |
| `accounts[].accounts` | `object` | yes | Accounts now, by status. |
| `media` | `object` | yes |  |
| `media.files` | `integer` | yes |  |
| `media.bytes` | `integer` | yes |  |

## See also

| Doc | Why |
|---|---|
| [API reference](https://docs.flung.dev/reference/api.md) | Every endpoint |
| [Schemas](https://docs.flung.dev/reference/api/schemas.md) | Every request and response type |
| [Errors](https://docs.flung.dev/reference/api/errors.md) | Every error code and what to do about it |
