# Resources API

## Overview

メッセージオブジェクトや、ユーザーオブジェクトなどのDB上に格納されている情報へのアクセスができるAPIです。

### Dreaming in URL’s

```
https://{YOUR_OKSKY_DOMAIN}/rapi/v1/
```

{% hint style="info" %}
YOUR\_OKSKY\_DOMAINは、テナント毎に発行されます。
{% endhint %}

Sample URLs

```
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/{resource_name}
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/{resource_name}/{resource_id}
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/{resource_name}/relationships/{resource_name}
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/{resource_name}/relationships/{child_resource_name}/{child_resource_id}
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/rooms
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/rooms/1/
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/rooms/1/relationships/messages
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/messages
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/messages/1
```

## GET Request Sample

<mark style="color:blue;">`GET`</mark> `https://{YOUR_OKSKY_DOMAIN}/rapi/v1/rooms`

#### Query Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

#### Headers

| Name           | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| X-Access-Token | string | your access token set here. |
| Content-Type   | string | application/vnd.api+json    |
| Accept         | string | application/vnd.api+json    |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

### Fetch (GET) Requests

JSONAPIはフィルタリング、ページネーション、ソート、関連リソースを含むクエリ文字列パラメタを提供します。

#### Example

```
https://{YOUR_OKSKY_DOMAIN}.ok-sky.com/rapi/v1/rooms
  ?page[number]=2
  &page[size]=50
  &sort=create_user_id,-created
  &fields[users]=id,name,created_at
  &include=messages,create_user
  &filter[kind]=support_room
```

* page\[] - ページパラメータはページ番号とレコード数を指定することができます。
  * number
    * ページ番号
    * デフォルトは `1`
  * size
    * １ページあたりのレコード数
    * デフォルトは `25`
    * 最大取得レコード数は `100`
* sort - カンマで区切られたフィールド名。降順で並び替える場合は、フィールド名に `-` をつける。
* fields\[resource] - 関連リソース名を指定します。値はカンマで区切られた属性名。
* include - カンマで区切られた関連リソース名。
* filter\[] - 属性名を指定します。

## Create Request Sample

<mark style="color:green;">`POST`</mark> `https://{YOUR_OKSKY_DOMAIN}/rapi/v1/rooms`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

### POST Request

POST（作成）リクエストは、JSONペイロードが必要です。

#### Example

```
data: {
  type: "rooms",
  attributes: {
    kind: "support_room"
  }
}
```

* data - 各リソースオブジェクトの内容を参照
  * type - リソース名
  * attributes - 属性名と値のハッシュ値。

## Edit Request Sample

<mark style="color:orange;">`PUT`</mark> `https://{YOUR_OKSKY_DOMAIN}/rapi/v1/rooms/1`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

### PUT Request

PUT（更新）リクエストには、JSONペイロードが必要です。

#### Example

```
data: {
  type: "rooms",
  id: "1",
  attributes: {
    kind: "support_room"
  }
}
```

* data - 各リソースオブジェクトの内容を参照
  * type - リソース名
  * id - 更新対象のリソースID。
  * attributes - 属性名と値のハッシュ値。

## Delete Request Sample

<mark style="color:red;">`DELETE`</mark> `https://{YOUR_OKSKY_DOMAIN}/rapi/v1/rooms/1`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

### Delete Request

IDを持つレコードエンドポイントを指定します。

### Status codes

返す主要なstatus codeは以下です。

| Code | Description          |
| ---- | -------------------- |
| 200  | Success              |
| 201  | Success              |
| 400  | bad request          |
| 401  | unauthorized         |
| 403  | unauthorized         |
| 404  | not found            |
| 405  | not allowed          |
| 406  | not acceptable       |
| 422  | unprocessable entity |
| 500  | standard error       |
| 501  | not implemented      |

### Error responses

エラー時のresponse bodyは、以下のフィールドを持つJSONデータです

| Field             | Type         | Description |
| ----------------- | ------------ | ----------- |
| erros             | Object Array |             |
| errors\[n].status | error code   |             |
| errors\[n].code   | error code   |             |
| errors\[n].title  | error title  |             |
| errors\[n].detail | error detail |             |

### Error messages

Error response JSONにおける errors\[title] フィールドに設定される主要なエラーメッセージは以下です。

| Title                                                                | Description               |
| -------------------------------------------------------------------- | ------------------------- |
| Unauthorized                                                         | AccessTokenなど、認証に必要な情報の不足 |
| Invalid IP Address. Did you set the VALID\_IPS environment variable? | リクエスト元IPアドレスが不正           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ok-sky.com/resources-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
