> ## Documentation Index
> Fetch the complete documentation index at: https://www.marqeta.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Card Counts

> Retrieve card count data, such as the number of cards in circulation or how many are active or suspended, at a specified aggregation level. The data is derived from the transaction-related messages sent to and from the Marqeta platform.

export const EndpointCard = ({method = "API", title, children, href, arrow = true}) => {
  const METHOD_STYLES = {
    GET: {
      bg: "mint-bg-green-400/20 dark:mint-bg-green-400/20",
      text: "mint-text-green-700 dark:mint-text-green-400",
      border: "mint-border-green-300 dark:mint-border-green-700"
    },
    POST: {
      bg: "mint-bg-blue-400/20 dark:mint-bg-blue-400/20",
      text: "mint-text-blue-700 dark:mint-text-blue-400"
    },
    PUT: {
      bg: "mint-bg-yellow-400/20 dark:mint-bg-yellow-400/20",
      text: "mint-text-yellow-700 dark:mint-text-yellow-400"
    },
    PATCH: {
      bg: "mint-bg-orange-400/20 dark:mint-bg-orange-400/20",
      text: "mint-text-orange-700 dark:mint-text-orange-400"
    },
    DELETE: {
      bg: "mint-bg-red-400/20 dark:mint-bg-red-400/20",
      text: "mint-text-red-700 dark:mint-text-red-400"
    },
    API: {
      bg: "mint-bg-black",
      text: "mint-text-white"
    }
  };
  const MethodBadge = ({method}) => {
    const style = METHOD_STYLES[method?.toUpperCase()] ?? METHOD_STYLES.GET;
    return <span className={`
          method-pill rounded-lg font-semibold px-1.5 py-0.5 text-xs leading-5 ${style.bg} ${style.text}`}>
        {method?.toUpperCase()}
      </span>;
  };
  const content = <div className="group flex items-center gap-4 border border-gray-200 dark:border-gray-700 rounded-xl p-5 hover:border-gray-400 dark:hover:border-gray-500 hover:shadow-md transition-all cursor-pointer">
      {}
      <div className="shrink-0">
        <MethodBadge method={method} />
      </div>
      {}
      <div className="flex-1 min-w-0">
        <p className="font-semibold text-gray-900 dark:text-white text-sm leading-snug">{title}</p>
        {children && <p className="mt-1 text-sm text-gray-500 dark:text-gray-400 line-clamp-2">{children}</p>}
      </div>
    </div>;
  if (!href) return content;
  return <a href={href} className="block no-underline border-b-0 mb-2">
      {content}
    </a>;
};

Retrieve card count data, such as the number of cards in circulation or how many are active or suspended, at a specified aggregation level. The data is derived from the transaction-related messages sent to and from the Marqeta platform.

This endpoint supports multiple response formats, query filtering, field filtering, sorting, and pagination. For more information about response options, see [Response Customization](/diva-api/response-customization/).

<h2 id="_retrieve_card_count_data_json">
  Retrieve card count data (JSON)
</h2>

**Action:** `GET`\
**Endpoint:** `/views/cardcounts/{time_agg}`

Retrieve card data, aggregated over the specified time period. This endpoint returns a JSON object that contains an array of records matching your filter query.

<h3 id="_url_path_parameters">
  URL path parameters
</h3>

| Fields                                    | Description                                                                                                                                                                                                                             |
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| time\_agg<br /><br />string<br />Required | Time period over which to aggregate the data. For more information, see <a href="/diva-api/response-customization/#_data_aggregation_levels">Data aggregation levels</a> .<br /><br />**Allowable Values:**<br /><br />day, week, month |

<h3 id="_sample_response_body">
  Sample response body
</h3>

The following sample shows a representative response for a `GET` request to the `/views/cardcounts/day?program=my_program&fields=card_type,in_suspension_eop,in_suspension_ever_during` endpoint.

```json JSON expandable lines wrap theme={null}
{
    "total": 32,
    "is_more": false,
    "count": 32,
    "info": {},
    "start_date": "2019-02-01T00:00:00+0000",
    "end_date": "2019-02-14T00:00:00+0000",
    "last_run_time": "2019-02-07T00:02:00Z",
    "schema": [
        {
            "field": "card_type",
            "type": "character varying(128)",
            "description": "The type of card: virtual, physical.",
            "display": "Card Type",
            "enum_values": [],
            "units": null,
            "has_total": false,
            "is_filter_only": false
        },
        {
            "field": "in_suspension_eop",
            "type": "bigint",
            "description": null,
            "display": "In Suspension Eop",
            "units": null,
            "has_total": false,
            "is_filter_only": false
        },
        {
            "field": "in_suspension_ever_during",
            "type": "bigint",
            "description": null,
            "display": "In Suspension Ever During",
            "units": null,
            "has_total": false,
            "is_filter_only": false
        }
    ],
    "records": [
        {
            "card_type": "VIRTUAL_PAN",
            "in_suspension_eop": 7,
            "in_suspension_ever_during": 7
        },
        {
            "card_type": "PHYSICAL_MSR",
            "in_suspension_eop": 0,
            "in_suspension_ever_during": 0
        },
        ...
        {
            "card_type": "VIRTUAL_PAN",
            "in_suspension_eop": 7,
            "in_suspension_ever_during": 7
        }
    ]
}
```

<h2 id="_retrieve_card_count_data_file_export">
  Retrieve card count data (file export)
</h2>

**Action:** `GET`\
**Endpoint:** `/views/cardcounts/{time_agg}/{export_type}`

Retrieve card count data, aggregated over the specified time period. This endpoint asynchronously generates a file in the specified format and returns a job token for retrieving the file when it is completed. The file contains a list of records matching your filter query.

<h3 id="_url_path_parameters_2">
  URL path parameters
</h3>

| Fields                                       | Description                                                                                                                                                                                                                             |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| time\_agg<br /><br />string<br />Required    | Time period over which to aggregate the data. For more information, see <a href="/diva-api/response-customization/#_data_aggregation_levels">Data aggregation levels</a> .<br /><br />**Allowable Values:**<br /><br />day, week, month |
| export\_type<br /><br />string<br />Required | File format in which to export the data.<br /><br />**Allowable Values:**<br /><br />csv                                                                                                                                                |

<h3 id="_query_parameters">
  Query parameters
</h3>

| Fields                                   | Description                                                                                                                               |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| compress<br /><br />string<br />optional | Type of file compression for the exported file.<br /><br />**Allowable Values:**<br /><br />gz, zip<br /><br />**Default value:**<br />gz |

<h3 id="_sample_response_body_2">
  Sample response body
</h3>

```json JSON lines wrap theme={null}
{
  "token": "111122226c444d8888888a9999ae11111db63da4.csv.gz"
}
```

<h2 id="_retrieve_card_count_schema">
  Retrieve card count schema
</h2>

**Action:** `GET`\
**Endpoint:** `/views/cardcounts/{time_agg}/schema`

Retrieve a JSON representation of the cardcounts view schema for data aggregated over the specified time period. The schema object contains an array of objects that describe the available columns and the data type of each column.

<h3 id="_url_path_parameters_3">
  URL path parameters
</h3>

| Fields                                    | Description                                                                                                                                                                                                                             |
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| time\_agg<br /><br />string<br />Required | Time period over which to aggregate the data. For more information, see <a href="/diva-api/response-customization/#_data_aggregation_levels">Data aggregation levels</a> .<br /><br />**Allowable Values:**<br /><br />day, week, month |

<h3 id="_sample_response_body_3">
  Sample response body
</h3>

The following sample shows a representative response for a `GET` request to the `/views/cardcounts/day/schema?program=my_program` endpoint. The schema can vary based on the data aggregation level and the data you are authorized to access (based on the credentials you provide in your request).

```json JSON expandable lines wrap theme={null}
[
    {
        "field": "program",
        "type": "character varying(128)",
        "description": "The name of the card program.",
        "display": "Program",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "period_start_date",
        "type": "date",
        "description": null,
        "display": "Period Start Date",
        "units": null,
        "has_total": false,
        "date_format": "YYYY-MM-DD",
        "is_filter_only": false
    },
    {
        "field": "card_type",
        "type": "character varying(128)",
        "description": "The type of card: virtual, physical.",
        "display": "Card Type",
        "enum_values": [],
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "circulating_eop",
        "type": "bigint",
        "description": null,
        "display": "Circulating Eop",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "active_eop",
        "type": "bigint",
        "description": null,
        "display": "Active Eop",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "in_suspension_eop",
        "type": "bigint",
        "description": null,
        "display": "In Suspension Eop",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "circulating_ever_during",
        "type": "bigint",
        "description": null,
        "display": "Circulating Ever During",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "active_ever_during",
        "type": "bigint",
        "description": null,
        "display": "Active Ever During",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "in_suspension_ever_during",
        "type": "bigint",
        "description": null,
        "display": "In Suspension Ever During",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "issued_during_period",
        "type": "bigint",
        "description": null,
        "display": "Issued During Period",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "activated_during_period",
        "type": "bigint",
        "description": null,
        "display": "Activated During Period",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "suspended_during_period",
        "type": "bigint",
        "description": null,
        "display": "Suspended During Period",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "terminated_during_period",
        "type": "bigint",
        "description": null,
        "display": "Terminated During Period",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "swiped_during_period",
        "type": "bigint",
        "description": null,
        "display": "Swiped During Period",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    },
    {
        "field": "entry_createdate",
        "type": "timestamp without time zone",
        "description": "The date and time when a record has been read into the database following a replication cycle.",
        "display": "Entry Createdate",
        "units": null,
        "has_total": false,
        "date_format": "YYYY-MM-DD",
        "is_filter_only": false
    },
    {
        "field": "last_modified_time",
        "type": "timestamp without time zone",
        "description": "The date when the record was most recently updated.",
        "display": "Last Modified Time",
        "units": null,
        "has_total": false,
        "date_format": "YYYY-MM-DD",
        "is_filter_only": false
    },
    {
        "field": "etl_batch_id",
        "type": "bigint",
        "description": null,
        "display": "Etl Batch Id",
        "units": null,
        "has_total": false,
        "is_filter_only": false
    }
]
```
