# social.grain.repo.createRecord

> Create a record in the logged-in account's repo, at its PDS, and index it before answering. For the web, by its session cookie, from a page of the site; a service token is refused (the apps write to their own PDS, then call social.grain.sync.refreshRecords).

- 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.createRecord)
- [Schema JSON](https://lexicon.garden/lexicon/did:plc:e7rftrdyz5e2rw4y6ocszew2/social.grain.repo.createRecord/schema.json)
- [Analytics](https://lexicon.garden/lexicon/did:plc:e7rftrdyz5e2rw4y6ocszew2/social.grain.repo.createRecord/analytics)

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

Type: procedure · POST

### Input (application/json)

- `collection` (string · nsid, required): A collection grain indexes.
- `record` (unknown, required): The record. One without a $type is given the collection's.
- `rkey` (string · record-key)
  - Constraints: maxLength: 512
- `swapCommit` (string · cid)

### Output (application/json)

- `schema` (ref)
  - Reference: `social.grain.repo.defs#written`

### Errors

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

## Schema

```json
{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "main": {
      "description": "Create a record in the logged-in account's repo, at its PDS, and index it before answering. For the web, by its session cookie, from a page of the site; a service token is refused (the apps write to their own PDS, then call social.grain.sync.refreshRecords).",
      "errors": [
        {
          "description": "grain does not index the collection.",
          "name": "UnknownCollection"
        },
        {
          "description": "The record does not fit its lexicon.",
          "name": "InvalidRecord"
        },
        {
          "name": "InvalidSwap"
        },
        {
          "description": "The account's PDS granted the session less than the write needs.",
          "name": "ScopeMissingError"
        }
      ],
      "input": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "collection": {
              "description": "A collection grain indexes.",
              "format": "nsid",
              "type": "string"
            },
            "record": {
              "description": "The record. One without a $type is given the collection's.",
              "type": "unknown"
            },
            "rkey": {
              "format": "record-key",
              "maxLength": 512,
              "type": "string"
            },
            "swapCommit": {
              "format": "cid",
              "type": "string"
            }
          },
          "required": [
            "collection",
            "record"
          ],
          "type": "object"
        }
      },
      "output": {
        "encoding": "application/json",
        "schema": {
          "ref": "social.grain.repo.defs#written",
          "type": "ref"
        }
      },
      "type": "procedure"
    }
  },
  "id": "social.grain.repo.createRecord",
  "lexicon": 1
}
```
