# prepareContract

Step 2: freeze a contract READY to send, with its unsigned PDF. Build `input.contract` from getContractSendDraft's result (change what the person asked): `values` as { key, value } for every value to set, required blanks included; one recipient per role with exactly one of email or phone. Pass `idempotencyKey` (a new UUID) and resend it unchanged on a retry, so a lost response never makes a second contract. A template published again since step 1 is refused: start over. Needs the manage contracts capability. It reaches no signer: the person presses Send on `/contracts/<id>`, or a developer-API key calls sendContract.

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

## Variables

- `input`: `AdminContractPrepareInput!` (required)
  - `idempotencyKey`: `ID!` (required). A UUID the client generates once per prepare; a retry with the same key returns the same contract.
  - `contract`: `AdminContractSendInput!` (required). A contract as the sender has it on the prepare screen.
    - `templateId`: `ID!` (required)
    - `templateVersionId`: `ID!` (required). The published version the screen was opened on; a newer publish refuses the prepare.
    - `contactId`: `ID!` (required)
    - `pipelineItemId`: `ID`
    - `dealId`: `ID`
    - `title`: `String!` (required)
    - `values`: `[AdminContractSendValueInput!]!` (required). The sender's value per prefill; a prefill left out keeps what the CRM filled.
      - `key`: `ID!` (required). The prefill's key.
      - `value`: `String!` (required)
      - `type`: `AdminContractValueType` (one of `TEXT`, `DATE`, `MONEY`, `NUMBER`, `BOOLEAN`). The value's type on this send, when the sender changed it; left out keeps the template's.
    - `recipients`: `[AdminContractSendRecipientInput!]!` (required)
      - `roleKey`: `ID!` (required)
      - `displayName`: `String!` (required)
      - `email`: `String`. Their email when they are sent it by Email; give exactly one of an email or a phone.
      - `phone`: `String`. Their mobile number when they are sent it by Text, in any US form; give exactly one of an email or a phone.
      - `contactId`: `ID`. The contact this recipient is, when they are one.
      - `signingOrder`: `Int`. The signer's turn, 1-based; signers sharing a turn sign at once. Null on a copy; null on every recipient keeps the template's order.
    - `subject`: `String!` (required)
    - `message`: `String!` (required)
    - `expiryDays`: `Int!` (required). Days signers have once it is sent, 1-90.
    - `expiresOn`: `String`. The day the links stop working, YYYY-MM-DD, through its end in the contract's time zone; left out, expiryDays from the send.
    - `noteInText`: `Boolean`. The note opens the invitation texts too, as the send screen's note field says; left out, the note is for the email alone (workflows, the API).
    - `reminderIntervalDays`: `Int`. Days between automatic reminders, 1-30; left out, every day; null turns them off.
    - `afterSigning`: `ContractAfterSigningInput`. This send's After signing button. Left out: the template's; null: none on this send.
      - `label`: `String!` (required)
      - `url`: `String!` (required)
      - `caption`: `String`
      - `icon`: `ContractAfterSigningIcon!` (required, one of `GOLIATH`, `ARROW_RIGHT`, `CALENDAR`, `NONE`). The mark beside the After signing button's label. GOLIATH: Goliath's own mark, with a trailing arrow.
      - `style`: `ContractAfterSigningStyle!` (required, one of `DARK`, `LIGHT`, `BRAND`). How the After signing button is painted. DARK: The app's dark button. LIGHT: White with an outline. BRAND: Filled with the template owner's own color.
      - `color`: `String`
      - `autoContinue`: `Boolean!` (required)
    - `salesOfferId`: `ID`. The Goliath sales offer this send carries (a Goliath plan template's, created by a Goliath admin from the Plan sheet).
  - `heldContractId`: `ID`. A held workflow draft this send completes (from `heldDraft`): revision 1 is frozen on that contract.

## Response (data, an example)

```json
{
  "contractsMutation": {
    "prepareContract": {
      "id": "<ID>",
      "title": "…",
      "status": "PREPARING",
      "revisionNumber": 0,
      "contactName": "…",
      "unsignedPdfUrl": "…"
    }
  }
}
```

## 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": "prepareContract",
    "variables": {
      "input": {
        "idempotencyKey": "<idempotencyKey>",
        "contract": {
          "templateId": "<templateId>",
          "templateVersionId": "<templateVersionId>",
          "contactId": "<contactId>",
          "title": "<String>",
          "values": [
            {
              "key": "<key>",
              "value": "<String>"
            }
          ],
          "recipients": [
            {
              "roleKey": "<roleKey>",
              "displayName": "<String>"
            }
          ],
          "subject": "<String>",
          "message": "<String>",
          "expiryDays": 10
        }
      }
    }
  }'
```
