# Thing routes: restore, share, unrelate

URL: /code/api/thing/verbs-restore · Id: `page:code/api/thing/verbs-restore`

> The Thing Verbs restore, share, unrelate as api.sb routes, with inputs, result, refusals and an example.

Reference for [Thing](/business/nouns/thing), one group of [Thing routes](/code/api/thing).

### Thing.restore
Restore brings back a deleted Thing, or one an undone Action removed, with its history and Relationships intact. [Verb page](/business/nouns/thing/restore?interface=api).

```text
POST /{namespace}/things/{thing}/restore
```

Path: `thing`. Emits [`Thing.restored`](/business/events/Thing.restored).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `thing` | [Thing](/business/nouns/thing) | Yes | The deleted Thing. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `thing` | [Thing](/business/nouns/thing) | Yes | The Thing, back in every list and query it left. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| The Thing is not deleted | [`refused`](/code/api/errors/refused) | Clear what the check names, then call it again. | None. |
| `thing` is missing, or is not a thing | [`invalid-input`](/code/api/errors/invalid-input) | Send `thing` as a thing, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/things/thing_8ds0r9vvRl/restore \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: leaseline-thing-restore-1"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "thing": {
    "$id": "https://api.sb/leaseline.app/things/thing_8ds0r9vvRl",
    "$type": "Thing",
    "id": "Example id",
    "type": [
      "noun_v0akLUrXCN"
    ]
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Thing.restore",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Thing.share
Share grants a person, a Role or a guest Verbs on one record and everything it contains. [Verb page](/business/nouns/thing/share?interface=api).

```text
POST /{namespace}/things/{thing}/share
```

Path: `thing`. Body, as JSON: the other inputs. Emits [`Thing.shared`](/business/events/Thing.shared).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `thing` | [Thing](/business/nouns/thing) | Yes | The record to share. |
| `to` | [Party](/business/nouns/party) | Yes | Who receives the grant: a person, or a guest who fills only the `guest` Role. |
| `verbs` | `string[]` | Yes | The Verbs granted, such as `get` and `comment`. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `permission` | [Permission](/business/nouns/permission) | Yes | The grant, scoped to the record and its contents. |
| `thing` | [Thing](/business/nouns/thing) | Yes | The Thing shared. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| `thing` is missing, or is not a thing | [`invalid-input`](/code/api/errors/invalid-input) | Send `thing` as a thing, then call it again. | None. |
| `to` is missing, or is not a party | [`invalid-input`](/code/api/errors/invalid-input) | Send `to` as a party, then call it again. | None. |
| `verbs` is missing, or is not a string list | [`invalid-input`](/code/api/errors/invalid-input) | Send `verbs` as a string list, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/things/thing_8ds0r9vvRl/share \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: leaseline-thing-share-1" \
  -H "Content-Type: application/json" \
  -d '{"to":"party_hmQWaPrAyZ","verbs":["Example verbs"]}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "permission": {
    "$id": "https://api.sb/leaseline.app/permissions/permission_1IFL54Tlfx",
    "$type": "Permission",
    "scope": "Example scope"
  },
  "thing": {
    "$id": "https://api.sb/leaseline.app/things/thing_8ds0r9vvRl",
    "$type": "Thing",
    "id": "Example id",
    "type": [
      "noun_v0akLUrXCN"
    ]
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Thing.share",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Thing.unrelate
Unrelate ends a Relationship between two Things; the link stays in history and reads back at any earlier moment. [Verb page](/business/nouns/thing/unrelate?interface=api).

```text
POST /{namespace}/things/{thing}/unrelate
```

Path: `thing`. Body, as JSON: the other inputs. Emits [`Thing.unrelated`](/business/events/Thing.unrelated).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `thing` | [Thing](/business/nouns/thing) | Yes | The source Thing. |
| `predicate` | `string` | Yes | The Relationship as read from the source. |
| `to` | [Thing](/business/nouns/thing) | Yes | The target Thing. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `relationship` | [Relationship](/business/nouns/relationship) | Yes | The ended Relationship. |
| `thing` | [Thing](/business/nouns/thing) | Yes | The Thing the Relationship started from. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| `thing` is missing, or is not a thing | [`invalid-input`](/code/api/errors/invalid-input) | Send `thing` as a thing, then call it again. | None. |
| `predicate` is missing, or is not a string | [`invalid-input`](/code/api/errors/invalid-input) | Send `predicate` as a string, then call it again. | None. |
| `to` is missing, or is not a thing | [`invalid-input`](/code/api/errors/invalid-input) | Send `to` as a thing, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/things/thing_8ds0r9vvRl/unrelate \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: leaseline-thing-unrelate-1" \
  -H "Content-Type: application/json" \
  -d '{"predicate":"Example predicate","to":"thing_8ds0r9vvRl"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "relationship": {
    "$id": "https://api.sb/leaseline.app/relationships/relationship_iUVcHztTJh",
    "$type": "Relationship",
    "predicate": "Example predicate",
    "inverse": "Example inverse"
  },
  "thing": {
    "$id": "https://api.sb/leaseline.app/things/thing_8ds0r9vvRl",
    "$type": "Thing",
    "id": "Example id",
    "type": [
      "noun_v0akLUrXCN"
    ]
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Thing.unrelate",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```