# Tags

> Group issued and received invoices with your own words (a job site, an event, a customer) and filter by them.

A tag is the issuer's own word to group what goes together: a job site, an event, a customer, «Urgente». An invoice carries up to 10, and they're the same list as **Etiquetas** in the app, which purchase orders use too: «Obra Norte» is the same everywhere. They're Fiscalisto's own: they don't change the CFDI, its taxes, the books or what SAT sees. To split income and expenses in **Reportes**, an invoice goes in a single [cost center](https://fiscalisto.com/en/docs/api/centros-de-costo); tags are several and are for finding and grouping.

## Create a tag

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/tags \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Obra Norte", "color": "info" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const tag = await fiscalisto.tags.create({ name: "Obra Norte", color: "info" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

tag = fiscalisto.tags.create({"name": "Obra Norte", "color": "info"})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$tag = $fiscalisto->tags->create(['name' => 'Obra Norte', 'color' => 'info']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	tag, err := client.Tags.Create(ctx, &fiscalisto.CreateTagParams{
		Name:  "Obra Norte",
		Color: fiscalisto.String("info"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(tag.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateTagParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var tag = fiscalisto.tags().create(new CreateTagParams().setName("Obra Norte").setColor("info"));
System.out.println(tag.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var tag = await fiscalisto.Tags.CreateAsync(new CreateTagParams { Name = "Obra Norte", Color = "info" });
```

It answers the tag (`tag_…`) with `purchase_orders` and `invoices`, how many purchase orders and invoices carry it. The name doesn't repeat, regardless of case or accents: another one like it answers `tag_exists` and the message has its id. `color` is `info` (blue), `positive` (green), `warning` (amber), `critical` (red) or `muted` (gray); without it, it takes the next one in the list. Up to 200 per empresa.

You don't need to create them first: a new name on an invoice creates it.

## Tag an invoice

Send `tags` to an invoice that came from SAT, issued or received. It keeps exactly the ones you send, by id (`tag_…`) or by name:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/sat_invoices/sat_OufpKqnrvx9p1F \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "tags": ["Obra Norte", "Urgente"] }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const satInvoice = await fiscalisto.satInvoices.update("sat_OufpKqnrvx9p1F", { tags: ["Obra Norte", "Urgente"] });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

sat_invoice = fiscalisto.sat_invoices.update("sat_OufpKqnrvx9p1F", {"tags": ["Obra Norte", "Urgente"]})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$satInvoice = $fiscalisto->satInvoices->update('sat_OufpKqnrvx9p1F', ['tags' => ['Obra Norte', 'Urgente']]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	satInvoice, err := client.SatInvoices.Update(ctx, "sat_OufpKqnrvx9p1F", &fiscalisto.UpdateSatInvoiceParams{
		Tags: []string{"Obra Norte", "Urgente"},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(satInvoice.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.UpdateSatInvoiceParams;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var satInvoice = fiscalisto.satInvoices().update("sat_OufpKqnrvx9p1F", new UpdateSatInvoiceParams().setTags(List.of("Obra Norte", "Urgente")));
System.out.println(satInvoice.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var satInvoice = await fiscalisto.SatInvoices.UpdateAsync("sat_OufpKqnrvx9p1F", new UpdateSatInvoiceParams
{
    Tags = new() { "Obra Norte", "Urgente" },
});
```

It answers the invoice with its `tags`, each with its `id`, `name`, `color` and `automatic`. `[]` takes them all off. More than 10 answers `parameter_invalid`.

Some go on by themselves, and come with `automatic: true`:

- An invoice linked to a purchase order takes the order's tags, whether it arrives before or after the link.
- A [rule](https://fiscalisto.com/en/docs/api/reglas) can put them when an invoice arrives or is issued.

If you take one of those off (you leave it out of `tags`), it doesn't go back on by itself. If you send it again, it stays.

## See the invoices with a tag

```bash tab="cURL"
curl -G https://api.fiscalisto.com/v1/sat_invoices \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -d tag=tag_OufpKqnrvx9p1 \
  -d direction=received
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

for await (const item of fiscalisto.satInvoices.list({
  tag: "tag_OufpKqnrvx9p1",
  direction: "received",
})) {
  console.log(item.id);
}
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

for item in fiscalisto.sat_invoices.list({
    "tag": "tag_OufpKqnrvx9p1",
    "direction": "received",
}):
    print(item["id"])
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

foreach ($fiscalisto->satInvoices->list([
    'tag' => 'tag_OufpKqnrvx9p1',
    'direction' => 'received',
]) as $item) {
    echo $item['id'], "\n";
}
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	for item, err := range client.SatInvoices.ListAutoPaging(ctx, &fiscalisto.ListSatInvoicesParams{
		Tag:       fiscalisto.String("tag_OufpKqnrvx9p1"),
		Direction: fiscalisto.String("received"),
	}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(item.ID)
	}
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.ListSatInvoicesParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

for (var item : fiscalisto.satInvoices().listAutoPaging(new ListSatInvoicesParams()
        .setTag("tag_OufpKqnrvx9p1")
        .setDirection("received"))) {
    System.out.println(item.getId());
}
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

await foreach (var item in fiscalisto.SatInvoices.ListAutoPagingAsync(new ListSatInvoicesParams
{
    Tag = "tag_OufpKqnrvx9p1",
    Direction = "received",
}))
    Console.WriteLine(item.Id);
```

`tag` combines with the list's other filters (`direction`, `date_gte`, `cost_center`…).

## Change or delete a tag

`POST /v1/tags/{id}` changes its name or color, and it shows that way on all its invoices and orders:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/tags/tag_OufpKqnrvx9p1 \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "color": "positive" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const tag = await fiscalisto.tags.update("tag_OufpKqnrvx9p1", { color: "positive" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

tag = fiscalisto.tags.update("tag_OufpKqnrvx9p1", {"color": "positive"})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$tag = $fiscalisto->tags->update('tag_OufpKqnrvx9p1', ['color' => 'positive']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	tag, err := client.Tags.Update(ctx, "tag_OufpKqnrvx9p1", &fiscalisto.UpdateTagParams{
		Color: fiscalisto.String("positive"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(tag.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.UpdateTagParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var tag = fiscalisto.tags().update("tag_OufpKqnrvx9p1", new UpdateTagParams().setColor("positive"));
System.out.println(tag.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var tag = await fiscalisto.Tags.UpdateAsync("tag_OufpKqnrvx9p1", new UpdateTagParams { Color = "positive" });
```

`GET /v1/tags` lists them, newest first. `DELETE /v1/tags/{id}` deletes it: it comes off its invoices and orders, which don't change in anything else, and its automatic tags are deleted. It can't be undone.

## Errors

| Code | When |
| --- | --- |
| `tag_exists` | There's already a tag with that name; the message has its id. |
| `tag_limit` | The empresa has reached 200 tags. |
| `parameter_invalid` | More than 10 on an invoice, or a `tag_…` that isn't the issuer's. |
| `resource_missing` | The tag or the invoice doesn't exist, or belongs to another account. |
