# Test a rule

`POST https://api.fiscalisto.com/v1/rules/{id}/test`

What it would do with an invoice (uuid) or with the most recent ones of its trigger, without changing anything: each condition with what the record has and whether it's met.

## Parameters

| Name | In | Required | Description |
| --- | --- | --- | --- |
| `id` | path | yes | The object's id. |
| `Idempotency-Key` | header |  | Optional (the SDKs send it on their own). If the response is lost, repeat the request with the same value within 24 hours: it answers the same, with idempotent-replayed: true, and doesn't do it twice (it doesn't create, send emails or charge). |

## Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `uuid` | string (uuid) |  | The folio fiscal (UUID) of an invoice; without it, the most recent ones. |
| `limit` | integer |  | How many of the most recent (10 by default). (from 1 to 50) |

Example:

```json
{
  "uuid": "5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B"
}
```

## With the TypeScript SDK

```ts
import { Fiscalisto } from "fiscalisto";

// La llave viene de FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const { data } = await fiscalisto.rules.test("id", { uuid: "5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B" }, { idempotencyKey: "pedido-A-1042" });
```

## With the Python SDK

```python
from fiscalisto import Fiscalisto

# La llave viene de FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

data = fiscalisto.rules.test("id", {"uuid": "5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B"}, idempotency_key="pedido-A-1042")["data"]
```

## With the PHP SDK

```php
<?php

use Fiscalisto\Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$data = $fiscalisto->rules->test('id', [
    'uuid' => '5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B',
], ['idempotency_key' => 'pedido-A-1042'])['data'];
```

## With the .NET SDK

```csharp
using Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var ruleTestList = await fiscalisto.Rules.TestAsync("id", new TestRuleParams
{
    Uuid = "5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B",
}, new RequestOptions { IdempotencyKey = "pedido-A-1042" });
```

## With the Go SDK

```go
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// La llave viene de FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	ruleTestList, err := client.Rules.Test(ctx, "id", &fiscalisto.TestRuleParams{
		UUID: fiscalisto.String("5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B"),
	}, fiscalisto.WithIdempotencyKey("pedido-A-1042"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *ruleTestList)
}
```

## With the Java SDK

```java
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.TestRuleParams;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var ruleTestList = fiscalisto.rules().test("id", new TestRuleParams().setUuid("5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B"), RequestOptions.idempotencyKey("pedido-A-1042"));
System.out.println(ruleTestList);
```

## Response 200

OK.

A `RuleTestList` object:

| Field | Type | Always present | Description |
| --- | --- | --- | --- |
| `object` | `"list"` | yes | What kind of object it is («invoice», «customer»…). |
| `data` | array of object | yes | The objects on this page. |
| `data[].object` | `"rule_test"` | yes | What kind of object it is («invoice», «customer»…). |
| `data[].record` | string | yes | The invoice, order or bank movement, in words. |
| `data[].invoice_uuid` | string or null |  | The tax folio, for an invoice. |
| `data[].purchase_order` | integer |  | The purchase order. (from -9007199254740991 to 9007199254740991) |
| `data[].bank_movement` | string |  | The bank movement, its id in /v1/accounting/bank_movements: bwd_… a withdrawal, btx_… a deposit. |
| `data[].matches` | boolean | yes | Whether its conditions are met. |
| `data[].already_ran` | boolean | yes | It already ran on this record and won't again. |
| `data[].conditions` | array of object | yes | Each condition with what the record has. |
| `data[].conditions[].condition` | string | yes | The condition, in words. |
| `data[].conditions[].holds` | boolean | yes | Whether it is met. |
| `data[].conditions[].actual` | string | yes | What the record has. |
| `data[].would_do` | array of string | yes | What it would do, in words (nothing changes). |
| `has_more` | boolean | yes | true if there are more: request the next one with starting_after set to the id of the last one. |
| `url` | string | yes | This list's path. |

```json
{
  "object": "list",
  "data": [
    {
      "object": "rule_test",
      "record": "Factura A-120 de ACEROS DEL NORTE",
      "invoice_uuid": "5F3B2A10-8C4D-4E6F-9A1B-2C3D4E5F6A7B",
      "matches": true,
      "already_ran": false,
      "conditions": [
        {
          "condition": "Proveedor es ADN0101019Z3",
          "holds": true,
          "actual": "ADN0101019Z3"
        }
      ],
      "would_do": [
        "poner el centro de costo «Obra Norte»"
      ]
    }
  ],
  "has_more": false,
  "url": "/v1/rules/{id}/test"
}
```

## Errors

- `feature_not_in_plan` (403): Live, this part of the API (inventario, portal de proveedores, pedidos, comprobación de gastos) follows the empresa's plan, as in the app: it comes with Operaciones (added to any paid plan; included in Corporativo). The books (the /v1/accounting routes except DIOT, cross checks, IVA refunds and fixed assets) come with Contabilidad (added to Independiente, Emprendedor or Negocio; included in Despacho and Corporativo): without it, changing the books answers this error, and reading them works only up to the last month it had it. Add either in Ajustes › Plan y pagos; test mode has everything.
- `issuer_archived` (400): The issuer is archived and no longer stamps. Its documents can still be read and canceled.
- `issuer_linked_empresa` (403): That issuer is an empresa of the app connected to your account: through the API it only offers its Portal de proveedores (/v1/portal_suppliers and /v1/supplier_invoices) and, once someone who may pay suppliers and change Configurar pagos turned them on, its supplier payouts (/v1/payouts and /v1/payroll_payouts). It also stops when whoever connected it (or turned its payouts on) no longer has that permission in the empresa: message_es says which. Do everything else in the app.
- `issuer_missing` (404): There is no such issuer in the account (or it belongs to the other mode).
- `issuer_not_allowed` (403): This key can't use that issuer.
- `issuer_required` (400): The account has several issuers and the request doesn't say which: send `issuer` (iss_…).
- `livemode_mismatch` (400): The object belongs to the other mode: an fk_test_ key only sees test data and an fk_live_ key only live data.
- `resource_missing` (404): There's no object with that id (or it belongs to another issuer or the other mode).

Plus those of any call (key, fields, limits): https://fiscalisto.com/en/docs/api/errores.md.
