# Notes

Source: https://developers.swell.is/backend-api/notes

A note records an internal comment against a single record, and appears in that record's activity in the Swell dashboard. Notes are used with orders, subscriptions, and invoices. They are internal and are never shown to the customer.

Notes live in their own collection at `/:notes`, rather than on the record itself, so the same endpoint serves every model that supports them. The endpoint supports `GET`, `POST`, `PUT`, and `DELETE`.

### Fields

- `model`: the collection the note belongs to, such as `orders`, `subscriptions`, or `invoices`.
- `record_id`: the id of the record the note is attached to. Together with `model` this identifies the record.
- `body`: the text of the note.
- `user_id`: the id of the dashboard user credited with the note.

Two link fields can be expanded: `record` resolves the record the note is attached to, and `user` resolves the user who wrote it.

### Examples

**Working with notes**

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

// Add a note to an order
await swell.post('/:notes', {
  model: 'orders',
  record_id: '6345c7480e85140011bfb22f',
  body: 'Box lost in transit, replacement sent.',
  user_id: '621e50bb482679013db5f85e'
});

// List the notes on one record, newest first
await swell.get('/:notes', {
  where: {
    model: 'orders',
    record_id: '6345c7480e85140011bfb22f'
  },
  sort: 'date_created desc'
});

// Expand the user who wrote each note
await swell.get('/:notes', {
  where: { model: 'subscriptions' },
  expand: ['user']
});

// Edit a note
await swell.put('/:notes/{id}', {
  id: '644124c61bf9520013fb7db4',
  body: 'Box lost in transit, replacement delivered.'
});

// Remove a note
await swell.delete('/:notes/{id}', {
  id: '644124c61bf9520013fb7db4'
});
```

Orders, subscriptions, and invoices also each carry a single `notes` field on the record itself. That field holds one block of internal text, while the `/:notes` collection holds a series of separate notes, each attributed to a user.
