> 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/accounting/freee-accounting-custom-companies.md).

# freee会計の事業所データを取得する

{% hint style="success" %}

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

このレシピは、[freee会計 APIリファレンス - 取引先API](https://developer.freee.co.jp/reference/accounting/reference#/Companies) を参考に記述されています。
{% endhint %}

## **freee会計の「事業所データ」とは**

freee会計の事業所データとは、ユーザーが所属する事業所の一覧データです。\
（参考：[freee会計のメンバー招待・権限 - freeeヘルプセンター](https://support.freee.co.jp/hc/ja/articles/203318190-freee%E4%BC%9A%E8%A8%88%E3%81%AE%E3%83%A1%E3%83%B3%E3%83%90%E3%83%BC%E6%8B%9B%E5%BE%85-%E6%A8%A9%E9%99%90)）

### **freee会計の「事業所データ」の構造**

```json
{
  "companies": [
    {
      "id": 1,
      "name": "freee事務所",
      "name_kana": "フリージムショ",
      "display_name": "freee事務所",
      "role": "admin"
    }
  ]
}
```

### **freee会計APIにおける位置づけ**

freee会計のいくつかのAPIでは、**事業所ID**がリクエストの必須項目となっており、そういったAPIを実行するためには事前に事業所データを取得しておく必要があります。

ただしAnyflow Embedでは、エンドユーザー変数で[**アシスト**](/wizard-editor/widget.md#ashisuto)を設定することで、事業所データの取得が自動的に行われます。エンドユーザーが所属する事業所をリストの中から選択すると、選択した事業所に対応する事業所IDがソリューションの中で使用できます。

そのため、基本的にはソリューションの中で事業所データを独自に取得する必要はありません。

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

本レシピでは、上記のアシストが目的に合わず使えない場合や、事業所の一覧を取得したい場合のために、独自に事業所データを取得する方法を紹介します。

Anyflow Embedでfreee会計の事業所データを取得する手順を紹介します。

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

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

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

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

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

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

### **2. freee会計のカスタムアクションを設定する**

freee会計コネクタを追加します。

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

以下の通りに設定を行います。

| 設定項目名         | 設定値               |
| ------------- | ----------------- |
| カスタムアクション名    | 事業所データを取得         |
| HTTPメソッド      | GET               |
| リクエストパス       | `api/1/companies` |
| リクエストURLパラメータ | ※ 設定不要            |
| リクエストヘッダー     | ※ 設定不要            |
| リクエストタイプ      | ※ 設定不要            |
| レスポンスヘッダー定義   | ※ 設定不要            |
| レスポンスタイプ      | json              |

また、「レスポンスボディ定義」には以下の設定を行います。

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

```json
{
  "companies": [
    {
      "id": 1,
      "name": "freee事務所",
      "name_kana": "フリージムショ",
      "display_name": "freee事務所",
      "role": "admin"
    }
  ]
}
```

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

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

| 設定項目名      | 設定値           |
| ---------- | ------------- |
| アクション      | 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
name
name_kana
display_name
role
```

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

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

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

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

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

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

```
id
name
name_kana
display_name
role
```

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

<figure><img src="https://files.readme.io/e7615d3-CleanShot_2024-02-24_at_20.45.59.png" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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


---

# 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/accounting/freee-accounting-custom-companies.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.
