# social.grain.repo.applyWrites

> Make several writes in the logged-in account's repo at once, as com.atproto.repo.applyWrites makes them at its PDS, and index them before answering. Called as social.grain.repo.createRecord is.

- Kind: procedure
- Authority: repo.grain.social
- Lexicon: 1
- Published by [grain.social](https://lexicon.garden/identity/did:plc:e7rftrdyz5e2rw4y6ocszew2), the NSID's authority

## Links

- [Documentation](https://lexicon.garden/lexicon/did:plc:e7rftrdyz5e2rw4y6ocszew2/social.grain.repo.applyWrites)
- [Schema JSON](https://lexicon.garden/lexicon/did:plc:e7rftrdyz5e2rw4y6ocszew2/social.grain.repo.applyWrites/schema.json)
- [Analytics](https://lexicon.garden/lexicon/did:plc:e7rftrdyz5e2rw4y6ocszew2/social.grain.repo.applyWrites/analytics)

## Procedure (`social.grain.repo.applyWrites`)

Type: procedure · POST

### Input (application/json)

- `writes` (array, required)
  - Constraints: minLength: 1, maxLength: 200
  - `items` (union)
    - One of (closed): `#create`, `#update`, `#delete`

### Output (application/json)

- `results` (array, required): Each write's result, in the place of its write.
  - `items` (union)
    - One of (closed): `#createResult`, `#updateResult`, `#deleteResult`

### Errors

- `UnknownCollection`: grain does not index a write's collection.
- `InvalidRecord`: A write's value does not fit its lexicon.
- `InvalidSwap`: No description in schema.
- `ScopeMissingError`: The account's PDS granted the session less than the writes need.

## #create (`social.grain.repo.applyWrites#create`)

Type: object

### Properties

- `collection` (string · nsid, required)
- `rkey` (string · record-key)
  - Constraints: maxLength: 512
- `value` (unknown, required)

## #createResult (`social.grain.repo.applyWrites#createResult`)

Type: object

### Properties

- `cid` (string · cid, required)
- `uri` (string · at-uri, required)

## #delete (`social.grain.repo.applyWrites#delete`)

Type: object

### Properties

- `collection` (string · nsid, required)
- `rkey` (string · record-key, required)
  - Constraints: maxLength: 512

## #deleteResult (`social.grain.repo.applyWrites#deleteResult`)

Type: object

### Properties


## #update (`social.grain.repo.applyWrites#update`)

Type: object

### Properties

- `collection` (string · nsid, required)
- `rkey` (string · record-key, required)
  - Constraints: maxLength: 512
- `value` (unknown, required)

## #updateResult (`social.grain.repo.applyWrites#updateResult`)

Type: object

### Properties

- `cid` (string · cid, required)
- `uri` (string · at-uri, required)

## Schema

```json
{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "create": {
      "properties": {
        "collection": {
          "format": "nsid",
          "type": "string"
        },
        "rkey": {
          "format": "record-key",
          "maxLength": 512,
          "type": "string"
        },
        "value": {
          "type": "unknown"
        }
      },
      "required": [
        "collection",
        "value"
      ],
      "type": "object"
    },
    "createResult": {
      "properties": {
        "cid": {
          "format": "cid",
          "type": "string"
        },
        "uri": {
          "format": "at-uri",
          "type": "string"
        }
      },
      "required": [
        "uri",
        "cid"
      ],
      "type": "object"
    },
    "delete": {
      "properties": {
        "collection": {
          "format": "nsid",
          "type": "string"
        },
        "rkey": {
          "format": "record-key",
          "maxLength": 512,
          "type": "string"
        }
      },
      "required": [
        "collection",
        "rkey"
      ],
      "type": "object"
    },
    "deleteResult": {
      "properties": {},
      "type": "object"
    },
    "main": {
      "description": "Make several writes in the logged-in account's repo at once, as com.atproto.repo.applyWrites makes them at its PDS, and index them before answering. Called as social.grain.repo.createRecord is.",
      "errors": [
        {
          "description": "grain does not index a write's collection.",
          "name": "UnknownCollection"
        },
        {
          "description": "A write's value does not fit its lexicon.",
          "name": "InvalidRecord"
        },
        {
          "name": "InvalidSwap"
        },
        {
          "description": "The account's PDS granted the session less than the writes need.",
          "name": "ScopeMissingError"
        }
      ],
      "input": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "writes": {
              "items": {
                "closed": true,
                "refs": [
                  "#create",
                  "#update",
                  "#delete"
                ],
                "type": "union"
              },
              "maxLength": 200,
              "minLength": 1,
              "type": "array"
            }
          },
          "required": [
            "writes"
          ],
          "type": "object"
        }
      },
      "output": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "results": {
              "description": "Each write's result, in the place of its write.",
              "items": {
                "closed": true,
                "refs": [
                  "#createResult",
                  "#updateResult",
                  "#deleteResult"
                ],
                "type": "union"
              },
              "type": "array"
            }
          },
          "required": [
            "results"
          ],
          "type": "object"
        }
      },
      "type": "procedure"
    },
    "update": {
      "properties": {
        "collection": {
          "format": "nsid",
          "type": "string"
        },
        "rkey": {
          "format": "record-key",
          "maxLength": 512,
          "type": "string"
        },
        "value": {
          "type": "unknown"
        }
      },
      "required": [
        "collection",
        "rkey",
        "value"
      ],
      "type": "object"
    },
    "updateResult": {
      "properties": {
        "cid": {
          "format": "cid",
          "type": "string"
        },
        "uri": {
          "format": "at-uri",
          "type": "string"
        }
      },
      "required": [
        "uri",
        "cid"
      ],
      "type": "object"
    }
  },
  "id": "social.grain.repo.applyWrites",
  "lexicon": 1
}
```
