# Create or Update Record — Airtable

> Create a new record, or update an existing one if a Record ID is provided (an upsert). Leave Record ID blank to create a record from record; supply it to update that record's fields instead. Use List Tables to look up field names first…

- Key: `airtable_oauth-create-or-update-record`
- Type: Action (Write)
- Version: 1.0.0
- App: Airtable (`airtable_oauth`) — https://pipedream.com/apps/airtable-oauth.md
- This page (HTML): https://pipedream.com/apps/airtable-oauth/actions/create-or-update-record
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/airtable_oauth/actions/create-or-update-record/create-or-update-record.mjs

## Description

Create a new record, or update an existing one if a Record ID is provided (an upsert). Leave `Record ID` blank to create a record from `record`; supply it to update that record's fields instead. Use **List Tables** to look up field names first, and **List Records** to find an existing record's ID. [See the create-record documentation](https://airtable.com/developers/web/api/create-records) and the [update-record documentation](https://airtable.com/developers/web/api/update-record)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `baseId` | `string` | Yes | The ID of the base to use, e.g. appXXXXXXXXXXXXXX. Use List Bases to look one up. |
| `tableId` | `string` | Yes | The ID of the table to use, e.g. tblXXXXXXXXXXXXXX. Use List Tables to look one up. |
| `recordId` | `string` | No | To update an existing record, select it from the list or provide its Record ID. If left blank, a new record will be created. |
| `record` | `object` | No | An object keyed by Airtable field name, where each value is the data to write to that field, e.g. { "Name": "Acme", "Stage": "Won" }. Include at least one writable field, and any number of the table's other fields. Use List Tables to look up a table's field names and types. Computed fields (formula, rollup, count, autonumber, created time, created by, last modified time and last modified by) cannot be written to. Enable Typecast when supplying human-readable values such as select option names or date strings. You may also use a custom expression. |
| `typecast` | `boolean` | No | The Airtable API will perform best-effort automatic data conversion from string values if the typecast parameter is True. This is disabled by default to ensure data integrity, but it may be helpful for integrating with 3rd party data sources. |
| `returnFieldsByFieldId` | `boolean` | No | If set to true, the returned field objects will have the field ID as the key, instead of the field name. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "airtable_oauth",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "airtable_oauth-create-or-update-record",
  arguments: {
    baseId: "Base",
    tableId: "Table",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "airtable_oauth-create-or-update-record",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    airtable_oauth: { authProvisionId: "apn_xxxxxxx" },
    baseId: "Base",
    tableId: "Table",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "airtable_oauth-create-or-update-record",
    "configured_props": {
      "airtable_oauth": { "authProvisionId": "apn_xxxxxxx" },
      "baseId": "Base",
      "tableId": "Table"
    }
  }'
```

---

- App: https://pipedream.com/apps/airtable-oauth.md · All apps: https://pipedream.com/apps
