首页 > 解决方案 > 如何使用 Shopify API 创建结帐

问题描述

通过 Postman,我根据 Shopify 文档的此页面将 GraphQL 发送到适当的端点:使用 Storefront API 创建结帐。我收到以下回复:

{
    "errors": "[API] This action requires merchant approval for write_checkouts scope."
}

这对我来说没有意义,因为我已经启用了结帐权限,如下所示: 在此处输入图像描述

如果应用程序需要转换为销售渠道或公共应用程序,请告诉我如何完成。谢谢你的帮助!

标签: shopifyshopify-appshopify-api

解决方案


我不相信私人或自定义应用程序可以做到这一点。您的应用必须是公开的。这里的一些附加信息: https ://community.shopify.com/c/shopify-apis-and-sdks/how-to-grant-write-checkouts-permission/td-p/448587

以下链接的要求部分提到您的应用必须是公开的: https ://shopify.dev/apps/channels/getting-started

再三考虑,StoreFront API 有 createCart: https ://shopify.dev/custom-storefronts/cart#create-a-cart-and-add-a-line-item

我创建了一个私人应用程序并使用了以下内容:

帖子:https://[storename].myshopify.com/api/2021-10/graphql.json

添加标题:X-Shopify-Storefront-Access-Token:somevalue

设置主体:

mutation MyMutation1 {
   
  cartCreate(input: {lines: {merchandiseId: "someproducytid==",quantity:1}, buyerIdentity: {email: "test@test.com"}}) {
    cart {
      id
      checkoutUrl
      buyerIdentity {
        customer {
          email
        }
      }
    }
  }

}

推荐阅读