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

{‘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’: [email removed] ‘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’}]}}]}

1 Like

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 Order1. Create the draft order without the selling plan

  1. Complete the draft order to convert it to a regular order
  2. 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

1 Like