RefundLineItems for Refunds with bulk GraphQl

Solved
Highlighted
Shopify Partner
10 0 1

I'm trying to retrieve all Refunded LineItems from an Order using the bulk api.

I understand that when doing it nested directly inside the order  query I get the following error:
"Queries that contain a connection field within a list field are not currently supported."

 

But I also get the same error when querying the refunds directly:

          mutation {
              bulkOperationRunQuery(
                query:"""
                {
                  nodes(ids: ["gid://shopify/Refund/637704896591", "gid://shopify/Refund/637614456911"]) {
                    ... on Refund {
                      id
                      refundLineItems{
                          edges {
                              node{
lineItem{id}
priceSet{shopMoney{amount}}
quantity
subtotalSet{shopMoney{amount}}
totalTaxSet{shopMoney{amount}} } } } } } } """ ) { bulkOperation { id status } userErrors { field message } } }

Shouldn't this return every refund individually with it's refund line items?

 

Thanks,

Norbert

 

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

This is an accepted solution.

Hey @HeartCoding ,

 

As it currently stands with the GraphQL Bulk Query API, you cannot make a query with "nodes" being the top field. As well, you cannot make a query to preform a bulk operation on the orders object using refundLineItems or fulfillments with connections - otherwise you will get the error you are seeing (Queries that contain a connection field within a list field are not currently supported.).

 

Although this isn't currently supported, you should be able to get the desired information from connections available directly on the order object. I put together this query which grabs refund and fulfillment data directly from lineItems and transactions for orders that have financial status of "refunded": 

 

mutation {
  bulkOperationRunQuery(
   query: """
   {
    	orders(query: "financial_status:refunded") {
    edges {
      node {
        id
        totalPriceSet {
          shopMoney {
            amount
          }}
        name
        displayFinancialStatus
        displayFulfillmentStatus
        
        lineItems {
          edges {
            node {
              id
              variant {
                id
              }
              quantity
              fulfillmentStatus
              fulfillableQuantity
              refundableQuantity
            }}}
        transactions {
          id
          kind
          amountSet {
            shopMoney {
              amount
    }}}}}
  }
  }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

Alternatively, you can use this Bulk Query that gets therefundLineItems property from the Refund object QueryRoot instead of the orders object:

mutation {
  bulkOperationRunQuery(
   query: """
   {
  refund(id:"gid://shopify/Refund/63042387990") {
    refundLineItems(first: 10) {
      edges {
        node {
          lineItem{id}
          priceSet{shopMoney{amount}}
          quantity
          subtotalSet{shopMoney{amount}}
          totalTaxSet{shopMoney{amount}}
          
        }
      }
    }
  }
  }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Partner
10 0 1

Hi @hassain,

 

thank you very much for your answer.

I think I will go with your second solution since I already have the Refund IDs.

 

Cheers,

Norbert

0 Likes