FROM CACHE - en_header

GraphQL, how to get multiple customer based on their ID

user7856
Tourist
7 0 3

Hi, I want to get data of customers with ID. I see an example like below code but its same code repeting multiple time, is there any way to call like `Customers(ids: [graphqlid, graphqqlid]){ ...}`

customer1: customer(id:"gid://shopify/Customer/1310260264982") {
displayName
}
customer2: customer(id:"gid://shopify/Customer/1310260789270") {
displayName
}
customer3: customer(id: "gid://shopify/Customer/1310260854806") {
displayName
}
}
 

Replies 4 (4)
Paul_vd_Dool
Shopify Partner
85 6 75

Hi,

In case you still have this issue or anybody else is looking for the proper answer, here it goes.

You can query multiple id's like this:

```

{
nodes( ids: [ "gid://shopify/Customer/3781894373511", "gid://shopify/Customer/3903388090503", "gid://shopify/Customer/3903390777479" ] ) {
...on Customer {
displayName
}
}
}
```

Doppelganger - Managing duplicate user accounts
Paul_vd_Dool
Shopify Partner
85 6 75

Hi,

In case you still have this issue or anybody else is looking for the proper answer, here it goes.

You can query multiple id's like this:

{
  nodes( ids: [ "gid://shopify/Customer/3781894373511", "gid://shopify/Customer/3903388090503", "gid://shopify/Customer/3903390777479" ] ) {
    ...on Customer {
      displayName
    }
  }
}


Hope this helps.

Paul

Doppelganger - Managing duplicate user accounts
Thalia-Yotpo
Tourist
3 0 1

Hi @Paul_vd_Dool !

 

Thank you for the example you had provided - are you able to provide a second example that passes the array of IDs as variables? 

 

We are trying to switch from your REST API GET /customers call, which we filter by IDs - 

https://shopify.dev/api/admin-rest/2021-10/resources/customer#[get]/admin/api/2021-10/customers.json

 

To your graphQL customers query, and are facing some difficulties in incorporating variables with nodes.

 

Any idea how we can achieve this?

Thanks!

Paul_vd_Dool
Shopify Partner
85 6 75

Hi @Thalia-Yotpo ,

I've grabbed an example from my app.

 

 

query getSubCustomers($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on Customer {
      id
      displayName
      email
    }
  }
}

// variables
{
    "ids": [
        "gid://shopify/Customer/987654321",
        "gid://shopify/Customer/123456789"
    ]
}

 

 

I hope this helps.

Doppelganger - Managing duplicate user accounts