Create a order using existing products in my shopify with a api

DionCosina
Shopify Partner
11 0 1

Hi, i want to make a order using json api, but if i want to add products it auto makes a new product. So how do i still make a order using json api but with existing products in my shopify store so i dont have to mannually put all the information.

Reply 1 (1)
Umiko
Shopify Staff
Shopify Staff
42 8 13

Hi @DionCosina 👋

 

Using Admin GraphQL API, we can use the `draftOrderCreate` mutation and pass `ProductVariant.id` as a input variable under line items to load the existing product into the order:

mutation draftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
    }
  }
}

{ // input variables
    "input": {
        "lineItems": [{
            "variantId": "gid://shopify/ProductVariant/12345",
            "quantity": 1
        }]
    }
}

 Then the resulting `DraftOrder.id` can be used with the `draftOrderComplete` mutation to create the order: 

mutation {
  draftOrderComplete(id: "gid://shopify/DraftOrder/67890") {
    draftOrder {
      order{
          id
      }
    }
  }
}

 

Similarly in Admin REST API, we can create a new `DraftOrder` then complete the `DraftOrder` as well. 

 

Hope that helps!

Umiko | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog