---
displayed_sidebar: pricingReference
badge:
  variant: orange
  text: Beta
slug: /references/pricing/listAndCountRuleTypes
sidebar_label: listAndCountRuleTypes
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# listAndCountRuleTypes - Pricing Module Reference

This documentation provides a reference to the `listAndCountRuleTypes` method. This belongs to the Pricing Module.

This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.

## Example

To retrieve a list of rule types using their IDs:

```ts
import {
  initialize as initializePricingModule,
} from "@medusajs/pricing"

async function retrieveRuleTypes (ruleTypeId: string) {
  const pricingService = await initializePricingModule()

  const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
    id: [
      ruleTypeId
    ]
  })

  // do something with the rule types or return them
}
```

To specify attributes that should be retrieved within the rule types:

```ts
import {
  initialize as initializePricingModule,
} from "@medusajs/pricing"

async function retrieveRuleTypes (ruleTypeId: string) {
  const pricingService = await initializePricingModule()

  const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
    id: [
      ruleTypeId
    ]
  }, {
    select: ["name"]
  })

  // do something with the rule types or return them
}
```

By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:

```ts
import {
  initialize as initializePricingModule,
} from "@medusajs/pricing"

async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
  const pricingService = await initializePricingModule()

  const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
    id: [
      ruleTypeId
    ]
  }, {
    select: ["name"],
    skip,
    take
  })

  // do something with the rule types or return them
}
```

You can also use the `$and` or `$or` properties of the `filter` parameter to use and/or conditions in your filters. For example:

```ts
import {
  initialize as initializePricingModule,
} from "@medusajs/pricing"

async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
  const pricingService = await initializePricingModule()

  const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
    $and: [
      {
        id: ruleTypeId
      },
      {
        name
      }
    ]
  }, {
    select: ["name"],
    skip,
    take
  })

  // do something with the rule types or return them
}
```

## Parameters

<ParameterTypes parameters={[
  {
    "name": "filters",
    "type": "[FilterableRuleTypeProps](../../pricing/interfaces/pricing.FilterableRuleTypeProps.mdx)",
    "description": "The filters to apply on the retrieved rule types.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "$and",
        "type": "([FilterableRuleTypeProps](../../pricing/interfaces/pricing.FilterableRuleTypeProps.mdx) \\| [BaseFilterable](../../pricing/interfaces/pricing.BaseFilterable.mdx)&#60;[FilterableRuleTypeProps](../../pricing/interfaces/pricing.FilterableRuleTypeProps.mdx)&#62;)[]",
        "description": "An array of filters to apply on the entity, where each item in the array is joined with an \"and\" condition.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "$or",
        "type": "([FilterableRuleTypeProps](../../pricing/interfaces/pricing.FilterableRuleTypeProps.mdx) \\| [BaseFilterable](../../pricing/interfaces/pricing.BaseFilterable.mdx)&#60;[FilterableRuleTypeProps](../../pricing/interfaces/pricing.FilterableRuleTypeProps.mdx)&#62;)[]",
        "description": "An array of filters to apply on the entity, where each item in the array is joined with an \"or\" condition.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "id",
        "type": "`string`[]",
        "description": "The IDs to filter rule types by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "name",
        "type": "`string`[]",
        "description": "The names to filter rule types by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "rule_attribute",
        "type": "`string`[]",
        "description": "The rule attributes to filter rule types by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "config",
    "type": "[FindConfig](../../pricing/interfaces/pricing.FindConfig.mdx)&#60;[RuleTypeDTO](../../pricing/interfaces/pricing.RuleTypeDTO.mdx)&#62;",
    "description": "The configurations determining how the rule types are retrieved. Its properties, such as `select` or `relations`, accept the\nattributes or relations associated with a rule type.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "order",
        "type": "`object`",
        "description": "An object used to specify how to sort the returned records. Its keys are the names of attributes of the entity, and a key's value can either be `ASC`\nto sort retrieved records in an ascending order, or `DESC` to sort retrieved records in a descending order.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "relations",
        "type": "`string`[]",
        "description": "An array of strings, each being relation names of the entity to retrieve in the result.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "select",
        "type": "(`string` \\| keyof `Entity`)[]",
        "description": "An array of strings, each being attribute names of the entity to retrieve in the result.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "skip",
        "type": "`null` \\| `number`",
        "description": "A number indicating the number of records to skip before retrieving the results.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "take",
        "type": "`null` \\| `number`",
        "description": "A number indicating the number of records to return in the result.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "withDeleted",
        "type": "`boolean`",
        "description": "A boolean indicating whether deleted records should also be retrieved as part of the result. This only works if the entity extends the\n`SoftDeletableEntity` class.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "sharedContext",
    "type": "[Context](../../pricing/interfaces/pricing.Context.mdx)",
    "description": "A context used to share resources, such as transaction manager, between the application and the module.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "enableNestedTransactions",
        "type": "`boolean`",
        "description": "A boolean value indicating whether nested transactions are enabled.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "isolationLevel",
        "type": "`string`",
        "description": "A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "manager",
        "type": "`TManager`",
        "description": "An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "transactionId",
        "type": "`string`",
        "description": "A string indicating the ID of the current transaction.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "transactionManager",
        "type": "`TManager`",
        "description": "An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

## Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[[RuleTypeDTO](../../pricing/interfaces/pricing.RuleTypeDTO.mdx)[], number]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "The list of rule types along with their total count.",
    "expandable": false,
    "children": [
      {
        "name": "RuleTypeDTO[]",
        "type": "[RuleTypeDTO](../../pricing/interfaces/pricing.RuleTypeDTO.mdx)[]",
        "optional": false,
        "defaultValue": "",
        "description": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "number",
        "type": "`number`",
        "optional": true,
        "defaultValue": "",
        "description": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />
