Paginated returns with GraphQL API

Solved

Paginated returns with GraphQL API

Tokuhn
Shopify Partner
5 0 0

Hi,

I want to display the list of returns for a store in a table with pagination control. As I understand, this requires using the Shopify GraphQL API to get returns.

I know returns can be queried under orders, simple example (I've omitted the cursor controls for simplicity):

 

{
   orders (first:10) {
      edges {
         node {
            id
            returns (first:10) {
               edges {
                  node {
                     id
                  }
               }
            }
         }
      }
   }
}

 

But I want to display say 10 returns per paginated page and not every order has a return.

How do I add the condition that only orders that have at least 1 return line item should be returned in the query response?

Furthermore, since it seems that it is possible that an order can have more than 1 return, how can I ensure that for each GraphQL query I get exactly 10 return line items (assuming that there is another page of returns after the current cursor, the last page of course could have fewer items than the page size).

Accepted Solution (1)
Eric-HAN
Shopify Partner
106 15 9

This is an accepted solution.

Hi, Tokuhn

 

return_status  I think  this field you also could check to filter.

EricHAN_0-1718586375591.png

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee

View solution in original post

Replies 6 (6)

Eric-HAN
Shopify Partner
106 15 9

HI, there 

I think you could filter all the order which has return.   and then go on your logic. what do you think?

you could refer the GraphQL below:

{
   orders (first:10,query: "financial_status:refunded") {
      edges {
         node {
            id
            
         }
      }
   }
}
- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Tokuhn
Shopify Partner
5 0 0

Hi Eric-Han,

Thanks very much for your reply. That is helpful.

I added partially_refunded to the query and that is working, i.e.
query: "financial_status:refunded,partially_refunded"

I need to also get returns that are in progress though. This status does not appear in the list for financial_status likely since it applies to the return and not the order.

Any ideas on how to also get the returns that are in progress? I need to get all types of returns

Eric-HAN
Shopify Partner
106 15 9

This is an accepted solution.

Hi, Tokuhn

 

return_status  I think  this field you also could check to filter.

EricHAN_0-1718586375591.png

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Tokuhn
Shopify Partner
5 0 0

Hi Eric-HAN,

I think that provides what I was looking for. The Shopify GraphQL API is a bit strange though as you need to put returnStatus = "IN_PROGRESS" as you highlighted but the API response returns "OPEN" for the return object status instead of "IN_PROGRESS".

Thanks very much for your help with this!

WKS
Shopify Partner
5 0 0

hi Tokuhn, 

can you please share with me the structure of the query. 

 

thank you in advance. 

Tokuhn
Shopify Partner
5 0 0

Hi WKS,

The general query is of this form:

{
  orders(first: 10, query: "returnStatus:IN_PROGRESS,RETURNED") {
    nodes {
      returns(first: 10) {
        nodes {
          id
          status
        }
      }
    }
    pageInfo {
          hasNextPage
          endCursor
    }
  }
}


You can add/change other return statuses as needed.