# Issuing Stock Rule

The Issuing Stock Rule resource lets you register low-balance alerts for your card stocks.

When the available count of an issuing stock falls below the configured minimum balance, the registered emails and phones are notified.

Each issuing stock can have only one active rule at a time.

### The Issuing Stock Rule object

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `id` | STRING | Unique identifier for the issuing stock rule. |
| `minimumBalance` | INTEGER | Stock count threshold that triggers the alert. Example: 1000. |
| `stockId` | STRING | Id of the IssuingStock monitored by this rule. |
| `emails` | LIST OF STRINGS | List of email addresses notified when the rule is triggered. Max: 10. |
| `phones` | LIST OF STRINGS | List of phone numbers notified when the rule is triggered. Max: 10. |
| `tags` | LIST OF STRINGS | Array of strings to tag the entity for future queries. |
| `status` | STRING | Current rule status. Options: "active", "canceled". |
| `created` | STRING | Creation datetime. Example: "2022-01-01T00:00:00.000000+00:00". |
| `updated` | STRING | Last update datetime. Example: "2022-01-01T00:00:00.000000+00:00". |

### Create Issuing Stock Rules

`POST /v2/issuing-stock-rule`

Use this route to register stock rules.

Send a "rules" array where each element carries the parameters below. At least one email or phone must be informed per rule.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `minimumBalance` | REQUIRED | Stock count threshold that triggers the alert. Must be a positive integer. Example: 1000. |
| `stockId` | REQUIRED | Id of the IssuingStock to monitor. |
| `emails` | OPTIONAL | List of email addresses to notify. Max: 10. |
| `phones` | OPTIONAL | List of phone numbers to notify. Max: 10. |
| `tags` | OPTIONAL | Array of strings to tag the entity for future queries. |

**Request**

```python
import starkinfra

rules = starkinfra.issuingstockrule.create([
    starkinfra.IssuingStockRule(
        minimum_balance=1000,
        stock_id="6724771005489152",
        emails=["aria@stark.com"],
        phones=["+5511999999999"],
        tags=["stock: black-card"]
    )
])

for rule in rules:
    print(rule)
```

**Response**

```python
IssuingStockRule(
    id=5715709195239424,
    minimum_balance=1000,
    stock_id=6724771005489152,
    emails=['aria@stark.com'],
    phones=['+5511999999999'],
    tags=['stock: black-card'],
    status=active,
    created=2022-01-01 00:00:00,
    updated=2022-01-01 00:00:00
)
```

### List Issuing Stock Rules

`GET /v2/issuing-stock-rule`

Get a list of issuing stock rules in chunks of at most 100.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `limit` | OPTIONAL | Number of results per cursor. Max = 100. |
| `cursor` | OPTIONAL | String used to get the next batch of results. Our SDKs handle this for you. |
| `after` | OPTIONAL | Filter entities created after this date. |
| `before` | OPTIONAL | Filter entities created before this date. |
| `status` | OPTIONAL | Filter entities by status. Options: "active", "canceled". |
| `stockIds` | OPTIONAL | List of strings to get rules attached to specific IssuingStock ids. |
| `ids` | OPTIONAL | List of strings to get specific entities by ids. |
| `tags` | OPTIONAL | List of strings to filter entities by tags. |

**Request**

```python
import starkinfra

rules = starkinfra.issuingstockrule.query(
    limit=10,
    status="active"
)

for rule in rules:
    print(rule)
```

**Response**

```python
IssuingStockRule(
    id=5715709195239424,
    minimum_balance=1000,
    stock_id=6724771005489152,
    emails=['aria@stark.com'],
    phones=['+5511999999999'],
    tags=['stock: black-card'],
    status=active,
    created=2022-01-01 00:00:00,
    updated=2022-01-01 00:00:00
)
```

### Update an Issuing Stock Rule

`PATCH /v2/issuing-stock-rule/:id`

Update the properties of an existing issuing stock rule.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the issuing stock rule entity. |
| `minimumBalance` | OPTIONAL | New stock count threshold that triggers the alert. |
| `emails` | OPTIONAL | New list of email addresses to notify. Max: 10. |
| `phones` | OPTIONAL | New list of phone numbers to notify. Max: 10. |
| `tags` | OPTIONAL | New array of strings to tag the entity. |

**Request**

```python
import starkinfra

rule = starkinfra.issuingstockrule.update(
    "5715709195239424",
    minimum_balance=2000,
    emails=["aria@stark.com", "tony@stark.com"]
)

print(rule)
```

**Response**

```python
IssuingStockRule(
    id=5715709195239424,
    minimum_balance=2000,
    stock_id=6724771005489152,
    emails=['aria@stark.com', 'tony@stark.com'],
    phones=['+5511999999999'],
    tags=['stock: black-card'],
    status=active,
    created=2022-01-01 00:00:00,
    updated=2022-06-01 00:00:00
)
```

### Cancel an Issuing Stock Rule

`DELETE /v2/issuing-stock-rule/:id`

Cancel an issuing stock rule. This action is irreversible.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the issuing stock rule entity to cancel. |

**Request**

```python
import starkinfra

rule = starkinfra.issuingstockrule.cancel("5715709195239424")

print(rule)
```

**Response**

```python
IssuingStockRule(
    id=5715709195239424,
    minimum_balance=2000,
    stock_id=6724771005489152,
    emails=['aria@stark.com', 'tony@stark.com'],
    phones=['+5511999999999'],
    tags=['stock: black-card'],
    status=canceled,
    created=2022-01-01 00:00:00,
    updated=2022-06-01 00:00:00
)
```

## Available Languages

Code samples on this page are in Python. The same content is available with samples in:

- [Python](https://docs.starkinfra.com/api/v2/issuing-stock-rule-python.md)
- [Node.js](https://docs.starkinfra.com/api/v2/issuing-stock-rule-node.md)
- [PHP](https://docs.starkinfra.com/api/v2/issuing-stock-rule-php.md)
- [Java](https://docs.starkinfra.com/api/v2/issuing-stock-rule-java.md)
- [Ruby](https://docs.starkinfra.com/api/v2/issuing-stock-rule-ruby.md)
- [Elixir](https://docs.starkinfra.com/api/v2/issuing-stock-rule-elixir.md)
- [.NET](https://docs.starkinfra.com/api/v2/issuing-stock-rule-dotnet.md)
- [Go](https://docs.starkinfra.com/api/v2/issuing-stock-rule-go.md)
- [Clojure](https://docs.starkinfra.com/api/v2/issuing-stock-rule-clojure.md)
- [cURL](https://docs.starkinfra.com/api/v2/issuing-stock-rule-curl.md)
