# Get Indexes Example

> Example showing how to list the indexes of a table on any database from custom code with g.sys.system.getIndexes.

Source: https://docs.apimaker.dev/v1/examples/sys/system/getIndexes.html

`g.sys.system.getIndexes` calls the [get indexes system API](https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-get-indexes-api.html) from your code, whatever the settings of that API say about HTTP callers.

### Get indexes System API

List the indexes of a table using global object 'g', in the same format for every database.

```ts
const indexes = await g.sys.system.getIndexes({
    instance: 'mysql8',
    database: 'inventory',
    table: 'orders',
});
// [
//     { name: 'PRIMARY', key: { id: 1 }, unique: true },
//     { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
```

- `key` holds the fields in order with their direction : `1` ascending, `-1` descending, `hashed` or `text` on MongoDB.
- Several tables at once : give a list of such objects, the answer is a list of lists in the same order.
- `instance: "crm::acme"` reads the table in the database of the tenant `acme` of the multi-tenant instance `crm`.

## Related

- [Get indexes system API](https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-get-indexes-api.html) · [All system APIs from code](https://docs.apimaker.dev/v1/examples/sys/system/system.html) · [The global object g](https://docs.apimaker.dev/v1/docs/pre-defined-terms/global-object-g.html)
