# importDeal

Create-or-get a deal migrated from an external system. Keyed on (sourceSystem, externalId): replaying the same record returns the existing deal with wasCreated=false instead of duplicating. Honors historical createdAt/updatedAt (must be in the past) and suppresses live side effects: no workflow triggers (neither DEAL stage-entered nor per-contact deal-created events fire), no notifications. The deal field takes the same shape as createDeal: stageId from listPipelineStages, linked contacts/users by id, propertyStrings for unresolved addresses, customFieldValues from listDealCustomFields. The create is atomic: the deal row and every link (contacts, properties, users, splits) commit together or not at all, so a failed call leaves nothing behind and a retry re-creates cleanly. A replay (wasCreated=false) never rewrites the existing deal (links and edits made since the import are left alone) with one deliberate exception: custom-field values are filled where still MISSING (crash-retry recovery for the one write applied after the create) and never overwritten.

- Call: `POST https://server.goliathdata.com/api/v1/call` with `{ "operationId": "importDeal", "variables": {...} }`
- Scope: `IMPORT`
- Type: mutation
- Idempotency: honors `Idempotency-Key` (24 h)
- Rate-limited: no

## Variables

- `input`: `ImportPipelineItemInput!` (required)
  - `pipelineItem`: `CreatePipelineItemInput`. The deal's fields, in the same shape the ordinary createDeal mutation accepts (stageId from listPipelineStages; contacts/properties/users linked by id; customFieldValues from listDealCustomFields).
    - `title`: `String!` (required)
    - `stageId`: `ID!` (required)
    - `description`: `String`
    - `priceCents`: `BigInt`
    - `commissionAmountCents`: `BigInt`
    - `commissionPercentBps`: `Int`
    - `teamSplitAmountCents`: `BigInt`
    - `teamSplitPercentBps`: `Int`
    - `participantSplits`: `[PipelineItemParticipantSplitInput!]`
      - `userId`: `ID!` (required)
      - `splitAmountCents`: `BigInt`
      - `splitPercentBps`: `Int`
    - `closeDate`: `DateTime`
    - `propertyIds`: `[ID!]`
    - `propertyStrings`: `[String!]`
    - `contactIds`: `[ID!]`
    - `userIds`: `[ID!]`
    - `fileIds`: `[ID!]`
    - `customFieldValues`: `[PipelineItemCustomFieldValueInput!]`
      - `customFieldId`: `ID!` (required)
      - `textValue`: `String`
      - `dateValue`: `DateTime`
      - `numberValue`: `Float`
      - `dropdownSelectedValues`: `[String!]`
  - `deal`: `CreatePipelineItemInput`
    - `title`: `String!` (required)
    - `stageId`: `ID!` (required)
    - `description`: `String`
    - `priceCents`: `BigInt`
    - `commissionAmountCents`: `BigInt`
    - `commissionPercentBps`: `Int`
    - `teamSplitAmountCents`: `BigInt`
    - `teamSplitPercentBps`: `Int`
    - `participantSplits`: `[PipelineItemParticipantSplitInput!]`
      - `userId`: `ID!` (required)
      - `splitAmountCents`: `BigInt`
      - `splitPercentBps`: `Int`
    - `closeDate`: `DateTime`
    - `propertyIds`: `[ID!]`
    - `propertyStrings`: `[String!]`
    - `contactIds`: `[ID!]`
    - `userIds`: `[ID!]`
    - `fileIds`: `[ID!]`
    - `customFieldValues`: `[PipelineItemCustomFieldValueInput!]`
      - `customFieldId`: `ID!` (required)
      - `textValue`: `String`
      - `dateValue`: `DateTime`
      - `numberValue`: `Float`
      - `dropdownSelectedValues`: `[String!]`
  - `sourceSystem`: `String!` (required). Short slug identifying the system this record came from (e.g. "resimpli", "podio"). Lowercase letters, digits, and hyphens only, at most 32 characters. Part of the idempotency key.
  - `externalId`: `String!` (required). The record's id in the source system. At most 256 characters. Part of the idempotency key: importing the same (sourceSystem, externalId) twice returns the existing deal.
  - `createdAt`: `DateTime`. When the record was created in the source system. Must be in the past (any time since 1970). Omitted = now.
  - `updatedAt`: `DateTime`. When the record was last updated in the source system. Must be in the past and not before createdAt; requires createdAt to be provided as well (an omitted createdAt means "now", which would put the update before creation). Also stamps the deal's stage-entry timestamp (lastStageChangeAt): source systems don't export per-stage move history, so the deal is recorded as sitting in its stage since updatedAt: falling back to createdAt, then to the import time when neither is provided.

## Response (data, an example)

```json
{
  "crmImportMutation": {
    "importDeal": {
      "dealId": "<ID>",
      "wasCreated": true
    }
  }
}
```

## Example

```bash
curl https://server.goliathdata.com/api/v1/call \
  -H "Authorization: Bearer $GOLIATH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "operationId": "importDeal",
    "variables": {
      "input": {
        "sourceSystem": "<String>",
        "externalId": "<String>"
      }
    }
  }'
```
