Skip to content

Instantly share code, notes, and snippets.

@zsy715
Last active June 4, 2021 17:10
Show Gist options
  • Save zsy715/e86866c24fac0ccc120f6462a77630e9 to your computer and use it in GitHub Desktop.
Save zsy715/e86866c24fac0ccc120f6462a77630e9 to your computer and use it in GitHub Desktop.

create plan with product


curl -X POST http://localhost:3000/graphql_extension -H "authorization: #{token}" -d 'query=
mutation {
  sellingPlanGroupCreate(
    input: {
      name: "Bill monthly"
      merchantCode: "bill-monthly"
      options: ["Delivery every"]
      position: 1
      sellingPlansToCreate: [
        {
          name: "Delivered every month"
          options: "1 Month(s)"
          position: 1
          billingPolicy: { recurring: { interval: MONTH, intervalCount: 1, anchors: [{type: MONTHDAY, day: 2}] } }
          deliveryPolicy: { recurring: { interval: MONTH, intervalCount: 1, anchors: [{type: MONTHDAY, day: 2}] } }
          pricingPolicies: [
            {
              fixed: {
                adjustmentType: PERCENTAGE
                adjustmentValue: { percentage: 15.0 }
              }
            }
          ]
        }
      ]
    }
    resources: { productIds: ["gid://shopify/Product/6211635085506"], productVariantIds: [] }
  ) {
    sellingPlanGroup{
      id
      name
    }
    userErrors {
      field
      message
    }
  }
}'

Add product to plan

curl -X POST \
  "http://localhost:3000/graphql_extension" \
  -H "authorization: #{token}"  \
  -d 'query=mutation {
      sellingPlanGroupAddProducts(
        id: "gid://shopify/SellingPlanGroup/60391618"
        productIds: ["gid://shopify/Product/6211635085506"]
      ) {
        sellingPlanGroup{id name}
        userErrors {
          field
          message
        }
      }
    }' 

Remove product from plan

curl -X POST http://localhost:3000/graphql_extension -H "authorization: #{token}" -d 'query=
mutation {
      sellingPlanGroupRemoveProducts(
        id: "gid://shopify/SellingPlanGroup/73597122"
        productIds: ["gid://shopify/Product/6211635085506"]
      ) {
        removedProductIds
        userErrors {
          field
          message
        }
      }
    }'

Update selling plan

curl -X POST http://localhost:3000/graphql_extension -H "authorization: #{token}" -d 'query=
mutation {
  sellingPlanGroupUpdate(
    input: {
      name: "Bill monthly"
      merchantCode: "bill-monthly"
    }
    id: "gid://shopify/SellingPlanGroup/95060162"
  ) {
    sellingPlanGroup{
      id
      name
    }
    userErrors {
      field
      message
    }
  }
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment