# GraphQL Queries

Query operation schemas and runnable GraphQL examples.

<!-- docs-source -->
Source: https://learning.monetizekit.app/docs/graphql/queries
<!-- /docs-source -->

## GraphQL endpoint

`https://app.monetizekit.app/api/graphql`

> [!NOTE] Authentication and execution
>
> You can browse the schema and examples without signing in. Sign in and provide your own API token to execute live operations.

## Query operations

### OBJECT Query

| Field | Type | Arguments | Complexity | Description | Deprecated |
| --- | --- | --- | --- | --- | --- |
| `plan` | Plan | key: String! (required) | 4 | Get one plan with entitlements | No |
| `customers` | [Customer] | first: Int, after: String | 6 | List customers | No |
| `entitlementCheck` | EntitlementDecision | customerId: ID! (required), featureKey: String! (required) | 3 | Check one entitlement decision | No |
| `usageCounter` | UsageCounter | customerId: ID! (required), meterKey: String! (required) | 3 | Fetch usage counter | No |
| `creditBalance` | CreditBalance | customerId: ID! (required) | 3 | Fetch customer credits | No |

## Curated examples

### Plan with entitlements

```graphql
query PlanWithEntitlements($key: String!) {
  plan(key: $key) {
    id
    key
    entitlements {
      featureKey
      value
    }
  }
}
```

Variables

```json
{
  "key": "starter_monthly"
}
```

### Customers with subscriptions

```graphql
query CustomersWithSubscriptions($first: Int) {
  customers(first: $first) {
    id
    externalId
    subscriptions {
      id
      planKey
    }
  }
}
```

Variables

```json
{
  "first": 20
}
```

### Single entitlement check

```graphql
query SingleEntitlement($customerId: ID!, $featureKey: String!) {
  entitlementCheck(customerId: $customerId, featureKey: $featureKey) {
    allowed
    reason
  }
}
```

Variables

```json
{
  "customerId": "cust_dev_1001",
  "featureKey": "analytics_export"
}
```

### Usage data

```graphql
query UsageData($customerId: ID!, $meterKey: String!) {
  usageCounter(customerId: $customerId, meterKey: $meterKey) {
    meterKey
    current
    limit
  }
}
```

Variables

```json
{
  "customerId": "cust_dev_1001",
  "meterKey": "api_requests"
}
```

### Credit balances

```graphql
query CreditBalances($customerId: ID!) {
  creditBalance(customerId: $customerId) {
    available
    pending
  }
}
```

Variables

```json
{
  "customerId": "cust_dev_1001"
}
```