> ## Documentation Index
> Fetch the complete documentation index at: https://detrack.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Import contacts

> Add contacts in bulk from a CSV or Excel file: upload it to a signed URL, start the import with POST /dn/contacts/import, then poll its status.

Add many contacts at once from a CSV or Excel file, up to 10 MB and 2,000 rows. An import takes three requests: get an upload URL, upload the file to it, and start the import. The import then runs in the background, so you poll its status until it finishes.

## Importing a file

**1. Get an upload URL**

Send your file's name, so Detrack knows how to read it. The response has the upload `url` and the file's `id`.

```bash theme={null}
curl "https://app.detrack.com/api/v2/dn/contacts/import/presign?filename=contacts.csv" \
  -H "X-API-KEY: $DETRACK_API_KEY"
```

**2. Upload the file**

`PUT` the file to `url` exactly as returned, within 15 minutes. Don't send your API key: the URL is already signed. If the response had any `headers`, send those too.

```bash theme={null}
curl -X PUT "$UPLOAD_URL" --upload-file contacts.csv
```

**3. Start the import**

Send the `id` from the first step. The response is the import's own `id`, with `status` set to `processing`.

```bash theme={null}
curl -X POST "https://app.detrack.com/api/v2/dn/contacts/import" \
  -H "X-API-KEY: $DETRACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data": {"id": "5f0c3a1d29e804cae4fe0b22/3b9f2c7e5d4a4f1e9a6b8c0d1e2f3a4b.csv"}}'
```

**4. Poll until it finishes**

Call [Get import status](https://detrack.mintlify.site/api-reference/contacts/get-import-status.md) with the import's `id` until `status` is `completed` or `failed`.

## The file

Use a `.csv`, `.xlsx`, or `.xls` file. Detrack finds the header row by its **Address** column, then matches the other columns by their header names, ignoring case. Your account can rename columns, so [download a sample file](https://detrack.mintlify.site/api-reference/contacts/download-sample.md) to get the exact names. Rows with no values are skipped.

A file can have up to 2,000 rows under the header row. Rows with no values don't count. A bigger file fails with `too_many_rows` and nothing is imported, so split it into smaller files.

Each row needs a name or company name, and an address unless it has an address line (the **Address 1** to **Address 3** columns, by default). Rows that can't be saved are listed in the import's `invalid_contacts`. The file's other rows are still saved.

## Replacing your contacts

Send `"delete": true` to delete the contacts your API key's user can see before the file is imported. It's ignored if the user can't delete contacts.

> [!WARNING]
>
> Send `delete` as a JSON `true` or `false`, or leave it out. Any other value, even the string `"false"`, `0`, or `""`, counts as `true` and deletes the contacts.
>
> Detrack checks the file's size and row count first, so a file that fails with `file_too_large` or `too_many_rows` deletes nothing. Otherwise it deletes the contacts before it imports the file. If the import then fails, for example with `missing_required_headers`, the deleted contacts aren't restored. Try the file without `delete` first.

## Import errors

A failed import has one of these codes in `errors`:

| Code | Meaning |
| - | - |
| `file_too_large` | The file is over 10 MB. |
| `too_many_rows` | The file has more than 2,000 rows with values under the header row. |
| `invalid_file` | Detrack couldn't read the file. Check that it's a `.csv`, `.xlsx`, or `.xls` file, and that the `filename` you sent for the upload URL had the same extension. |
| `invalid_csv_file` | The CSV file is malformed, for example a quote that's never closed. |
| `missing_required_headers` | The file has no **Address** column, so Detrack couldn't find the header row. |
| `invalid_contact` | Some rows couldn't be saved. They're listed in `invalid_contacts`, and the other rows are still saved. |

Request errors, such as an `id` you didn't upload, return `422` straight away and nothing is imported or deleted.


## OpenAPI

````yaml POST /dn/contacts/import
openapi: 3.0.3
info:
  title: Detrack REST API v2
  version: '2.0'
  description: >-
    Detrack REST API v2. Checked against detrack-webapp origin/main (production)
    on 2026-09-29: dn_jobs.rb @ d246ad006, dn_depots.rb @ 2a5f387, dn_routes.rb
    @ 50a73a9, app_helper.rb @ d745ad2, dn_jobs_helper.rb @ d296e30,
    job_decorator.rb @ 3041da7, run_location_decorator.rb @ 0f0274d,
    vehicle_route_plan_decorator.rb and tsp_route_decorator.rb @ 7d1f3ef,
    data_export.rb @ ed4e135. Vehicle check submissions checked against
    origin/main on 2026-11-03: dn_vehicle_checklist_submissions.rb @ 3071523d1,
    vehicle_checklist_submission_decorator.rb @ f4002c957,
    vehicle_checklist_submission.rb @ b80aea03c,
    vehicle_checklist_submission_rules.rb @ e55194ed7. Contacts checked against
    origin/main on 2026-11-04: dn_contacts.rb, contacts_helper.rb and contact.rb
    @ a1b3694a0, contact_decorator.rb @ a51f1eab7.
servers:
  - url: https://app.detrack.com/api/v2
security:
  - apiKey: []
tags:
  - name: Jobs
    description: Deliveries and collections.
  - name: Depots
    description: Saved warehouse and pickup locations.
  - name: Contacts
    description: Your address book of saved recipients.
  - name: Routes
    description: Optimized multi-stop plans across vehicles.
  - name: Vehicle checks
    description: >-
      Checklists your drivers submit for a vehicle, such as start-of-day and
      end-of-day checks.
  - name: Contact imports
    description: Add contacts in bulk from a CSV or Excel file.
paths:
  /dn/contacts/import:
    post:
      tags:
        - Contact imports
      summary: Import contacts
      description: >-
        Starts importing a file you uploaded with [Get an upload
        URL](/api-reference/contacts/get-upload-url). A file can be up to 10 MB
        and 2,000 rows. The import runs in the background: poll [Get import
        status](/api-reference/contacts/get-import-status) with the returned
        `id`.
      operationId: importContacts
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - data
              properties:
                data:
                  type: object
                  required:
                    - id
                  properties:
                    id:
                      type: string
                      description: >-
                        The `id` from [Get an upload
                        URL](/api-reference/contacts/get-upload-url).
                    delete:
                      type: boolean
                      default: false
                      description: >-
                        Set to `true` to delete the contacts your API key's user
                        can see before importing. Send a JSON boolean: any other
                        value, even the string `"false"`, deletes them too.
                        Ignored if the user can't delete contacts.
                    metadata:
                      type: object
                      description: Optional details about the file.
                      properties:
                        filename:
                          type: string
                          example: contacts.csv
            example:
              data:
                id: 5f0c3a1d29e804cae4fe0b22/3b9f2c7e5d4a4f1e9a6b8c0d1e2f3a4b.csv
                metadata:
                  filename: contacts.csv
      responses:
        '201':
          description: The import has started. Poll its `id` until `status` changes.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                        example: 6ae1949608fe77f3f222fa08
                      status:
                        type: string
                        example: processing
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          description: >-
            `data` is missing or isn't an object, or `id` isn't a file you
            uploaded (`invalid_data`), or the file is over 10 MB
            (`file_too_large`). Nothing is imported or deleted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: invalid_data
                message: >-
                  Upload the file with /dn/contacts/import/presign and send its
                  id
        '503':
          description: Detrack couldn't check the uploaded file. Retry shortly.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: storage_unavailable
                message: Could not check the uploaded file. Try again.
        default:
          $ref: '#/components/responses/ServerError'
components:
  responses:
    BadRequest:
      description: The request body isn't valid JSON.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            code: invalid_json_format
    Unauthorized:
      description: >-
        The API key is missing or invalid. A missing `X-API-KEY` returns `{
        "error": "Missing Authorization header" }`; an invalid key returns `{
        "code": "invalid_key", "message": "Invalid key" }`.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                title: Missing key
                required:
                  - error
                properties:
                  error:
                    type: string
                    example: Missing Authorization header
              - type: object
                title: Invalid key
                required:
                  - code
                properties:
                  code:
                    type: string
                    example: invalid_key
                  message:
                    type: string
                    example: Invalid key
          example:
            code: invalid_key
            message: Invalid key
    Forbidden:
      description: Your API key's user doesn't have permission for this action.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: forbidden
          example:
            code: forbidden
    ServerError:
      description: >-
        Unexpected server error. Retry with exponential backoff, and contact
        Detrack support if it persists.
  schemas:
    Error:
      type: object
      properties:
        code:
          type: string
          example: not_found
        message:
          type: string
          example: Could not find job with this DO number
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-KEY
      description: Your Detrack API key, from **Integrations > API Key** in the dashboard.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.