GraphQL not returning customer data

Solved
nidhimongia
Tourist
8 1 2

I am new to GraphQL, need to set up a custom storefront for nonshopify website which will use Shopify as storefront 

Getting error while fetching customer id and Lastname:

Customer query :

 

{

customer {
id
firstName
displayName
}

}

 

Error: 

{
"errors": [
{
"message": "Field 'customer' is missing required arguments: id",
"locations": [
{
"line": 4,
"column": 3
}
],
"path": [
"query",
"customer"
],
"extensions": {
"code": "missingRequiredArguments",
"className": "Field",
"name": "customer",
"arguments": "id"
}
}
]

 

0 Likes
Jayvin
Shopify Partner
217 34 57

Hi,

To retrieve a single customer, you need to use a query like this

{
    customer(id: "gid://shopify/Customer/[ID_OF_CUSTOMER]") {
      email
      firstName
      lastName
      defaultAddress {
        address1
        city
        province
        zip
        country
      }
    }
  }

 

To retrieve multiple customers, you need to query like this:

# Get the first 10 customers
{
  customers(first: 10) {
    edges {
      node {
        id
        displayName
      }
    }
  }
}

 

More info here 

0 Likes
nidhimongia
Tourist
8 1 2
Getting this error while fetching the info
 
message: "Field 'customers' doesn't exist on type 'QueryRoot'"
 
 
 
 
0 Likes
Kevin_A
Shopify Staff
Shopify Staff
315 42 54

Hey @nidhimongia 

Can you grab the x-request-id response header so I can take a look at our logs?

Kevin_A | Developer Support @ 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

0 Likes
nidhimongia
Tourist
8 1 2

Hi Kevin,

 

This is the request 

 

<?php$curl = curl_init();curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://dogpound1.myshopify.com/api/2021-01/graphql.json',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "query": "query { customers {    edges{      node {displayName}    }  }}"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'X-Shopify-Storefront-Access-Token: 41188c26740597cc35126e1880ca94b9',
    'Cookie: _landing_page=%2Fadmin%2Fauth%2Flogin; _orig_referrer=https%3A%2F%2Fdogpound1.myshopify.com%2Fadmin%2Foauth%2Fauthorize%3Fclient_id%3D42243027%26scope%3Dunauthenticated_read_product_listings%2Cunauthenticated_write_checkouts%2Cunauthenticated_write_customers%2Cunauthenticated_read_customer_tags%2Cunauthenticated_read_content%2Cunauthenticated_read_product_tags%26redirect_uri%3Dhttps%3A%2F%2Fwww.google.com%2F%26state%3Dnonce1; _s=c6e26140-ce0a-4f11-9dc7-84713172ed0b; _shopify_fs=2021-02-02T12%3A51%3A13Z; _shopify_s=c6e26140-ce0a-4f11-9dc7-84713172ed0b; _shopify_y=3d089914-3993-45c0-9de5-83b274bf3f81; _y=3d089914-3993-45c0-9de5-83b274bf3f81'
  ),
));$response = curl_exec($curl);curl_close($curl);
echo $response;

0 Likes
Kevin_A
Shopify Staff
Shopify Staff
315 42 54

This is an accepted solution.

Hey @nidhimongia 

Ah you are using the storefront API and not the admin API which is why you are seeing that error. There is no 'customers' object for the storefront API. Please see our docs for more information:

https://shopify.dev/docs/storefront-api/reference/common-objects/queryroot

Kevin_A | Developer Support @ 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

0 Likes
nidhimongia
Tourist
8 1 2

This is an accepted solution.

Thanks, Kevin. I installed the admin version of GraphQL and able to retrieve customer data.

 

0 Likes