# 特定の商品が入った注文が作成されたとき、フルフィルメントを自動にする方法

**URL:** <https://community.shopify.com/t/topic/302744>\
**Category:** 決済、配送、フルフィルメント\
**Created:** [March 6, 2024, 1:08am UTC](https://community.shopify.com/t/topic/302744 "2024-03-06T01:08:10Z")\
**Posts on this page:** 2\
**Page:** 1

## AI-generated summary

**課題:**
Shopify Flowを使用して、特定商品Aを含む注文作成時に自動フルフィルメントを実現したい。支払方法はクレジットカードのみで、顧客への通知は不要。

**解決方法:**
- Shopify Flowで「Order Created」をトリガーに設定
- 支払方法が「shopify_payments」の場合に分岐
- ShopifyのREST APIを実行してフルフィルメントを自動化

**実装詳細:**
- HTTP method: POST
- エンドポイント: `/admin/api/2024-01/fulfillments.json`
- カスタムアプリを作成してアクセストークンを発行し、`X-Shopify-Access-Token`ヘッダーに設定
- Bodyには`fulfillment_order_id`を動的に取得するLiquidコードを使用

**検証結果:**
開発ストアでテストし、この方法で正常に動作することを確認。スクリーンショット付きで具体的な設定手順が共有されている。

<div class="post-metadata">

**Author:** ![tatsuki\_ttt](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tatsuki\_ttt](https://community.shopify.com/u/tatsuki_ttt)\
**Post date:** [March 6, 2024, 1:08am UTC](https://community.shopify.com/t/topic/302744/1 "2024-03-06T01:08:10Z")

</div>

お世話になります。

フルフィルメントの自動化について知っていらっしゃる方がおられましたら教えてください。

★shopifyflowを利用予定です。

特定の商品Aが入った注文が作成されたとき、「アイテムをフルフィルメント」を自動で行いたいと考えております。

※支払い方法はクレジットカードのみ

※お客様への通知は不要

shopify flowで実装できないかと調査しておりますが、なかなかうまくいかずの状態です･･･。

わかる方がいらっしゃいましたら、何卒ご協力いただけますと幸いです。

よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![Qcoltd](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/qcoltd/32/900_2.png) [@Qcoltd](https://community.shopify.com/u/Qcoltd)\
**Post date:** [March 6, 2024, 9:58am UTC](https://community.shopify.com/t/topic/302744/2 "2024-03-06T09:58:04Z")

</div>

@tatsuki_ttt 様

Order Createdをトリガーとした場合、シンプルに「発送済み」にするアクションが見当たらなかったので、

調査してみたところ、下記の投稿を見つけました。

[https://community.shopify.com/post/2209832](https://community.shopify.com/post/2209832)

しかし、こちらの投稿の方法で本当にうまくいくのか確信がなかったので、

開発ストアで試してみました。

結論、下記の方法でうまく行きました。

 ![screenshot_20240307_02.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/1/6/165db37a33b88943f03679eeb0abbd34be37f02e.png)

(1)トリガー: Order Created

(2) 分岐: 支払方法(Order.paymentGatewayNames)が "shopify\_payments"の時

(3) ShopifyのAPI実行

※クレジットカード支払いを、Shopify Paymentによる支払いとして考えています。

API実行は下記のようにします。

 ![screenshot_20240307_03.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/8/3/8372162802dca13c2bc220bfc81f68f5c6cbc1f4.png)

HTTP method: POST

URL: https://{{shop.myshopifyDomain}}/admin/api/2024-01/fulfillments.json

Body:

```markup
{%- assign fulfillment_order_id = 0 -%}
{%- for fulfillmentOrders_item in order.fulfillmentOrders -%}
  {%- assign fulfillment_order_id = fulfillmentOrders_item.id | remove: "gid://shopify/FulfillmentOrder/" -%}
{%- endfor -%}
{
    "fulfillment": {
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": {{ fulfillment_order_id }}
            }
        ],
        "tracking_info": {
            "number": "MS1562678",
            "url": "https://www.my-shipping-company.com?tracking_number=MS1562678"
        }
    }
}

```

上記のtacking\_infoは、

[https://shopify.dev/docs/api/admin-rest/2024-01/resources/fulfillment#post-fulfillments](https://shopify.dev/docs/api/admin-rest/2024-01/resources/fulfillment#post-fulfillments)

こちらのサンプルの値をそのまま利用しています。

不要であれば、指定しなくても大丈夫ですので、下記にご変更ください。

```markup
{%- assign fulfillment_order_id = 0 -%}
{%- for fulfillmentOrders_item in order.fulfillmentOrders -%}
  {%- assign fulfillment_order_id = fulfillmentOrders_item.id | remove: "gid://shopify/FulfillmentOrder/" -%}
{%- endfor -%}
{
    "fulfillment": {
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": {{ fulfillment_order_id }}
            }
        ]
    }
}

```

X-Shopify-Access-Tokenについてです。

こちらは下記の方法で、カスタムアプリを作成して発行したトークンを指定します。

[https://help.shopify.com/ja/manual/apps/app-types/custom-apps#enable-custom-app-development](https://help.shopify.com/ja/manual/apps/app-types/custom-apps#enable-custom-app-development)

APIスコープは、正確にはどれが必要か分かっていませんが、私は下記を指定して実際の動作を確認しました。

（設定しなくても問題ないスコープもありそうです。）

 ![screenshot_20240307_04.png](https://canada1.discourse-cdn.com/shopifyforum/original/3X/a/e/ae011ba1dc3b134da4e2d420ecbb4ae4f8dc48f1.png)

> 特定の商品Aが入った注文が作成されたとき

こちらについては、

(2) 分岐: 支払方法(Order.paymentGatewayNames)が "shopify\_payments"の時

の、後に、商品情報による分岐を作成すれば良いはずです。

ご参考まで。

(キュー田辺)
