如何在 Shopify 中创建自定义 Web 挂钩

How to create a Custom Web hook in Shopify

我想在 Shopify 中使用私人应用程序为客户登录创建自定义网络挂钩,下面是我的代码,但我收到错误 Array ( [errors] => Array ( [topic] => 数组 ( [0] => 指定的主题无效。允许的主题:app/uninstalled、carts/create、carts/update、checkouts/create、checkouts/delete、checkouts/update, checkouts/paid, collections/create, collections/delete, collections/update, customer_groups/create, customer_groups/delete, customer_groups/update, customers/create, customers/delete、customers/disable、customers/enable、customers/update、order_transactions/create、orders/cancelled、orders/create、orders/delete、orders/edited, orders/fulfilled, orders/paid, orders/partially_fulfilled, orders/updated, products/create, products/delete, products/update, refunds/create, shop/update, themes/create, themes/delete, themes/publish, themes/update, tender_transactions/create, app_purchases_one_time/update, app_subscriptions/update, variants/delete ) )

session_start();

require __DIR__.'/vendor/autoload.php';
use phpish\shopify;

require __DIR__.'/conf.php';

$shopify = shopify\client(SHOPIFY_SHOP, SHOPIFY_APP_API_KEY, SHOPIFY_APP_PASSWORD, true);

try
{
    # Making an API request can throw an exception



    $customers = $shopify('POST /admin/api/2020-01/webhooks.json', array(), array
    (
        'webhook' => array 
        (
            "topic" =>  "customers/login",
            "address" => "myappurl", 
            "format" => "json"
        )

    ));

    print_r($customers);
}
catch (shopify\ApiException $e)
{
    # HTTP status code was >= 400 or response contained the key 'errors'
    echo $e;
    print_R($e->getRequest());
    print_R($e->getResponse());
}
catch (shopify\CurlException $e)
{
    # cURL error
    echo $e;
    print_R($e->getRequest());
    print_R($e->getResponse());
}

请帮忙是否可以从私人应用程序创建它?

通过使用 web-hook,您可以获取由 shopify 本身提供的 shopify 商店上发生的特定事件的数据。

要开始收听此更新,您需要在特定商店上创建 webhook。

但是您需要从shopify提供的列表中选择主题。

Shopify 不为 Customer/Login 事件(或主题)提供 webhook。

如果您想在登录时更新您的系统,您需要创建自定义通知(完全自定义的解决方案)。

为此你可以做的是...

使用 JS 和 Liquid 创建自定义代码,在用户登录时更新您的系统。

您可以使用 App Proxy

通过应用程序执行此操作