FROM CACHE - en_header

draftOrderCreate graphQL mutation failing suddenly

arnarfs
New Member
3 0 0

Hi, 

Today The draftOrderCreate method started failing suddenly on a store I manage. The endpoint that is calling the mutation on my hand hasn't been modified for months and neither has the website. 

Below I'll show you the mutation, input and output I'm receiving.

Mutation: 

mutation($input: DraftOrderInput!, $lineItemsFirst: Int, $metafieldsFirst: Int) {
    draftOrderCreate(input: $input) {
        draftOrder {
            ...draftOrder
            lineItems(first: $lineItemsFirst) {
                edges {
                    node {
                        ...lineItem
                        discountedTotal
                        appliedDiscount {
                            title
                            amountV2 {
                                amount
                                currencyCode
                            }
                            value
                            valueType
                        }
                    }
                }
                pageInfo {
                    hasNextPage
                    hasPreviousPage
                }
            }
        }
        
    }
}

 

Here's the input/output:

input:
{
  'lineItemsFirst': 50,
  'metafieldsFirst': 8,
  'input': {
    'lineItems': [{
      'variantId': 'gid://shopify/ProductVariant/26139281883200',
      'quantity': 1,
      'sku': '61514'
    }]
  }
}

output:
{
  'draftOrderCreate': {
     'draftOrder': None
  }
}

 

Any ideas on what might be wrong? I've been looking into this for a few hours but I have no idea why it's happening

Replies 11 (11)
Greg_Kujawa
Shopify Partner
1023 84 266

You declare the metafieldsFirst variable, but don't use it later on. When I tried this in my GraphiQL app that's what kicked back as an error. When I tried the GQL request below it worked fine.

mutation ($input: DraftOrderInput!, $lineItemsFirst: Int) {
  draftOrderCreate(input: $input) {
    draftOrder {
      lineItems(first: $lineItemsFirst) {
        edges {
          node {
            discountedTotal
            appliedDiscount {
              title
              amountV2 {
                amount
                currencyCode
              }
              value
              valueType
            }
          }
        }
        pageInfo {
          hasNextPage
          hasPreviousPage
        }
      }
    }
  }
}

 

with the query variables

 

{
  "lineItemsFirst": 50,
  "input": {
    "lineItems": [{
      "variantId": "gid://shopify/ProductVariant/31620852416564",
      "quantity": 1,
      "sku": "61514"
    }]
  }
}
dev_wine
New Member
1 0 0

we're receiving the same error! suddenly out of nowhere all our orders started failing since draft orders were not getting create on Shopify.

our input parameters are:

{shippingAddress:{zip:"POSTCODE",phone:"+4412345678",lastName:"X",firstName:"X",country:"GB",city:"London",address2:null,address1:"X"},lineItems:[{variantId:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTc4MjM5MTc3NTI2Nw==",quantity:1,appliedDiscount:{valueType:FIXED_AMOUNT,value:2.26,title:"Discount",amount:"2.26"}},{variantId:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTYxNDg1MjMwMDgzNQ==",quantity:1,appliedDiscount:{valueType:FIXED_AMOUNT,value:2.700000000000001,title:"Discount",amount:"2.700000000000001"}},{variantId:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMjA0NTUzNTIzMjAzNQ==",quantity:1,appliedDiscount:{valueType:FIXED_AMOUNT,value:2.0,title:"Discount",amount:"2.0"}},{variantId:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTYxNDg0OTQ1MDAxOQ==",quantity:1,appliedDiscount:{valueType:FIXED_AMOUNT,value:2.5,title:"Discount",amount:"2.5"}}],billingAddress:{zip:"POSTCODE",phone:"+4412345678",lastName:"X",firstName:"X",country:"GB",city:"London",address2:null,address1:"X"},email:"email@provider.com"}

the graphql requst is:

draftOrderCreate(input: #{input}) {
          userErrors {
            field
            message
          }
          draftOrder {
            id
            totalPrice
            totalShippingPrice
            totalTax
            subtotalPrice
            lineItems(first: 250) {
              edges {
                node {
                  id
                  quantity
                  variant {
                    id
                  }
                }
              }
            }
          }
        }

And the response is:

     "data" => %{
       "draftOrderCreate" => %{
         "draftOrder" => nil,
         "userErrors" => [
           %{"field" => nil, "message" => "Invalid input arguments."}
         ]
       }
     },
     "extensions" => %{
       "cost" => %{
         "actualQueryCost" => 10,
         "requestedQueryCost" => 10,
         "throttleStatus" => %{
           "currentlyAvailable" => 990,
           "maximumAvailable" => 1.0e3,
           "restoreRate" => 50.0
         }
       }
     }
   },

 
it suddenly happened today around 4/5PM GMT+1 (London time). we haven't changed/touched this since 2019.

What is going on? We have a live app and it's crucial for us to get this fixed. We spoke to the support but they haven't come back to us with a solution just yet

arnarfs
New Member
3 0 0

That's around the same time this started failing for us. Something has changed at that time because everything was working fine before that. One from our business team noticed this issue at around 5:30 GMT

arnarfs
New Member
3 0 0

what do you mean don't use it later on?

The full mutation is as follows, (I left the fragments out in my former post)

mutation($input: DraftOrderInput!, $lineItemsFirst: Int, $metafieldsFirst: Int) {
    draftOrderCreate(input: $input) {
        draftOrder {
            ...draftOrder
            lineItems(first: $lineItemsFirst) {
                edges {
                    node {
                        ...lineItem
                        discountedTotal
                        appliedDiscount {
                            title
                            amountV2 {
                                amount
                                currencyCode
                            }
                            value
                            valueType
                        }
                    }
                }
                pageInfo {
                    hasNextPage
                    hasPreviousPage
                }
            }
        }
        
    }
} fragment draftOrder on DraftOrder {
          id
          totalPrice
          totalTax
          subtotalPrice
          status
    } fragment lineItem on DraftOrderLineItem {
        id
        title
        quantity
        customAttributes {
          key
          value
        }
        product {   
            id
            title 
            handle
            descriptionHtml
            description
        }
        variant {
            ...variant
        }
      } fragment variant on ProductVariant {
          id
          title
          price
          sku
          compareAtPrice
          createdAt
          requiresShipping
          updatedAt
          weight
          weightUnit
          selectedOptions {
            name
            value
          }
          image {
              id
              originalSrc
              transformedSrc
              altText
          }
          metafields(first: $metafieldsFirst) {
                edges {
                    node {
                        key
                        value
                    }
                }
          }
    }

 

The query I'm using has been working for a long while now and as another comment below stated it stopped working for them at the same time.

This shouldn't be a code issue since it has worked for a while now

Greg_Kujawa
Shopify Partner
1023 84 266

Yes, it does sound like a more global issue seeing that multiple API consumers ran into the issue right around the same time. With untouched code that hasn't been modified. Sorry @arnarfs , I didn't originally see your fragments, so I didn't see where the metafieldsFirst variable was coming into play. Now it makes sense! Seeing this appears to be a back-end Shopify GQL handling issue I'm surprised no Shopify staffer has replied as to the current status. 

Flick-Flack
New Member
2 0 0

It seems I am experiencing the same problem when dealing with any mutation using GraphQL. Here the example of the code: 

`mutation productCreate {
  productCreate(input: {title: "title"}) {
    product {
      id
    }
  }
}
`



example of the response: 
`{
    "errors": [
        {
            "message": "Field 'productCreate' doesn't exist on type 'Mutation'",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "mutation productCreate",
                "productCreate"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "Mutation",
                "fieldName": "productCreate"
            }
        }
    ]
}`

It seems like there is some issue with the Shopify API and it doesn`t allow me to do any mutation. 

Greg_Kujawa
Shopify Partner
1023 84 266

@Flick-Flack Strange. Is there a specific API version your are referencing in your URL? When I just tried this using the GraphiQL app on my test shop the call worked fine. See below.

GQL Mutation.jpg

Flick-Flack
New Member
2 0 0

When I use the built-in  GraphiQL app from the test shop everything is working fine. The issue happens when I am trying to do it using my own application with the help of the GraphiQL.
So I have been doing research whether it is possible to create an order in the Shopify with the help of the GraphiQL app. I was able to send requests and get the data.

I don`t why but for some reason, it won`t work when I do it from other application sending the same request in both cases. 

Greg_Kujawa
Shopify Partner
1023 84 266

And if this is regardless of the API version you are referencing in your URL then I'd suggest opening a ticket or something. Although I'm not sure if the support folks wouldn't just point you to this forum. Which hasn't elicited a reply from a Shopify staffer???

Kevin_A
Shopify Staff
Shopify Staff
318 42 60

Hey @arnarfs 

Do you have a recent example of this (preferably within the last 72 hours)? If so can you provide the request ID response header so I can take a look?

Kevin_A | Solutions Engineer @ 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

sivainguva
Tourist
29 0 1

Hi All, I am pretty new to the shopify development , So The Draftorder Api is returning the Null Pointer expection for the Graphql query we are sending to shopify, I need some help on this , PLease guide me.

Here is the graphgl query mutation we are sending 

 

mutation {
draftOrderCreate(draftOrder: {
lineItems: [
#foreach( $lineItem in $lineItems )
{
variantId: "$lineItem.id"
quantity: $lineItem.quantity
}
#end
]
}) {
draftOrder {
id
invoiceUrl
}
userErrors {
field
message
}
}
}

And thats throwing an Null pointer when trying to checkout .