## Base

A `Base` provides an entry point to all of the data in a given base. There is only ever one base
available—the base in which this script is installed. It can be accessed via the `base`
global variable. You can use it to get data from your base, like [tables](/developers/scripting/api/table.md),
[views](/developers/scripting/api/view.md), [fields](/developers/scripting/api/field.md), and [records](/developers/scripting/api/record.md).

```js
console.log(`The name of my base is ${base.name}.`);
console.log(`It contains ${base.tables.length} tables.`);
```

### id

```js
string
```

The unique ID of your base.

### name

```js
string
```

The name of your base.

### activeCollaborators

> See also: [Collaborator](/developers/scripting/api/collaborator.md)
```js
Array<Collaborator>
```

The users who have access to this base.

```js
// show a table of all the base collaborators:
console.log('# All collaborators:');
console.log(base.activeCollaborators);
```

### tables

> See also: [Table](/developers/scripting/api/table.md)
```js
Array<Table>
```

The tables in this base.

```js
// log every table's name and id from the base
for (let table of base.tables) {
    console.log(`Table '${table.name}' has id '${table.id}'.`);
}
```

### getCollaborator

> See also: [Collaborator](/developers/scripting/api/collaborator.md)
```js
function (idOrNameOrEmail: string) => Collaborator;
```

| Parameter name | Description |
|---|---|
| `idOrNameOrEmail` | The id, name, or email address of the user [collaborator](/developers/scripting/api/collaborator.md) you want to retrieve. |

Get a user collaborator, that is shared either directly or indirectly via a user group, from the base according to their ID, name, or email.

```js
// Get collaborator by id:
let collaborator1 = base.getCollaborator("usrDOCS0000000002");
console.log(collaborator1);

// Get collaborator by name:
let collaborator2 = base.getCollaborator("Casey Park");
console.log(collaborator2);

// Get collaborator by email:
let collaborator3 = base.getCollaborator("sandy.hagen@airtable.com");
console.log(collaborator3);
```

### getTable
> See also: [Table](/developers/scripting/api/table.md)
```js
function (idOrName: string) => Table;
```

| Parameter name | Description |
|---|---|
| `idOrName` | The id or name of the [table](/developers/scripting/api/table.md) you want to retrieve. |

Get a table from the base according to its ID or name.

```js
// Get table by id:
let table1 = base.getTable("tblDOCS0000000014");
console.log(table1);

// Get table by name:
let table2 = base.getTable("Projects");
console.log(table2);
```

### createTableAsync (extensions only)

```js
(name: string, fields: Array<{name: string, type: FieldType, options?: {[key: string]: unknown} | null, description?: string | null}>) => Promise<string>
```

| Parameter name | Description |
|---|---|
| `name` | Name for the table. Must be case-insensitive unique |
| `fields` | Array of fields to create in the table. See below for details. |

Creates a new table.

Throws an error if the user does not have permission to create a table, if an invalid table name
is provided, or if invalid fields are provided (invalid name, type, options or description).

At least one field must be specified. The first field in the fields array will be used as the
table's [primary field](https://support.airtable.com/docs/the-primary-field)
and must be a supported primary field type. Fields must have case-insensitive unique names within
the table.

The following field types can be created:
- checkbox
- singleSelect
- multipleSelects
- singleCollaborator
- multipleCollaborators
- number
- percent
- currency
- duration
- singleLineText
- email
- url
- multilineText
- phoneNumber
- richText
- barcode
- multipleAttachments
- date
- dateTime
- rating
- multipleRecordLinks

The following field types cannot be created:
- formula
- createdTime
- rollup
- count
- multipleLookupValues
- autoNumber
- lastModifiedTime
- button
- createdBy
- lastModifiedBy
- externalSyncSource
- aiText

Refer to [Cell values & field options](/developers/scripting/api/cell_values.md) for the write
format for field options and other specifics for certain field types.

`name` and `type` must be specified for all fields, while `options` is only required for
fields that have field options. `description` is optional and will be `''` if not specified or
if specified as `null`.

A default grid view will be created with all fields visible.

This action is asynchronous: you must add `await` before each call to this method to ensure it
takes effect.


```js
const tableId = await base.createTableAsync("Tasks", [{name: "Title", type: "singleLineText"}]);
```
