Bulk Operation failed with INTERNAL_SERVER_ERROR

nahid
Shopify Partner
5 0 0

When I created a bulk operation from my app for a shop it failed with INTERNAL_SERVER_ERROR if the shop contains orders older than 60 days. Here is my Bulk Operation GraphQL code.

I have also grant access for read_all_orders

API Version: 2022-10

 

mutation {
  bulkOperationRunQuery(
    query: """
      {
      products {
          edges {
          node {
              id
              legacyResourceId
              description
              title
              handle
              vendor
              productType
              onlineStorePreviewUrl
              priceRangeV2 {
              maxVariantPrice {
                  amount
                  currencyCode
              }
              minVariantPrice {
                  amount
                  currencyCode
              }
              }
              totalInventory
              totalVariants
              publishedAt
              status
              images(first: 1) {
              edges {
                  node {
                  id
                  url(transform: { maxWidth: 300, maxHeight: 300 })
                  originalSrc
                  }
              }
              }
          }
          }
      }
    customers {
      edges {
        node {
          id
          legacyResourceId
          firstName
          lastName
          email
          phone
          state
          lastOrder {
            id
            legacyResourceId
          }
          verifiedEmail
          defaultAddress {
            address1
            address2
            city
            company
            country
            firstName
            lastName
            formatted
            formattedArea
            id
            latitude
            longitude
            province
            zip
          }
        }
      }
    }
    orders {
      edges {
        node {
          name
          email
          createdAt
          fulfillable
          displayFulfillmentStatus
          displayFinancialStatus
          fulfillments {
              status
              createdAt
              displayStatus
            }
          id
          legacyResourceId
          customer {
            id
          }
          customerAcceptsMarketing
          cancelledAt
          createdAt
          cancelReason
          confirmed
          currencyCode
          transactions {
              id
              gateway
              kind
              status
              createdAt
          }
          currentSubtotalPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          currentTotalDiscountsSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          currentTotalPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          currentTotalTaxSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          customerLocale
          discountCode
          physicalLocation {
            id
          }
          phone
          paymentGatewayNames
          processedAt
          closed
          closedAt
          app {
            name
            icon {
              id
              altText
              url
            }
          }
          billingAddress {
            address1
            address2
            city
          }
          lineItems {
            edges {
              node {
                id
                currentQuantity
                name
                product {
                  legacyResourceId
                }
                quantity
                requiresShipping
                title
                unfulfilledQuantity
                fulfillmentStatus
                originalTotalSet {
                  presentmentMoney {
                    amount
                    currencyCode
                  }
                  shopMoney {
                    amount
                    currencyCode
                  }
                }
                totalDiscountSet {
                  presentmentMoney {
                    amount
                    currencyCode
                  }
                  shopMoney {
                    amount
                    currencyCode
                  }
                }
                taxLines {
                  priceSet {
                    presentmentMoney {
                      amount
                      currencyCode
                    }
                    shopMoney {
                      amount
                      currencyCode
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
      }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 

there a no X-Request-ID found in my webhook request but here is the request headers

{
  "x-shopify-webhook-id": [
    "f4fe21e6-f96d-4d55-b40e-9affce6a6a1f"
  ],
  "x-shopify-triggered-at": [
    "2023-04-01T06:58:26.160904169Z"
  ],
  "x-shopify-topic": [
    "bulk_operations/finish"
  ],
  "x-shopify-shop-domain": [
    "naims-test-store-10.myshopify.com"
  ],
  "x-shopify-hmac-sha256": [
    "***"
  ],
  "x-shopify-api-version": [
    "2022-10"
  ],
  "content-type": [
    "application/json"
  ],
  "accept-encoding": [
    "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
  ],
  "accept": [
    "*/*"
  ],
  "content-length": [
    "203"
  ],
  "user-agent": [
    "Shopify-Captain-Hook"
  ],
  "host": [
    "***"
  ]
}


Please help me, I can not figure out whats wrong with me.

 

Replies 7 (7)

okur90
Shopify Partner
126 20 17

Hi @nahid 

 

You can modify the GraphQL query to include a filter for orders created within the last 60 days. You can add the `query` parameter along with the `orders` field in your GraphQL query.

 

mutation {
  bulkOperationRunQuery(
    query: """
      {
        ...
        orders(query: "created_at:>now-60d") {
          edges {
            node {

 

so it should avoid the INTERNAL_SERVER_ERROR issue.

Code Slingin, Pixel Wranglin - Laugh it up at onlinex.com.au
nahid
Shopify Partner
5 0 0

Thank you @okur90 for your reply. I have another question, what should I do if I want to fetch all previous orders from the bulk operation?

okur90
Shopify Partner
126 20 17

In this case, you can try to fetch the orders in smaller batches by using date range filters. You can run multiple bulk operations, each with a different date range, to ensure that you're able to fetch all previous orders without encountering server errors.

 

orders(query: "created_at:>now-60d") {
  edges {
    node {

 

orders(query: "created_at:>now-120d created_at:<=now-60d") {
  edges {
    node {

 

Continue with additional batches for older orders as needed, making sure that the date ranges don't overlap.

Code Slingin, Pixel Wranglin - Laugh it up at onlinex.com.au
nahid
Shopify Partner
5 0 0

Thanks again @okur90 for you help, I tried as you said. Here is my Create Bulk Operation GQL code with a custom date range.

mutation {
  bulkOperationRunQuery(
    query: """
      {
    orders(query: "created_at:<=2023-04-02T00:00:00Z created_at>=2023-02-30T00:00:00") {
      edges {
        node {
          name
          email
          createdAt
          fulfillable
          displayFulfillmentStatus
          displayFinancialStatus
          fulfillments {
              status
              createdAt
              displayStatus
            }
          id
          legacyResourceId
          customer {
            id
          }
          customerAcceptsMarketing
          cancelledAt
          createdAt
          cancelReason
          confirmed
          currencyCode
          transactions {
              id
              gateway
              kind
              status
              createdAt
          }
          currentSubtotalPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          currentTotalDiscountsSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          currentTotalPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          currentTotalTaxSet {
            presentmentMoney {
              amount
              currencyCode
            }
            shopMoney {
              amount
              currencyCode
            }
          }
          customerLocale
          discountCode
          physicalLocation {
            id
          }
          phone
          paymentGatewayNames
          processedAt
          closed
          closedAt
          app {
            name
            icon {
              id
              altText
              url
            }
          }
          billingAddress {
            address1
            address2
            city
          }
          lineItems {
            edges {
              node {
                id
                currentQuantity
                name
                product {
                  legacyResourceId
                }
                quantity
                requiresShipping
                title
                unfulfilledQuantity
                fulfillmentStatus
                originalTotalSet {
                  presentmentMoney {
                    amount
                    currencyCode
                  }
                  shopMoney {
                    amount
                    currencyCode
                  }
                }
                totalDiscountSet {
                  presentmentMoney {
                    amount
                    currencyCode
                  }
                  shopMoney {
                    amount
                    currencyCode
                  }
                }
                taxLines {
                  priceSet {
                    presentmentMoney {
                      amount
                      currencyCode
                    }
                    shopMoney {
                      amount
                      currencyCode
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
      }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 X-Request-ID: 3875bd96-558d-4db8-90ba-fb08187acc41

 

But it didn't work for me, then the operation has been failed with `INTERNAL_SERVER_ERROR`. Here is the response of the current bulk operation status

{
    "data": {
        "currentBulkOperation": {
            "id": "gid://shopify/BulkOperation/3001911771442",
            "status": "FAILED",
            "errorCode": "INTERNAL_SERVER_ERROR",
            "createdAt": "2023-04-02T09:31:27Z",
            "completedAt": null,
            "objectCount": "39",
            "fileSize": null,
            "url": null,
            "partialDataUrl": null
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 1,
            "actualQueryCost": 1,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 999,
                "restoreRate": 50.0
            }
        }
    }
}

 

Could you please give me any solution? Thank you

okur90
Shopify Partner
126 20 17

@nahid there is a typo in the custom date range for the 'created_at' field in the query.

It should be "created_at:<=2023-04-02T00:00:00Z created_at:>=2023-02-28T00:00:00Z".

 

The date "2023-02-30" does not exist, can you update the query and try it again.

Code Slingin, Pixel Wranglin - Laugh it up at onlinex.com.au
nahid
Shopify Partner
5 0 0

@okur90 thanks for your quick response, I just tried with the given params, but failed again.

 
orders(query: "created_at:<=2023-04-02T00:00:00Z created_at>=2023-02-28T00:00:00")
gcree
Visitor
2 0 0

@nahid Try formatting your date filter query like this:

"created_at:>='2023-02-28T00:00:00Z' AND created_at:<'2023-04-02T00:00:00Z'"

 The key is to make sure that both your timestamps end with a 'Z' and also to wrap your timestamps in single quotes ('). You also need the 'AND' keyword between your two date filters.