Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

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

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

DionCosina
Shopify Partner
11 0 2

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.

Replies 3 (3)

Umiko
Shopify Staff
42 8 14

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

nkls
Visitor
2 0 1

Hi @Umiko,

 

thanks for your explanation. I'm still not absolutely sure how to handle this. I'm in the same position as @DionCosina right now. I'm looking for a way to create order through the Shopify API without creating new products.

 

Is there any way to do this using simple JSON requests?

 

Kind regards,

Niklas

seckley
Shopify Partner
2 0 0

I am also trying to do something similar. I am also looking for a flow of how an order is created and what needs to happen to make it all the way through to payment using the shopify payment system.