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

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

# retrievePriceRule - Pricing Module Reference

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

This method is used to retrieve a price rule by its ID.

## Example

A simple example that retrieves a price rule by its ID:

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

async function retrievePriceRule (id: string) {
  const pricingService = await initializePricingModule()

  const priceRule = await pricingService.retrievePriceRule(id)

  // do something with the price rule or return it
}
```

To specify relations that should be retrieved:

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

async function retrievePriceRule (id: string) {
  const pricingService = await initializePricingModule()

  const priceRule = await pricingService.retrievePriceRule(id, {
    relations: ["price_set"]
  })

  // do something with the price rule or return it
}
```

## Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "The ID of the price rule to retrieve.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../pricing/interfaces/pricing.FindConfig.mdx)&#60;[PriceRuleDTO](../../pricing/interfaces/pricing.PriceRuleDTO.mdx)&#62;",
    "description": "The configurations determining how the price rule is retrieved. Its properties, such as `select` or `relations`, accept the\nattributes or relations associated with a price rule.",
    "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;[PriceRuleDTO](../../pricing/interfaces/pricing.PriceRuleDTO.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "The retrieved price rule.",
    "expandable": false,
    "children": [
      {
        "name": "id",
        "type": "`string`",
        "description": "The ID of the price rule.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "price_list_id",
        "type": "`string`",
        "description": "The ID of the associated price list.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "price_set",
        "type": "[PriceSetDTO](../../pricing/interfaces/pricing.PriceSetDTO.mdx)",
        "description": "The associated price set.",
        "optional": false,
        "defaultValue": "",
        "expandable": true,
        "children": [
          {
            "name": "id",
            "type": "`string`",
            "description": "The ID of the price set.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "money_amounts",
            "type": "[MoneyAmountDTO](../../pricing/interfaces/pricing.MoneyAmountDTO.mdx)[]",
            "description": "The prices that belong to this price set.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "rule_types",
            "type": "[RuleTypeDTO](../../pricing/interfaces/pricing.RuleTypeDTO.mdx)[]",
            "description": "The rule types applied on this price set.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      },
      {
        "name": "price_set_id",
        "type": "`string`",
        "description": "The ID of the associated price set.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "price_set_money_amount_id",
        "type": "`string`",
        "description": "The ID of the associated price set money amount.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "priority",
        "type": "`number`",
        "description": "The priority of the price rule in comparison to other applicable price rules.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "rule_type",
        "type": "[RuleTypeDTO](../../pricing/interfaces/pricing.RuleTypeDTO.mdx)",
        "description": "The associated rule type.",
        "optional": false,
        "defaultValue": "",
        "expandable": true,
        "children": [
          {
            "name": "default_priority",
            "type": "`number`",
            "description": "The priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy \nthe provided context. The higher the value, the higher the priority of the rule type.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "id",
            "type": "`string`",
            "description": "The ID of the rule type.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "name",
            "type": "`string`",
            "description": "The display name of the rule type.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "rule_attribute",
            "type": "`string`",
            "description": "The unique name used to later identify the rule\\_attribute. For example, it can be used in the `context` parameter of \nthe `calculatePrices` method to specify a rule for calculating the price.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      },
      {
        "name": "rule_type_id",
        "type": "`string`",
        "description": "The ID of the associated rule type.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "value",
        "type": "`string`",
        "description": "The value of the price rule.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />
