> 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/solution-editor/triggers/outgoing/request-triggers.md).

# Requestトリガー

## **概要**

Requestトリガーを使用すると、自社プロダクトからAnyflowにAPIリクエストを送信することでソリューションを実行することができます。\
ソリューションの実行が終わると、実行結果がAPIレスポンスとして返却されます。

例えば外部SaaSのデータを自社プロダクトのDBに取り込む場合などに、\
**自社のAPIを用意しなくてもデータを取得することができます**。

Requestトリガーを使用したソリューションを実行するまでの流れは次のようになります：

<table><thead><tr><th width="51.66015625">#</th><th>内容</th><th>場所</th></tr></thead><tbody><tr><td>1</td><td>Requestトリガーをソリューションに適用する</td><td>Anyflow Embed 管理画面</td></tr><tr><td>2</td><td>エンドポイントが発行される</td><td>Anyflow Embed 管理画面</td></tr><tr><td>3</td><td><strong>エンドポイントにAPIリクエストを送信する</strong></td><td><strong>自社プロダクトのサーバー</strong></td></tr><tr><td>4</td><td>ソリューションが実行される</td><td>Anyflow Embed</td></tr><tr><td>5</td><td><strong>実行結果をAPIレスポンスとして受け取る</strong></td><td><strong>自社プロダクトのサーバー</strong></td></tr></tbody></table>

{% hint style="success" %}

### エンドユーザーでのインストールは必要です

他のトリガーと同様、エンドユーザーがソリューションをインストールしている場合のみ実行されます。

エンドユーザーがソリューションをインストールしていない場合、RequestトリガーのAPIリクエストを送信してもソリューションは実行されません。
{% endhint %}

## **使用方法**

トリガーで「Request & Response」を選択します。

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

自社プロダクトから送信するリクエストのペイロードを定義します。\
ここでは例として firstname, lastname, email というシンプルな3項目を定義します。

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

次に、このソリューションの処理結果を自社プロダクトに返却するために、レスポンス定義を設定します。

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

<table><thead><tr><th width="216.4296875">項目</th><th>説明</th></tr></thead><tbody><tr><td>レスポンス名</td><td>後述の<a href="/pages/kcB40BqXF6ExxQl04t7e">Responseステップ</a>でこのレスポンス定義を呼び出すために使用します。<br>APIレスポンスの中にはこの名前は反映されません。</td></tr><tr><td>レスポンスペイロード</td><td>APIレスポンスのペイロードスキーマを定義できます。<br>ここで設定するのは「スキーマ」のみです。<br>実際のレスポンスの「値」は後述の<a href="/pages/kcB40BqXF6ExxQl04t7e">Responseステップ</a> で設定します。</td></tr></tbody></table>

参考：レスポンスボディの仕様

```json
{
  "job": {
    "id": string,
    "state": "succeeded" | "failed"
  },
  "payload": {
    // レスポンスペイロードで定義したスキーマ
  }
}
```

今回は、　レスポンス名：created　レスポンスペイロード：id　として設定します。

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

次にアクションを適用します。\
アクションの設定ではリクエストペイロードの値を使用できます。

ここではHubSpotの「人物情報を作成」アクションを設定します。

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

3つ目のステップとしてResponseステップを適用します。\
「ステップを追加」 から「レスポンス」を選択します。

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

Responseステップの設定にて、レスポンス名から先ほど作成した「created」を選択します。

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

ステップ1のRequestトリガーで作成したスキーマ定義が呼び出され、APIレスポンスとして返却する値を設定できます。

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

{% hint style="success" %}

### ヒント

Responseステップを適用しない場合には、payloadを含まないレスポンスが返却されます。
{% endhint %}

参考：Resopnseステップを適用しない場合のレスポンス

```json
{
  "job": {
    "id": string,
    "state": "succeeded" | "failed"
  }
}
```

## **Responseステップを複数配置する**

Responseステップはソリューションの中で複数配置することが可能です。\
例えば以下のように、ifなどと組み合わせて状況に応じたレスポンスをすることができます。

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

Responseステップの仕様の詳細は[こちら](/solution-editor/triggers/outgoing/request-triggers/response-step.md)をご確認ください。

## **テスト**

テストモードを起動すると、1度のみリクエストを受け付けます。\
リクエストに必要なcURLの例が表示されるので、ペイロードの値を変更しつつご自身の環境から実行してください。

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

リクエストを送信すると、ソリューションが実行されます。\
実行が完了すると、テスト結果画面が表示されます。

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

{% hint style="danger" %}

### ヘッダーにアクセストークンの値が表示されない場合

「cURLで実行」のサンプルコードの中でAuthorizationヘッダーにアクセストークンの具体的な値が設定されていない場合は、[API Secretの生成画面](https://embed.anyflow.jp/settings/api-secret)でSecretキーを生成してから再度お試しください。\
一度生成してあれば、テストの度に生成する必要はありません。
{% endhint %}

<figure><img src="https://files.readme.io/ec495330e02a1218c5390092dc9eea288c9fa66817fbc7b72ccbc1a6c2f2d3ea-image.png" alt="アクセストークンの値が表示されていない場合"><figcaption><p>アクセストークンの値が表示されていない場合</p></figcaption></figure>

<figure><img src="https://files.readme.io/413faaf304cdab9c24d2a69192b5b6e570c256b3e47a2ff094e0becb1bed59a2-image.png" alt="API Secret の生成画面"><figcaption><p>API Secret の生成画面</p></figcaption></figure>

## **本番実装**

自社プロダクトの環境でリクエストを送信する場合は、[Vender Server API](/anyflow-api/vender-server-api.md) の仕様書を見ながら実装してください。

手順：

1. リクエストトリガー用のアクセストークンを取得する `POST /token`
2. ソリューションインスタンスを取得する `GET /solution_instances`
3. リクエストトリガーを発火させる `POST /request_trigger`


---

# 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/solution-editor/triggers/outgoing/request-triggers.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.
