Error when attempting to pass Selling Plan Id to draft order via API

Error when attempting to pass Selling Plan Id to draft order via API

AndrewVINSI
Visitor
1 0 0

{'errors': [{'message': 'Variable $input of type DraftOrderInput! was provided invalid value for lineItems.0.selling_plan_id (Field is not defined on DraftOrderLineItemInput)', 'locations': [{'line': 2, 'column': 31}], 'extensions': {'value': {'email': 'test@test.com', 'lineItems': [{'variantId': 'gid://shopify/ProductVariant/1111111111', 'quantity': 2, 'selling_plan_id': 'gid://shopify/SellingPlanGroup/11111111111'}]}, 'problems': [{'path': ['lineItems', 0, 'selling_plan_id'], 'explanation': 'Field is not defined on DraftOrderLineItemInput'}]}}]}

Reply 1 (1)

TheUntechnickle
Shopify Partner
540 65 159

Hey @AndrewVINSI,

This error occurs because the Shopify GraphQL API doesn't support adding selling plans directly to draft orders through the selling_plan_id field on DraftOrderLineItemInput.

 

The Issue

The DraftOrderLineItemInput type doesn't have a selling_plan_id field, which is why you're getting the "Field is not defined" error. This is a limitation of Shopify's draft order API.

 

Solutions

 

Option 1: Create the Draft Order First, Then Convert to Order

  1. Create the draft order without the selling plan
  2. Complete the draft order to convert it to a regular order
  3. Use the Order API to apply selling plans

 

Option 2: Use the Orders API Directly

If possible, bypass draft orders entirely and create orders directly with selling plans:

mutation orderCreate($order: OrderInput!) {
  orderCreate(order: $order) {
    order {
      id
      name
    }
    userErrors {
      field
      message
    }
  }
}

With variables:

{
  "order": {
    "lineItems": [
      {
        "variantId": "gid://shopify/ProductVariant/1111111111",
        "quantity": 2,
        "sellingPlanId": "gid://shopify/SellingPlanGroup/11111111111"
      }
    ],
    "email": "test@test.com"
  }
}

 

Option 3: Use Custom Attributes (Workaround)

As a temporary workaround, you could store the selling plan ID in custom attributes and handle it in your order processing:

{
  "input": {
    "email": "test@test.com",
    "lineItems": [
      {
        "variantId": "gid://shopify/ProductVariant/1111111111",
        "quantity": 2,
        "customAttributes": [
          {
            "key": "selling_plan_id",
            "value": "gid://shopify/SellingPlanGroup/11111111111"
          }
        ]
      }
    ]
  }
}

 

Recommendation

The most straightforward approach is to use the Orders API directly if your use case allows it, as it has proper support for selling plans. If you specifically need draft orders, you'll need to handle the selling plan application as a separate step after order creation.

 

Hope this helps!
Shubham | Untechnickle

Helping for free: hello@untechnickle.com


Don't forget to say thanks, it'll make my day - just send me an email! 


Get Revize for Free | Let your shoppers edit orders post-purchase | Get Zero Support Tickets | #1 Order Editing + Upsell App