Python ShopifAPI:删除折扣和价格规则

Python ShopifAPI:删除折扣和价格规则,python,shopify,shopify-app,Python,Shopify,Shopify App,我正在使用Shopify Python库处理商店的订单、折扣等。我正在编写一些测试,包括创建和删除价格规则和折扣 def test_get_discount(self): random_number_string = str(randint(0,10000)) price_rule = shopify.PriceRule.create({ 'title': 'TEST-PRICERULE-' + random_number_string, 'ta

我正在使用Shopify Python库处理商店的订单、折扣等。我正在编写一些测试,包括创建和删除价格规则和折扣

def test_get_discount(self):
    random_number_string = str(randint(0,10000)) 
    price_rule = shopify.PriceRule.create({
        'title': 'TEST-PRICERULE-' + random_number_string,
        'target_type': 'line_item',
        'target_selection': 'all',
        'allocation_method': 'across',
        'value_type': 'fixed_amount',
        'value': -1000,
        'once_per_customer': True,
        'customer_selection': 'all',
        'starts_at': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    })
    discount = shopify.DiscountCode.create({
        'price_rule_id': price_rule.id,
        'code': 'TEST-DISCOUNT-' + random_number_string,
        'usage_count': 1,
        'value_type': 'fixed_amount',
        'value': -1000
    })
    fetched_price_rule = shopify_utils.get_discount_codes('TEST-PRICERULE-' + random_number_string)
    self.assertIsNotNone(fetched_price_rule)
    #deleted_discount = discount.destroy()
    #self.assertIsNone(deleted_discount)
    deleted_price_rule = price_rule.delete('discounts')
    self.assertIsNone(deleted_price_rule)
删除之前的所有操作都正常工作。我也可以毫无问题地删除折扣,但当我尝试删除价格规则时,它会出现以下错误:

deleted_price_rule = price_rule.delete()
TypeError: _instance_delete() missing 1 required positional argument: 'method_name'
我相信它是在问我嵌套的资源名,所以我试着传递一些东西,比如
折扣
折扣
,等等,但没有成功。我看到
pyactiveresource
正在使用
method\u name
构建一个url来删除相关资源,只是不知道他们的API是什么样子,因为对于这种情况,它没有很好的文档记录

当我指定了一个(错误的)方法名时,会出现以下错误:

pyactiveresource.connection.ClientError: Response(code=406, body="b''", headers={'Server': 'nginx', 'Date': 'Sun, 10 Sep 2017 00:57:28 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'close', 'X-Sorting-Hat-PodId': '23', 'X-Sorting-Hat-PodId-Cached': '0', 'X-Sorting-Hat-ShopId': '13486411', 'X-Sorting-Hat-Section': 'pod', 'X-Sorting-Hat-ShopId-Cached': '0', 'Referrer-Policy': 'origin-when-cross-origin', 'X-Frame-Options': 'DENY', 'X-ShopId': '13486411', 'X-ShardId': '23', 'X-Shopify-Shop-Api-Call-Limit': '3/40', 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT': '3/40', 'X-Stats-UserId': '0', 'X-Stats-ApiClientId': '1807529', 'X-Stats-ApiPermissionId': '62125531', 'Strict-Transport-Security': 'max-age=7776000', 'Content-Security-Policy': "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://maps.googleapis.com https://stats.g.doubleclick.net https://www.google-analytics.com https://visitors.shopify.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=error_404&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Ferrors&source%5Bsection%5D=admin_api&source%5Buuid%5D=72550a71-d55b-4fb2-961f-f0447c1d04c6", 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'X-XSS-Protection': '1; mode=block; report=/xss-report?source%5Baction%5D=error_404&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Ferrors&source%5Bsection%5D=admin_api&source%5Buuid%5D=72550a71-d55b-4fb2-961f-f0447c1d04c6', 'X-Dc': 'ash,chi2', 'X-Request-ID': '72550a71-d55b-4fb2-961f-f0447c1d04c6'}, msg="Not Acceptable") 

非常感谢任何想法

正如@Tim在他的回复中提到的,销毁方法对我有效,成功地删除了所有子实例和父实例

我在api上达到了顶峰。并查看了github中的单元测试。我猜您需要向delete方法传递一个id(如果create向price\u规则对象添加了一个id),或者使用destroy方法。谢谢@Tim!id不起作用,但销毁方法起作用了!我可以发誓我试过了,我猜不是:)