Generating dummy orders for development app

Generating dummy orders for development app

PedroFernandes
Shopify Partner
2 0 1

Maybe someone can tell me where I'm messing up. I recently started app development. My goal is pretty simple: - read orders, expenses, sales from my stores (multiple) using shopify api. - read expenses and conversions from Google ads api - read expenses costs from meta api. And aggregate those into total expenses and total sales. I followed the shopify doca on how to create a dummy app to familiarize myself and added it to a new dev store (creates and adds 5 random products). I want my app to be on another domain instead of in the store admin, and then the user would oauth one of their stores. For the mvp this doesn't really matter but would be nice later. So then I tried creating dummy orders using the same logic from the sample app that creates products. I went with the graphql api due to personal preference (v2023 - 01) and saw that creating orders isn't possible. I have to first create draft orders and then complete said orders, ok no problem there I'll just write two queries instead. But then I spent all of yesterday banging my head because of the PurchasingEntity field (specifies if order is B2B or B2C). The purchasingEntity object contains either a customerId or a purchasingCompany and according to their docs, if one is provided the other can be null. No matter what I did I could not successfully create draft orders, much less complete them and then read my dummy data. I can't add this type of app to my live stores because it's a development app and hasn't gone through the shopify review process. I'll be able to jump those hurdles once I comply with the ToS and have it thoroughly tested but for that I need data. I found some plug-ins that claim to provide dummy data but wanted to gather thoughts from others before wasting money for some json. I'm exhausted and reading up on the different app types (public/private/custom) left me more confused. It seems I can't make a custom app public later?

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 501

Hi @PedroFernandes 👋

 

To generate test orders on a partner development store, you will need to use Admin REST API to force-set the order to be valid test orders. I'd recommend reviewing this tutorial on how to manage test orders and the limitations to test orders here.

 

If you're looking to use GraphQL to complete an order from draft, and only need expenses and sales info, you can simply specify only the line items in the draft order input. Since you'll be aggregating expenses, you'll want to use a variant ID below in place of the custom product to capture the product cost:

 

 

mutation ($input: DraftOrderInput!) {
    draftOrderCreate(input: $input) {
        draftOrder {
            id
        }
    }
}
{
    "input": {
        "lineItems": [{
            "title": "Replace this custom product with a variant with an associated cost",
            "originalUnitPrice": 10,
            "quantity": 5
        }]
    }
}

 

 

Then simply complete the draft to mark it as paid manually. Please keep in mind that this workflow will lock the checkout on a partner development store, as this is not considered a valid test order.

 

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

 


Hope that helps!
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

PedroFernandes
Shopify Partner
2 0 1

Thank you for the reply, I can indeed create orders with the rest api but am sticking with graphql for now. I followed the steps outlined here and what you just outlined but I still get 'null' in my response for creating draft orders.

Here is my query object:

PedroFernandes_0-1674665596581.png

 

And here is my loop that creates several draft orders:

PedroFernandes_1-1674665668048.png

 

However notice the query response: 

PedroFernandes_2-1674666041065.png

 




ShopifyDevSup
Shopify Staff
1453 238 501

As I mentioned, using GraphQL to complete the draft order will lock your partner development store checkout. If this order was created in a partner development store, you will need to contact partner support here to help resolve this issue. 

 

Otherwise, if you're creating orders in a live merchant store with GraphQL, I'd recommend trying the same mutation in a curl request instead to rule out any issues with the client:

 

curl -L -X POST 'https://STORE-NAME.myshopify.com/admin/api/2023-01/graphql.json' \
-H 'X-Shopify-Access-Token: ACCESS-TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{"query":"mutation ($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id } } } ","variables":{"input":{"purchasingEntity":{"customerId":"gid://shopify/Customer/123"},"lineItems":[{"variantId":"gid://shopify/ProductVariant/456","quantity":5}]}}}'

 

From my testing, it appears to return the id without issue:

 

 

You can also modify the mutation to surface more details on user error:

 

mutation ($input: DraftOrderInput!) {
    draftOrderCreate(input: $input) {
        draftOrder {
            id
        }
        userErrors {
            message
        }
    }
}
{
    "input": {
        "purchasingEntity": {
            "customerId": "gid://shopify/Customer/123"
        },
        "lineItems": [{
            "variantId": "gid://shopify/ProductVariant/456",
            "quantity": 5
        }]
    }
}

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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