# List grant blocks

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Eventually Consistent](/docs/api/read-consistency)

Returns a list of grant blocks meeting all the conditions specified in the filter parameters below.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/grant_blocks \
     -G  \
     -u {site_api_key}:\
     --data-urlencode "subscription_id[is]"="1mGETgZVF2umUZq" \
     --data-urlencode "account_type[is]"="PROVISIONED" \
     --data-urlencode "sort_by[desc]"="created_at"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;
using ChargeBee.Models.Enums;
using ChargeBee.Filters.Enums;

ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = GrantBlock.ListGrantBlocks()
		.SubscriptionId().Is("1mGETgZVF2umUZq")
		.AccountType().Is(GrantBlock.AccountTypeEnum.Provisioned)
		.SortByCreatedAt(SortOrderEnum.Desc)
		.Request();

foreach (var listItem in result.List){
  GrantBlock grantBlock = listItem.GrantBlock;
}
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    "github.com/chargebee/chargebee-go/v3/filter"
    grantblockAction "github.com/chargebee/chargebee-go/v3/actions/grantblock"
    "github.com/chargebee/chargebee-go/v3/models/grantblock"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := grantblockAction.ListGrantBlocks(&grantblock.ListGrantBlocksRequestParams{
        SubscriptionId : &filter.StringFilter{
            Is : "1mGETgZVF2umUZq",
        },
        AccountType : &filter.EnumFilter{
            Is : "provisioned",
        },
        SortBy : &filter.SortFilter{
            Desc : "created_at",
        },
    }).ListRequest()
    if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            GrantBlock := res.List[idx].GrantBlock
        }
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.GrantBlockListGrantBlocksRequest{
    SubscriptionId : &chargebee.StringFilter{
        Is : "1mGETgZVF2umUZq",
    },
    AccountType : &chargebee.EnumFilter{
        Is : "provisioned",
    },
    SortBy : &chargebee.SortFilter{
        Desc : "created_at",
    },
}
  res, err := client.GrantBlock.ListGrantBlocks(req)
      if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            GrantBlock := res.List[idx].GrantBlock
        }
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.filters.enums.SortOrder;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.util.List;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        ListResult result = GrantBlock.listGrantBlocks().subscriptionId().is("1mGETgZVF2umUZq").accountType().is(GrantBlock.AccountType.PROVISIONED).sortByCreatedAt(SortOrder.DESC).request();

        for (ListResult.Entry entry : result) {
            GrantBlock grantBlock = entry.grantBlock();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.grantBlock.GrantBlock;
import com.chargebee.v4.models.grantBlock.params.ListGrantBlocksParams;
import com.chargebee.v4.models.grantBlock.responses.ListGrantBlocksResponse;
import java.util.List;

public class ListGrantBlocks {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        ListGrantBlocksParams params = ListGrantBlocksParams.builder()
            .subscriptionId()
            .is("1mGETgZVF2umUZq")
            .accountType()
            .is(ListGrantBlocksParams.AccountType.PROVISIONED)
            .sortBy()
            .created_at()
            .desc()
            .build();

        ListGrantBlocksResponse response = client.grantBlocks().listGrantBlocks(params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.grantBlock.listGrantBlocks({
        subscription_id: {
            is: "1mGETgZVF2umUZq"
        },
        account_type: {
            is: "provisioned"
        },
        "sort_by[desc]": "created_at"
    });
    result.list.forEach((entry) => {
        console.log(entry);
        const grantBlock = entry.grant_block;
    });
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->grantBlock()->listGrantBlocks([
    "subscription_id" => [
        "is" => "1mGETgZVF2umUZq"
    ],
    "account_type" => [
        "is" => "provisioned"
    ],
    "sort_by" => [
        "desc" => "created_at"
    ]
]);
foreach($result->list as $entry) {
    $grantBlock = $entry->grant_block;
}
```

#### Python

```python
import chargebee
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.GrantBlock.list_grant_blocks(
    cb_client.GrantBlock.ListGrantBlocksParams(
        subscription_id=Filters.StringFilter(IS="1mGETgZVF2umUZq"),
        account_type=Filters.EnumFilter(IS=chargebee.GrantBlock.AccountType.PROVISIONED),
        sort_by=Filters.SortFilter(DESC="created_at")
    )
)
for entry in entries.list:
    grant_block = entry.grant_block
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

list = ChargeBee::GrantBlock.list_grant_blocks({
  "subscription_id[is]" => "1mGETgZVF2umUZq",
  "account_type[is]" => "provisioned",
  "sort_by[desc]" => "created_at"
})

list.each do |entry|
  grant_block = entry.grant_block
end
```

## Sample Response

```json
{
  "list": [
    {
      "grant_block": {
        "id": "gb_ai_credits_001",
        "subscription_id": "1mGETgZVF2umUZq",
        "unit_id": "ai_credits",
        "unit_type": "credit_unit",
        "account_type": "provisioned",
        "effective_from": 1746723600,
        "expires_at": 1775402925,
        "status": "available",
        "grant_source": "subscription_created",
        "created_at": 1746723600,
        "modified_at": 1774978599,
        "resource_version": 1774978599000,
        "object": "grant_block",
        "provisioned_block_balance": {
          "granted_amount": "100.25",
          "total_balance": "100.25",
          "usable_balance": "49.7975",
          "hold_amount": "50.4525",
          "used_amount": "0",
          "expired_amount": "0",
          "rolled_over_amount": "0",
          "voided_amount": "0"
        },
        "overdraft_block_balance": null
      }
    },
    {..}
  ],
  "next_offset": "[\"1746723600000\",\"2019805959311302272\"]"
}
```

## URL Format

**GET** https://[site].chargebee.com/api/v2/grant_blocks

## Input Parameters

- `limit` (optional, integer, default=10, min=1, max=100)
  Specifies the maximum number of resources to return per page.
  
  **Default and Hard Cap**
  
  -   Optional parameter; if omitted, a server-defined default is applied.
  -   Values exceeding the server's maximum limit are capped (clamped) to the allowed maximum.
  
  **Example →** _limit = "50"_

- `offset` (optional, string, max chars=1000)
  Opaque cursor indicating the current position in the result set for pagination.
  
  **Behavior**
  
  -   To fetch the next page, pass the next\_offset value returned in the previous response.
  -   The value is opaque and must not be parsed, modified, or constructed manually.
  
  **Example →** _offset = "\["1771176208000","96000000006"\]"_

## Returns

- `next_offset` (optional, string, max chars=1000)
  This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter `offset`.

- `grant_block` (Grant block object)
  Resource object representing a credit grant block. The response is the standard Chargebee [list envelope](/docs/api/list-ops): `{ "list": [{ "grant_block": { ... } }, ...], "next_offset": "..." }`, where each `list` item wraps a single `grant_block` under its resource name.
