How i can create draft order using GraphQL API

Topic summary

A developer is building a public app and needs help creating draft orders with modified line item prices using Shopify’s GraphQL API. They shared incomplete mutation code attempting to use draftOrderCreate with various parameters including discounts, custom attributes, and shipping details.

Solution Provided:

Shopify support explained how to modify line item prices using the DraftOrderLineItemInput.appliedDiscount parameter. They provided a working example mutation that:

  • Applies a fixed amount discount ($5.00) to a line item
  • Returns the original price, discounted price, and applied discount details
  • Successfully demonstrates the discount being applied in the response

Key Technical Details:

  • Use appliedDiscount with fields: amount, description, title, value, and valueType (set to FIXED_AMOUNT)
  • The mutation returns both originalUnitPrice and discountedUnitPrice to verify the price modification
  • Include purchasingEntity with customerId to associate the draft order with a customer

The issue appears resolved with a functional code example provided.

Summarized with AI on November 24. AI used: claude-sonnet-4-5-20250929.

Hello
I am working on public app and i want to create draft order with change item price with the help of graphql API but not able to figure out how i will do. Please any one let me know complete process of creating draft order by mutation in graphql. below is some example code.

mutation {
		draftOrderCreate(
			input: {
				email: "test@gmail.com"
                lineItems: {
                    appliedDiscount: {
                        amount: 20
                        description: "test des"
                        title : "Test two"
                        value: 10
                        valueType: FIXED_AMOUNT
                    }
                    customAttributes: {
                        key: "payment"
                        value: "partial"
                    }
                    quantity: 2
                    weight : {
                        unit: GRAMS
                        value: 10
                    }
                }
                localizationExtensions: {
                    key: SHIPPING_CREDENTIAL_BR
                    value: "test"
                }
                metafields: {
                    description: "test"
                    key: "orde_id"
                    namespace: "prt"
                    type: "test"
                    value: "drt"

                }
                paymentTerms: {
                    paymentSchedules: {
                        dueAt: "2022-12-17T15:50:00Z"
                        issuedAt: "2022-12-15T15:50:00Z"
                    }
                }
                privateMetafields: {
                    key: "Test"
                    namespace: "dftrt"
                    valueInput: {
                        value: "testd"
                        valueType: STRING
                    }
                }
              purchasingEntity: {
                    customerId: "gid://shopify/Customer/6453791457508"
                    purchasingCompany: {
                       companyContactId: "gid://shopify/companies/63373540"
                       companyId: "gid://shopify/companies/63373540"
                       companyLocationId: "gid://shopify/locations/63570148"
                    }
                  }
                shippingAddress: {
                    address1: "sdsd"
                    address2: "sadsd"
                    city: "karnal"
                    company: "desonomate"
                    country: "India"
                    countryCode: IN
                    firstName: "Vinod"
                    lastName: "Kumar"
                    phone: "+919865326598"
                    province: "Haryana"
                    provinceCode: "HR"
                    zip: "132157"
                  }               
                  shippingLine: {
                    price: 50
                    shippingRateHandle: "FEDS"
                    title: "fedex"
                  }

			}
		) {
			 userErrors {
                field
                message
            }
		}
	}

Hi @vinodk :waving_hand:

You can use the DraftOrderLineItemInput.appliedDiscount parameter to modify the line item price. In my example draftOrderCreate mutation below, a fixed amount discount was applied to a line item:

mutation ($input: DraftOrderInput!) {
    draftOrderCreate(input: $input) {
        draftOrder {
            id
            lineItems (first:5) {
                nodes {
                    id 
                    originalUnitPrice
                    discountedUnitPrice
                    appliedDiscount {
                        amountV2 {
                            amount
                        }
                    }
                }
            }
        }
    }
}

With variables:

{
    "input": {
        "lineItems": [{
            "appliedDiscount": {
                "amount": "5.00",
                "description": "test modify lineitem price",
                "title": "modify lineitem price",
                "value": 5.00,
                "valueType": "FIXED_AMOUNT"
            },
            "variantId": "gid://shopify/ProductVariant/39803484209270",
            "quantity": 1
        }
    ],
        "purchasingEntity":{
            "customerId": "gid://shopify/Customer/5790884724854"
        }
    }
}

The mutation successfully returned the below response where we can see the discount applied:

{
    "data": {
        "draftOrderCreate": {
            "draftOrder": {
                "id": "gid://shopify/DraftOrder/897414987894",
                "lineItems": {
                    "nodes": [{
                         "id": "gid://shopify/DraftOrderLineItem/57463112892534",
                         "originalUnitPrice": "97.87",
                         "discountedUnitPrice": "92.87",
                         "appliedDiscount": {
                             "amountV2": {
                                 "amount": "5.0"
                             }
                         }
                    }]
                }
            }
        }
    }
}

Hope that helps!