> For the complete documentation index, see [llms.txt](https://docs-embed.anyflow.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-embed.anyflow.jp/recipe/hr/smarthr-custom-crew.md).

# SmartHRの従業員データを取得する

{% hint style="success" %}

### このレシピについて

このレシピは、[SmartHR API | 従業員](https://developer.smarthr.jp/api#%E5%BE%93%E6%A5%AD%E5%93%A1) を参考に記述されています。
{% endhint %}

## **SmartHRの「部署データ」とは**

SmartHR に登録された従業員に関する情報です。\
（参考：[SmartHR API | 従業員](https://developer.smarthr.jp/api#%E5%BE%93%E6%A5%AD%E5%93%A1)）

SmartHR API を利用することで、SmartHR に登録された**従業員データ**の一覧を取得できます。

## **SmartHRの「部署データ」の構造**

```json
{
  "emp_code": "string",
  "last_name": "string",
  "first_name": "string",
  "email": "string",
  "tel_number": "string",
  "emp_status": "employed",
  "position": "string",
  "entered_at": "2024-05-18",
  "resigned_at": "2024-05-18",
  "employment_type": {},
  "birth_at": "2024-05-18",
  "gender": "male"
}
```

## **Anyflow Embedで取得する**

Anyflow Embed で SmartHR の従業員データを取得する手順を紹介します。

SmartHR の従業員データを**スプレッドシートに一括追加する**というシンプルなソリューションを作成し、従業員ｆに含まれるデータを把握します。

<figure><img src="https://files.readme.io/d880132-CleanShot_2024-05-18_at_12.41.292x.png" alt=""><figcaption></figcaption></figure>

### **1. Clickトリガーを設定する**

Clickトリガーを設定します。

<figure><img src="https://files.readme.io/b9650b7-image.png" alt=""><figcaption></figcaption></figure>

### **2. SmartHR コネクタを設定する**

SmartHR コネクタを追加します。本レシピでは背景が白色の SmartHR コネクタを使用します。なお、2つのコネクタの違いについての詳細は [2種類のSmartHRコネクタ](broken://pages/X6fHe8FLtamDEervOs2M)2種類について を記載しています。

<figure><img src="https://files.readme.io/9dfd9b1-CleanShot_2024-05-18_at_12.43.302x.png" alt="" width="563"><figcaption></figcaption></figure>

### **3. SmartHR のカスタムアクションを設定する**

ソリューションエディタに戻り、freee人事労務コネクタを以下の通りに設定します。

| 設定項目名       | 設定値         |
| ----------- | ----------- |
| カスタムアクション名  | 従業員データを取得する |
| HTTPメソッド    | GET         |
| リクエストパス     | /v1/crews   |
| リクエストヘッダー   | ※ 設定不要      |
| リクエストタイプ    | ※ 設定不要      |
| レスポンスヘッダー定義 | ※ 設定不要      |
| レスポンスタイプ    | json        |

レスポンスボディ定義は以下のように設定します。

<figure><img src="https://files.readme.io/e48ca1f-CleanShot_2024-05-18_at_12.59.182x.png" alt="" width="563"><figcaption></figcaption></figure>

### **4. スプレッドシートの列名を設定する**

スプレッドシートコネクタを追加し、以下の通りに設定を行います。

| 設定項目名      | 設定値           |
| ---------- | ------------- |
| アクション      | 1行追加          |
| スプレッドシートID | 任意のスプレッドシートID |
| シートID      | 任意のシートID      |

<figure><img src="https://files.readme.io/677257c-_2024-02-26_17.45.08.png" alt=""><figcaption></figcaption></figure>

「ヘッダーの列名」は以下の通りに設定します。

```
id
last_name
first_name
email
tel_number
```

「行データ」にも同じ様に設定します。

<figure><img src="https://files.readme.io/84cf9ba-CleanShot_2024-05-18_at_13.02.172x.png" alt="" width="563"><figcaption></figcaption></figure>

### **5. スプレッドシートに一括追記する**

スプレッドシートコネクタを追加し、以下の通りに設定を行います。

| 設定項目名      | 設定値           |
| ---------- | ------------- |
| アクション      | 行を一括追加        |
| スプレッドシートID | 任意のスプレッドシートID |
| シートID      | 任意のシートID      |

「ヘッダーの列名」は以下の通りに設定します。

```
id
last_name
first_name
email
tel_number
```

「リストソース」は以下の通りに設定します。

<figure><img src="https://files.readme.io/8fbe67a-CleanShot_2024-05-18_at_13.03.572x.png" alt=""><figcaption></figcaption></figure>

「要素フィールド」は以下の通りに設定します。（「i番目のcrew」から項目を選択します。）

<figure><img src="https://files.readme.io/14f9e65-CleanShot_2024-05-18_at_13.05.522x.png" alt=""><figcaption></figcaption></figure>

### **6. ウィザードを設定する**

必要な認証をウィザードに追加します。

### **7. テストを行う**

テストを行うと、スプレッドシートにデータが追加されていることがわかります。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs-embed.anyflow.jp/recipe/hr/smarthr-custom-crew.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
