# Team

> Who gets into your empresa in the app, with which role and permissions: invite, change access and remove people, and manage your roles from your own system.

With the API you manage who gets into the empresa in the app: list its members, invite someone with a role, change their access or remove them, and create the empresa's roles. It's the same as **Ajustes › Miembros** and **Ajustes › Roles**, with the same rules. Use it, for example, to add to Fiscalisto each person who joins your company from your HR system.

## Who makes the change

The key acts as **the person who created it**, with their access in the empresa: if that person can't invite, neither can the key, and nobody gives more than they have. If that person is no longer a member, it answers `403` with `team_permission_denied`: create another key in **Desarrolladores › Llaves** with your user.

Giving, taking or touching a **sensitive permission** (team, credentials, security or plan), naming an owner or removing someone who has one requires confirming the identity of whoever does it, and that can only be done in the app: the API answers `403` with `team_change_requires_app`. That way a leaked key can't give anyone control of the empresa. [`GET /v1/permissions`](https://fiscalisto.com/en/docs/api/referencia/equipo/list-permissions) says which ones are sensitive (`sensitive`).

The team belongs to an empresa: it works with an `fk_live_` key on your own issuers (`type: "own"`). A connected issuer or a test one has no members and answers `400` with `issuer_has_no_team`; in test mode, [`GET /v1/roles`](https://fiscalisto.com/en/docs/api/referencia/equipo/list-roles) and `GET /v1/permissions` do answer, so you can build your integration.

## See the members

```bash tab="cURL"
curl "https://api.fiscalisto.com/v1/members?issuer=iss_OufpKqnrvx9p" \
  -H "Authorization: Bearer $FISCALISTO_API_KEY"
```

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

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

const { data } = await fiscalisto.members.list({ issuer: "iss_OufpKqnrvx9p" });
```

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

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

data = fiscalisto.members.list({"issuer": "iss_OufpKqnrvx9p"})["data"]
```

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

use Fiscalisto\Fiscalisto;

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

$data = $fiscalisto->members->list(['issuer' => 'iss_OufpKqnrvx9p'])['data'];
```

```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()

	memberList, err := client.Members.List(ctx, &fiscalisto.ListMembersParams{
		Issuer: fiscalisto.String("iss_OufpKqnrvx9p"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *memberList)
}
```

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

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

var memberList = fiscalisto.members().list(new ListMembersParams().setIssuer("iss_OufpKqnrvx9p"));
System.out.println(memberList);
```

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

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

var memberList = await fiscalisto.Members.ListAsync(new ListMembersParams { Issuer = "iss_OufpKqnrvx9p" });
```

Each member comes with their role (`role`), the permissions added (`permissions_added`) or removed (`permissions_removed`), the ones they end up with (`permissions`), the RFCs (`tax_ids`) and branches (`branches`) in their reach, and whether they sign in with two-step verification (`two_factor_enabled`). `null` in `tax_ids` or `branches` means «all, including the ones added later».

## Invite someone

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invitations \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "issuer": "iss_OufpKqnrvx9p", "email": "contador@despachoruiz.mx", "role": "contador" }'
```

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

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

const invitation = await fiscalisto.invitations.create({
  issuer: "iss_OufpKqnrvx9p",
  email: "contador@despachoruiz.mx",
  role: "contador",
});
```

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

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

invitation = fiscalisto.invitations.create({
    "issuer": "iss_OufpKqnrvx9p",
    "email": "contador@despachoruiz.mx",
    "role": "contador",
})
```

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

use Fiscalisto\Fiscalisto;

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

$invitation = $fiscalisto->invitations->create([
    'issuer' => 'iss_OufpKqnrvx9p',
    'email' => 'contador@despachoruiz.mx',
    'role' => 'contador',
]);
```

```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()

	invitation, err := client.Invitations.Create(ctx, &fiscalisto.CreateInvitationParams{
		Issuer: fiscalisto.String("iss_OufpKqnrvx9p"),
		Email:  "contador@despachoruiz.mx",
		Role:   "contador",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(invitation.ID)
}
```

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

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

var invitation = fiscalisto.invitations().create(new CreateInvitationParams()
        .setIssuer("iss_OufpKqnrvx9p")
        .setEmail("contador@despachoruiz.mx")
        .setRole("contador"));
System.out.println(invitation.getId());
```

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

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

var invitation = await fiscalisto.Invitations.CreateAsync(new CreateInvitationParams
{
    Issuer = "iss_OufpKqnrvx9p",
    Email = "contador@despachoruiz.mx",
    Role = "contador",
});
```

The person gets an email with a link to join the empresa, valid for 7 days. If they have no account, they create one when they open it. Inviting the same email again replaces the invitation (new link, new access). With `tax_ids` and `branches` you limit them to some RFCs and branches (`brn_…`, or `"matriz"` for the domicilio fiscal).

Each pending invitation counts as one of the plan's users: if no more fit, it answers `403` with `team_seat_limit`. [`GET /v1/invitations`](https://fiscalisto.com/en/docs/api/referencia/equipo/list-invitations) lists the pending ones and [`DELETE /v1/invitations/{id}`](https://fiscalisto.com/en/docs/api/referencia/equipo/cancel-invitation) cancels one: its link stops working.

## Change a member's access

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/members/mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4 \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "role": "contador", "tax_ids": ["ICV060329BY0"] }'
```

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

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

const member = await fiscalisto.members.update("mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4", { role: "contador", tax_ids: ["ICV060329BY0"] });
```

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

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

member = fiscalisto.members.update("mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4", {
    "role": "contador",
    "tax_ids": ["ICV060329BY0"],
})
```

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

use Fiscalisto\Fiscalisto;

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

$member = $fiscalisto->members->update('mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4', [
    'role' => 'contador',
    'tax_ids' => ['ICV060329BY0'],
]);
```

```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()

	member, err := client.Members.Update(ctx, "mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4", &fiscalisto.UpdateMemberParams{
		Role:   fiscalisto.String("contador"),
		TaxIDs: []string{"ICV060329BY0"},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(member.ID)
}
```

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

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

var member = fiscalisto.members().update("mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4", new UpdateMemberParams()
        .setRole("contador")
        .setTaxIds(List.of("ICV060329BY0")));
System.out.println(member.getId());
```

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

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

var member = await fiscalisto.Members.UpdateAsync("mem_OufpKqnrvx9p3fT0aW9CxR2YhJ8kLmNqP4", new UpdateMemberParams
{
    Role = "contador",
    TaxIds = new() { "ICV060329BY0" },
});
```

What you don't send stays as it is. There is always at least one owner: leaving the empresa without one answers `400` with `team_invalid`. [`DELETE /v1/members/{id}`](https://fiscalisto.com/en/docs/api/referencia/equipo/delete-member) removes the person from the empresa and cancels the invitations they sent. What they did keeps their name; what was waiting on them (approval steps that name them, pending approvals, notices, absences and the viáticos they approve) goes to the member in `?transfer_to=mem_…` or, without it, to anyone with the permission.

## Roles

`GET /v1/roles` returns the empresa's roles with their permissions and how many people have them: Propietario (`owner`), Fiscalisto's (`type: "starter"`: administrador, contador, facturista and more; they can be changed, not deleted) and yours (`custom`).

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/roles \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "issuer": "iss_OufpKqnrvx9p", "name": "Cobranza", "description": "Ve facturas y registra cobros.", "permissions": ["emitidas:ver", "facturar:pagos"] }'
```

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

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

const role = await fiscalisto.roles.create({
  issuer: "iss_OufpKqnrvx9p",
  name: "Cobranza",
  description: "Ve facturas y registra cobros.",
  permissions: ["emitidas:ver", "facturar:pagos"],
});
```

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

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

role = fiscalisto.roles.create({
    "issuer": "iss_OufpKqnrvx9p",
    "name": "Cobranza",
    "description": "Ve facturas y registra cobros.",
    "permissions": ["emitidas:ver", "facturar:pagos"],
})
```

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

use Fiscalisto\Fiscalisto;

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

$role = $fiscalisto->roles->create([
    'issuer' => 'iss_OufpKqnrvx9p',
    'name' => 'Cobranza',
    'description' => 'Ve facturas y registra cobros.',
    'permissions' => ['emitidas:ver', 'facturar:pagos'],
]);
```

```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()

	role, err := client.Roles.Create(ctx, &fiscalisto.CreateRoleParams{
		Issuer:      fiscalisto.String("iss_OufpKqnrvx9p"),
		Name:        "Cobranza",
		Description: fiscalisto.String("Ve facturas y registra cobros."),
		Permissions: []string{"emitidas:ver", "facturar:pagos"},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(role.ID)
}
```

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

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

var role = fiscalisto.roles().create(new CreateRoleParams()
        .setIssuer("iss_OufpKqnrvx9p")
        .setName("Cobranza")
        .setDescription("Ve facturas y registra cobros.")
        .setPermissions(List.of("emitidas:ver", "facturar:pagos")));
System.out.println(role.getId());
```

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

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

var role = await fiscalisto.Roles.CreateAsync(new CreateRoleParams
{
    Issuer = "iss_OufpKqnrvx9p",
    Name = "Cobranza",
    Description = "Ve facturas y registra cobros.",
    Permissions = new() { "emitidas:ver", "facturar:pagos" },
});
```

Permissions that another one needs are added on their own (recording payments needs seeing the invoices). [`POST /v1/roles/{id}`](https://fiscalisto.com/en/docs/api/referencia/equipo/update-role) changes its name or permissions, and with them the access of everyone who has it; [`DELETE /v1/roles/{id}`](https://fiscalisto.com/en/docs/api/referencia/equipo/delete-role) deletes one of yours once nobody has it.

## Learn more

- Each permission, with its name in the app and its group: [`GET /v1/permissions`](https://fiscalisto.com/en/docs/api/referencia/equipo/list-permissions).
- Each object's fields, in the [Equipo reference](https://fiscalisto.com/en/docs/api/referencia/equipo/list-members).
