使用Shopify API创建折扣代码?

使用Shopify API创建折扣代码?,shopify,Shopify,我目前正在尝试确定是否有办法通过shopify API添加折扣代码 我在去年发现了这个问题,当时无法通过API实现,但可以通过自定义脚本实现(如果可能的话,我希望避免这种黑客行为): 根据这篇文章,这应该是一个即将推出的功能: 这个API功能现在可用了吗?它还在开发中还是完全被放弃了?Shopify提供了一个免费的应用程序来制作和管理折扣代码。安装并使用它,因为它和用脚本编写代码一样好 对于所有来到这里的人,Shopify最近开发了一个端点来创建折扣代码和价格规则 否。该API不可公开获取

我目前正在尝试确定是否有办法通过shopify API添加折扣代码

我在去年发现了这个问题,当时无法通过API实现,但可以通过自定义脚本实现(如果可能的话,我希望避免这种黑客行为):

根据这篇文章,这应该是一个即将推出的功能:


这个API功能现在可用了吗?它还在开发中还是完全被放弃了?

Shopify提供了一个免费的应用程序来制作和管理折扣代码。安装并使用它,因为它和用脚本编写代码一样好

对于所有来到这里的人,Shopify最近开发了一个端点来创建折扣代码和价格规则


否。该API不可公开获取可能的副本
$shop = ShopifyApp::shop();

    if( $shopSettings->discount_id == '' || $shopSettings->discount_id == null || $shopSettings->discount_id == undefined ) {

        $price_rule = $shop->api()->rest(
            'POST',
            '/admin/price_rules.json',
            [
                "price_rule" => [
                    "title" => "SUMMERSALE10OFF",
                    "target_type" => "line_item",
                    "target_selection" => "all",
                    "allocation_method" => "across",
                    "value_type" => "percentage",
                    "value" => "-"+request('discount_percentage'),
                    "customer_selection" => "all",
                    "starts_at" => "2017-01-19T17:59:10Z"
                ]
            ]
        );

        $shopSettings->price_rule_id = $price_rule->body->price_rule->id;

        $discount_code = $shop->api()->rest(
            'POST',
            '/admin/price_rules/'.$price_rule->body->price_rule->id.'/discount_codes.json',
            [
                "discount_code" => [
                    "code" => $price_rule->body->price_rule->title
                ]
            ]
        );

        $shopSettings->discount_id = $discount_code->body->discount_code->id;

    } else if( request('discount_percentage') && request('discount_type') == "percentage" ) {

        $price_rule = $shop->api()->rest(
            'POST',
            '/admin/price_rules/'.$shopSettings->price_rule_id.'.json',
            [
                "price_rule" => [
                    "value" => "-"+request('discount_percentage')
                ]
            ]
        );

    }