# Write multiple records

## `POST /v1/records/upsert`

Process records in order. Each item returns its own result or error. Requires the `write` scope.

```json
{
  "tags": [
    "Records"
  ],
  "operationId": "upsert-records",
  "summary": "Write multiple records",
  "description": "Process records in order. Each item returns its own result or error. Requires the `write` scope.",
  "x-retainer-scope": "write",
  "parameters": [],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "items": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "object": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Singular API name of the object, e.g. \"person\", as describe_schema lists it."
                  },
                  "id": {
                    "description": "Update this record.",
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "bindings": {
                    "type": "object",
                    "properties": {
                      "bindings_revision": {
                        "type": "integer",
                        "exclusiveMinimum": 0,
                        "maximum": 9007199254740991
                      },
                      "objectId": {
                        "type": "string",
                        "format": "uuid",
                        "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                      },
                      "fieldIds": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "additionalProperties": {
                          "type": "string",
                          "format": "uuid",
                          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                        }
                      }
                    },
                    "required": [
                      "bindings_revision",
                      "objectId",
                      "fieldIds"
                    ],
                    "additionalProperties": false
                  },
                  "match": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "minProperties": 1,
                    "maxProperties": 1,
                    "description": "Match one unique field."
                  },
                  "values": {
                    "default": {},
                    "description": "Field name to value, in its type's format from describe_schema's valueFormats. Composite fields (emails, phones, links, money, full_name, address) are replaced whole, so include the values to keep. null clears a field. A many_to_many relation takes the whole list of record IDs ([] clears it): read the record first and send every member to keep. Fields marked readOnly are not yours to write: an inverse relation (isInverse) is written from the other side, and any other is written only by the app that added it.",
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "ifMissing": {
                    "default": "fail",
                    "description": "When id or match finds nothing: \"fail\" (default) or \"create\". Use \"create\" only when you mean to add a new record.",
                    "type": "string",
                    "enum": [
                      "fail",
                      "create"
                    ]
                  },
                  "expectedUpdatedAt": {
                    "description": "Reject the write if the record changed since this updatedAt.",
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "source": {
                    "description": "The event id (from log_event) these values come from. Values then carry the event's date, so an older email cannot overwrite a newer claim. Omit only for values that come from no conversation.",
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "idempotencyKey": {
                    "description": "Only for creates without id or match: retrying with the same key returns the first result instead of creating a second record.",
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  }
                },
                "required": [
                  "object"
                ],
                "additionalProperties": false,
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "id",
                        "match"
                      ]
                    },
                    {
                      "required": [
                        "id",
                        "idempotencyKey"
                      ]
                    },
                    {
                      "required": [
                        "match",
                        "idempotencyKey"
                      ]
                    }
                  ]
                }
              }
            }
          },
          "required": [
            "items"
          ],
          "additionalProperties": false
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "Successful response.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "results": {
                "type": "array",
                "items": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/WriteResult"
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                }
              }
            },
            "required": [
              "results"
            ]
          }
        }
      }
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "default": {
      "$ref": "#/components/responses/ApiError"
    }
  }
}
```

[Full OpenAPI contract](/openapi.json)
