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

# Entitlement checks

> Check feature access and retrieve entitlements for customers using Stigg backend SDKs.

## Entitlement checks

Stigg supports three types of feature entitlements: **boolean** (on/off), **numeric** (configuration values), and **metered** (usage-tracked with limits).

### Generic entitlement check (recommended)

A unified method to check any type of feature entitlement. It automatically returns the appropriate entitlement type based on the feature configuration.

You provide the customer ID and feature ID. Optionally, pass a resource ID for multi-subscription products, or a requested usage amount to proactively check if additional usage would be allowed (metered features only).

<CodeGroup>
  ```javascript Node.js theme={null}
  const entitlement = await stiggClient.getEntitlement({
    customerId: 'customer-demo-01',
    featureId: 'feature-demo-01',
    resourceId: 'resource-01', // optional, pass it to get entitlement of specific resource
  });

  if (entitlement.hasAccess) {
    // Customer has access to the feature
  } else {
    // Access denied
    console.log('Access denied reason:', entitlement.accessDeniedReason);
  }

  // Entitlement contains the specific entitlement details
  // based on feature type (boolean, numeric, or metered)
  switch (entitlement.type) {
    case "NUMERIC":
      console.log('Numeric value:', entitlement.value);
      break;
    case "METERED":
      console.log('Usage limit:', entitlement.usageLimit);
      console.log('Current usage:', entitlement.currentUsage);
      break;
    case "BOOLEAN":
      break;
  }
  ```

  ```python Python theme={null}
  resp = await client.get_entitlement(FetchEntitlementQuery(
    **{
      "customerId": "customer-id",
      "featureId": "feature-01-templates",
      "options": {
        "requestedUsage": 10
      },
      "resourceId": "resource-01",  # optional, pass it to get entitlement of specific resource
    }
  ))

  if resp.entitlement.is_granted:
    # customer has access to the feature
    pass
  else:
    # access denied
    pass
  ```

  ```go Go theme={null}
  result, err := client.GetEntitlement(context.Background(), stigg.FetchEntitlementQuery{
    CustomerID: "customer-demo-01",
    FeatureID:  "feature-01-templates",
    Options: &stigg.EntitlementOptions{
      RequestedUsage: Ptr(float64(0)),
    },
    ResourceID: Ptr("resource-01"),  // optional, pass it to get entitlement of specific resource
  })

  if result.Entitlement.IsGranted {
    // customer has access to the feature
  } else {
    // access denied
  }
  ```

  ```ruby Ruby theme={null}
  resp = client.request(Stigg::Query::GetEntitlement, {
    "query": {
      "customerId": "customer-id",
      "featureId": "feature-01-templates",
      "options": {
        "requestedUsage": 10
      },
      "resourceId": "resource-01",  # optional, pass it to get entitlement of specific resource
    }
  })

  if resp.data.entitlement.is_granted
      puts "Customer has access to the feature"
  else
      puts "Access denied"
  end
  ```

  ```java Java theme={null}
  var resp =
    stigg.query(
      GetEntitlementQuery.builder()
      .query(FetchEntitlementQuery.builder()
             .customerId("customer-demo-01")
             .featureId("feature-01-templates")
             .options(EntitlementOptions.builder()
                      .requestedUsage(10.0)
                      .build())
             .resourceId("resource-01") // optional
             .build())
      .build()
    );
  ```

  ```c# .NET theme={null}
  var resp = await stigg.GetEntitlement.ExecuteAsync(new FetchEntitlementQuery()
  {
    CustomerId = "customer-demo-01",
    FeatureId = "feature-02-templates",
    ResourceId = "resource-01" // optional
  });
  ```
</CodeGroup>

<Expandable title="Result - boolean feature">
  ```json theme={null}
  {
    "isFallback": false,
    "hasAccess": true,
    "entitlement": {
      "type": "BOOLEAN",
      "feature": {
          "id": "feature-demo-01",
          "featureType": "Boolean",
          "meterType": "None",
          "isMetered": false
      }
    }
  }
  ```
</Expandable>

<Expandable title="Result - numeric feature">
  ```json theme={null}
  {
    "isFallback": false,
    "hasAccess": true,
    "entitlement": {
      "type": "NUMERIC",
      "feature": {
        "id": "feature-demo-02",
        "featureType": "Numeric",
        "units": "request",
        "unitsPlural": "requests",
        "isMetered": false
      },
      "value": 100,
      "isUnlimited": false
    }
  }
  ```
</Expandable>

<Expandable title="Result - metered feature">
  ```json theme={null}
  {
    "isFallback": false,
    "hasAccess": true,
    "entitlement": {
      "type": "METERED",
      "feature": {
        "id": "feature-demo-03",
        "featureType": "Numeric",
        "meterType": "Incremental",
        "units": "request",
        "unitsPlural": "requests",
        "isMetered": true
      },
      "usageLimit": 2,
      "isUnlimited": false,
      "currentUsage": 0,
      "resetPeriod": "MONTH"
    }
  }
  ```
</Expandable>

### Boolean entitlement check

Check whether a customer has access to a boolean (on/off) feature.

<CodeGroup>
  ```javascript Node.js theme={null}
  const entitlement = await stiggClient.getBooleanEntitlement({
    customerId: 'customer-demo-01',
    featureId: 'feature-demo-01',
    resourceId: 'resource-01',      // optional
  });

  if (entitlement.hasAccess) {
    // customer has access to the feature
  } else {
    // access denied
  }
  ```

  ```python Python theme={null}
  resp = await client.get_entitlement(FetchEntitlementQuery(
    **{
      "customerId": "customer-id",
      "featureId": "feature-demo-01",
      "resourceId": "resource-01",  # optional
    }
  ))

  if resp.entitlement.is_granted:
    # customer has access
    pass
  ```

  ```go Go theme={null}
  result, err := client.GetEntitlement(context.Background(), stigg.FetchEntitlementQuery{
    CustomerID: "customer-demo-01",
    FeatureID:  "feature-demo-01",
    ResourceID: Ptr("resource-01"),  // optional
  })

  if result.Entitlement.IsGranted {
    // customer has access
  }
  ```

  ```ruby Ruby theme={null}
  resp = client.request(Stigg::Query::GetEntitlement, {
    "query": {
      "customerId": "customer-id",
      "featureId": "feature-demo-01",
      "resourceId": "resource-01",  # optional
    }
  })

  if resp.data.entitlement.is_granted
      puts "Customer has access"
  end
  ```

  ```java Java theme={null}
  var req =
    GetBooleanEntitlementRequest.newBuilder()
    .setCustomerId("customer-demo-01")
    .setFeatureId("feature-demo-01")
    .setResourceId("resource-01") // optional
    .build();

  var res = stigg.getBooleanEntitlement(req);

  if (res.getHasAccess()) {
    // Customer has access to the feature
  }
  ```

  ```c# .NET theme={null}
  var resp = await stigg.GetEntitlement.ExecuteAsync(new FetchEntitlementQuery()
  {
    CustomerId = "customer-demo-01",
    FeatureId = "feature-demo-01",
    ResourceId = "resource-01" // optional
  });
  ```
</CodeGroup>

### Numeric entitlement check

Retrieve the numeric value configured for a feature (e.g., max file size, API rate limit).

<CodeGroup>
  ```javascript Node.js theme={null}
  const entitlement = await stiggClient.getNumericEntitlement({
    customerId: 'customer-demo-01',
    featureId: 'feature-demo-02',
    resourceId: 'resource-01',      // optional
  });

  if (entitlement.hasAccess) {
    console.log(entitlement.value);
  }
  ```

  ```python Python theme={null}
  resp = await client.get_entitlement(FetchEntitlementQuery(
    **{
      "customerId": "customer-id",
      "featureId": "feature-demo-02",
      "resourceId": "resource-01",  # optional
    }
  ))
  ```

  ```go Go theme={null}
  result, err := client.GetEntitlement(context.Background(), stigg.FetchEntitlementQuery{
    CustomerID: "customer-demo-01",
    FeatureID:  "feature-demo-02",
    ResourceID: Ptr("resource-01"),  // optional
  })
  ```

  ```ruby Ruby theme={null}
  resp = client.request(Stigg::Query::GetEntitlement, {
    "query": {
      "customerId": "customer-id",
      "featureId": "feature-demo-02",
      "resourceId": "resource-01",  # optional
    }
  })
  ```

  ```java Java theme={null}
  var req =
    GetNumericEntitlementRequest.newBuilder()
    .setCustomerId("customer-demo-01")
    .setFeatureId("feature-demo-02")
    .setResourceId("resource-01") // optional
    .build();

  var res = stigg.getNumericEntitlement(req);

  if (res.getHasAccess()) {
    var value = res.getEntitlement().getValue();
  }
  ```

  ```c# .NET theme={null}
  var resp = await stigg.GetEntitlement.ExecuteAsync(new FetchEntitlementQuery()
  {
    CustomerId = "customer-demo-01",
    FeatureId = "feature-demo-02",
    ResourceId = "resource-01" // optional
  });
  ```
</CodeGroup>

### Metered entitlement check

Check whether a customer's usage of a metered feature is within the allowed quota. You can optionally provide a requested usage amount to proactively verify if a specific amount of additional usage would be allowed before performing the action.

<CodeGroup>
  ```javascript Node.js theme={null}
  const entitlement = await stiggClient.getMeteredEntitlement({
    customerId: 'customer-demo-01',
    featureId: 'feature-demo-03',
    resourceId: 'resource-01',      // optional
    options: {
      requestedUsage: 10             // optional, proactively check usage
    },
  });

  if (entitlement.hasAccess) {
    // has access and the requested usage is within the allowed quota
  } else {
    // the customer has exceeded his quota for this feature
  }
  ```

  ```python Python theme={null}
  resp = await client.get_entitlement(FetchEntitlementQuery(
    **{
      "customerId": "customer-id",
      "featureId": "feature-demo-03",
      "options": {
        "requestedUsage": 10
      },
      "resourceId": "resource-01",  # optional
    }
  ))
  ```

  ```go Go theme={null}
  result, err := client.GetEntitlement(context.Background(), stigg.FetchEntitlementQuery{
    CustomerID: "customer-demo-01",
    FeatureID:  "feature-demo-03",
    Options: &stigg.EntitlementOptions{
      RequestedUsage: Ptr(float64(10)),
    },
    ResourceID: Ptr("resource-01"),  // optional
  })
  ```

  ```ruby Ruby theme={null}
  resp = client.request(Stigg::Query::GetEntitlement, {
    "query": {
      "customerId": "customer-id",
      "featureId": "feature-demo-03",
      "options": {
        "requestedUsage": 10
      },
      "resourceId": "resource-01",  # optional
    }
  })
  ```

  ```java Java theme={null}
  var req =
    GetMeteredEntitlementRequest.newBuilder()
    .setCustomerId("customer-demo-01")
    .setFeatureId("feature-demo-03")
    .setResourceId("resource-01") // optional
    .setOptions(MeteredEntitlementOptions.newBuilder()
                .setRequestedUsage(10)
                .build())
    .build();

  var resp = stigg.getMeteredEntitlement(req);

  if (resp.getHasAccess()){
    // Has access, current usage is within the allowed quota
  }
  ```

  ```c# .NET theme={null}
  var resp = await stigg.GetEntitlement.ExecuteAsync(new FetchEntitlementQuery()
  {
    CustomerId = "customer-demo-01",
    FeatureId = "feature-demo-03",
    ResourceId = "resource-01" // optional
  });
  ```
</CodeGroup>

### Getting all entitlements

Retrieve all entitlements for a customer (or a specific resource), returning the full list of features they have access to along with usage limits and current usage.

<CodeGroup>
  ```javascript Node.js theme={null}
  const entitlementsState = await stiggClient.getEntitlementsState(
    'customer-demo-01',
    'resource-01', // optional
  );

  entitlementsState.entitlements.forEach((entitlement) => {
    console.log(JSON.stringify(entitlement));
  });
  ```

  ```python Python theme={null}
  data = await client.get_entitlements_state(FetchEntitlementsQuery(
    **{
      "customerId": "customer-demo-01",
      "resourceId": "resource-01",  # optional
    }
  ))
  ```

  ```go Go theme={null}
  result, err := client.GetEntitlementsState(context.Background(), stigg.FetchEntitlementsQuery{
    CustomerID: "customer-demo-01",
    ResourceID: Ptr("resource-01"), // optional
  })
  ```

  ```ruby Ruby theme={null}
  resp = client.request(Stigg::Query::GetEntitlementsState, {
    "query": {
      "customerId": "customer-demo-01",
      "resourceId": "resource-01",  # optional
    }
  })
  ```

  ```java Java theme={null}
  var resp = stigg.query(
    GetEntitlementsStateQuery.builder()
    .query(
      FetchEntitlementsQuery.builder()
      .customerId("customer-demo-01")
      .resourceId("resource-01") // optional
      .build())
    .build());
  ```

  ```c# .NET theme={null}
  var resp = await stigg.GetEntitlementsState.ExecuteAsync(new FetchEntitlementsQuery()
  {
    CustomerId = "customer-demo-01",
    ResourceId = "resource-01" // optional
  });
  ```
</CodeGroup>
