Files
upstream-twenty/packages/twenty-docs/user-guide/data-migration/how-tos/import-data-via-api.mdx
upstream-mirror e7da97194a
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
2026-09-17 23:28:13 +05:00

169 lines
5.7 KiB
Plaintext

---
title: Import Data via API
description: When and how to use Twenty's APIs for large-scale data imports.
---
## Overview
Twenty provides both **GraphQL** and **REST APIs** for programmatic data import. Use the API when CSV import isn't practical for your data volume or when you need automated, recurring imports.
## When to Use API Import
| Scenario | Recommended Method |
|----------|-------------------|
| Under 10,000 records | CSV Import |
| 10,000 - 50,000 records | CSV Import (split into files) |
| **50,000+ records** | **API Import** |
| One-time migration | Either (based on volume) |
| **Recurring imports** | **API Import** |
| **Real-time sync** | **API Import** |
| **Integration with other systems** | **API Import** |
<Note>For datasets in the hundreds of thousands, the API is significantly faster and more reliable than multiple CSV imports.</Note>
## API Rate Limits
Twenty enforces rate limits to ensure system stability:
| Limit | Value |
|-------|-------|
| **Requests per minute** | 100 |
| **Records per batch call** | 60 |
| **Maximum throughput** | ~6,000 records/minute |
<Warning>
**Plan your import around these limits.**
For 100,000 records at maximum throughput, expect approximately 17 minutes of import time. Add buffer time for error handling and retries.
</Warning>
## Getting Started
### Step 1: Get Your API Key
1. Go to **Settings → Developers**
2. Click **+ Create API key**
3. Give your key a descriptive name
4. Copy the API key immediately (it won't be shown again)
5. Store it securely
<Warning>
**Keep your API key secret.**
Anyone with your API key can access and modify your workspace data. Never commit it to code repositories or share it publicly.
</Warning>
### Step 2: Choose Your API
Twenty supports two API types:
| API | Best For | Documentation |
|-----|----------|---------------|
| **GraphQL** | Flexible queries, fetching related data, complex operations | [API Docs](/developers/extend/api) |
| **REST** | Simple CRUD operations, familiar REST patterns | [API Docs](/developers/extend/api) |
Both APIs support:
- Creating, reading, updating, and deleting records
- **Batch operations** — create or update up to 60 records per call
**For imports, use batch operations** to maximize throughput within rate limits.
### Step 3: Plan Your Import Order
Just like CSV imports, **order matters** for relations:
1. **Companies** first (no dependencies)
2. **People** second (can link to Companies)
3. **Opportunities** third (can link to Companies and People)
4. **Tasks/Notes** (can link to any of the above)
5. **Custom objects** (following their dependencies)
## Best Practices
### Batch Your Requests
- Don't send records one at a time
- Group up to **60 records per API call**
- This maximizes throughput within rate limits
### Handle Rate Limits
- Implement delays between requests (600ms minimum for sustained imports)
- Use exponential backoff when you hit limits
- Monitor for 429 (Too Many Requests) responses
### Validate Data First
- Clean and validate your data before importing
- Check required fields are populated
- Verify formats match Twenty's requirements (see [Field Mapping](/user-guide/data-migration/capabilities/field-mapping))
### Log Everything
- Log every record imported (including IDs)
- Log errors with full context
- This helps debug issues and verify completion
### Test First
- Test with a small batch (10-20 records)
- Verify data appears correctly in Twenty
- Then run the full import
### Upsert to Avoid Duplicates
The GraphQL API supports **batch upsert** — update if the record exists, create if not. This prevents duplicates when re-running imports.
## Finding Object and Field Names
To see available objects and fields:
1. Go to **Settings → API and Webhooks**
2. Browse the **Metadata API**
3. View all standard and custom objects with their fields
The documentation shows all standard and custom objects, their fields, and the expected data types.
## Professional Services
For complex API migrations, our partners can help:
| Service | What's Included |
|---------|-----------------|
| **Data Model Design** | design your optimal data structure |
| **Migration Scripts** | write and run the import scripts |
| **Data Transformation** | handle complex mapping and cleanup |
| **Validation & QA** | verify the migration is complete |
**Best for:**
- Migrations of 100,000+ records
- Complex data transformations
- Tight timelines
- Teams without developer resources
Contact us at [contact@twenty.com](mailto:contact@twenty.com) or explore our [Implementation Services](/user-guide/getting-started/capabilities/implementation-services).
## FAQ
<AccordionGroup>
<Accordion title="What's the difference between GraphQL and REST?">
GraphQL lets you request exactly the data you need in a single query and is better for complex operations. REST uses standard HTTP methods (GET, POST, PUT, DELETE) and may be more familiar if you've worked with traditional APIs.
</Accordion>
<Accordion title="Can I update existing records via API?">
Yes! Use update mutations (GraphQL) or PUT/PATCH requests (REST) with the record's `id`.
</Accordion>
<Accordion title="How do I handle duplicates?">
Query for existing records first using unique identifiers (email, domain). Update if exists, create if not.
</Accordion>
<Accordion title="Can I delete records via API?">
Yes, use delete mutations (GraphQL) or DELETE requests (REST).
</Accordion>
<Accordion title="Is there a Python or Node.js SDK?">
Not currently, but both APIs work with any HTTP client in any language.
</Accordion>
</AccordionGroup>
## API Documentation
For full implementation details, code examples, and schema reference:
- [API Documentation](/developers/extend/api)