customer query
The customer
query returns information about the logged-in customer, store credit history and customer's wishlist.
To retrieve information about a customer, we recommend you use customer tokens in the header of your GraphQL calls. However, you also can use session authentication.
Syntax
{customer: {Customer}}
Reference
The customer
reference provides detailed information about the types and fields defined in this query.
Example usage
Retrieve basic information about the logged-in customer
The following call returns information about the logged-in customer. Provide the customer's token in the header section of the query.
Request:
Copied to your clipboard{customer {firstnamelastnamesuffixaddresses {firstnamelastnamestreetcityregion {region_coderegion}postcodecountry_codetelephone}}}
Response:
Copied to your clipboard{"data": {"customer": {"firstname": "John","lastname": "Doe","suffix": null,"email": "jdoe@example.com","addresses": [{"firstname": "John","lastname": "Doe","street": ["123 Elm Street"],"city": "Anytown","region": {"region_code": "MI","region": "Michigan"},"postcode": "78758","country_code": "US","telephone": "512 555-1212"}]}}}
Retrieve custom attributes metadata from a customer
The following call returns custom attributes for the logged-in customer. Provide the customer's token in the header section of the query.
Request:
Copied to your clipboard{customer {firstnamelastnamesuffixcustom_attributes {code... on AttributeValue {value}... on AttributeSelectedOptions {selected_options {labelvalue}}}}}
Response:
Copied to your clipboard{"data": {"customer": {"firstname": "John","lastname": "Doe","suffix": null,"email": "jdoe@example.com","custom_attributes": [{"code": "reward_update_notification","value": "0"},{"code": "studies","selected_options": [{"label": "BSc","value": "501"},{"label": "MBA","value": "502"}]}]}}}
Retrieve custom attributes metadata from a customer address
The following call returns the customer address custom attributes for the logged-in customer. Provide the customer's token in the header section of the query.
Request:
Copied to your clipboard{customer {addresses {citycustom_attributesV2 {code... on AttributeValue {value}... on AttributeSelectedOptions {selected_options {labelvalue}}}}}}
Response:
Copied to your clipboard{"data": {"customer": {"email": "jdoe@example.com","addresses": [{"city": "Marseille","custom_attributesV2": [{"code": "neighbourhood","value": "St Barnabé"},{"code": "services","selected_options": [{"label": "hospital","value": "507"},{"label": "police","value": "508"}]}]}]}}}
Retrieve custom attributes metadata filtered by code
The following call returns the customer and customer address custom attributes for the logged-in customer filtered by code
. Provide the customer's token in the header section of the query.
Request:
Copied to your clipboard{customer {custom_attributes(attributeCodes: ["studies"]) {code... on AttributeValue {value}... on AttributeSelectedOptions {selected_options {labelvalue}}}addresses {citycustom_attributesV2(attributeCodes: ["services"]) {code... on AttributeValue {value}... on AttributeSelectedOptions {selected_options {labelvalue}}}}}}
Response:
Copied to your clipboard{"data": {"customer": {"email": "jdoe@example.com","custom_attributes": [{"code": "studies","selected_options": [{"label": "BSc","value": "501"},{"label": "MBA","value": "502"}]}],"addresses": [{"city": "Marseille","custom_attributesV2": [{"code": "services","selected_options": [{"label": "hospital","value": "507"},{"label": "police","value": "508"}]}]}]}}}
Retrieve a summary of the customer's order history
The following example returns a summary of the logged-in customer's previous orders.
Request:
Copied to your clipboardquery {customer {orders(pageSize: 20) {items {idorder_datetotal {grand_total {valuecurrency}}status}}}}
Response:
Copied to your clipboard{"data": {"customer": {"orders": {"items": [{"id": "MQ==","order_date": "2020-03-18 17:25:20","total": {"grand_total": {"value": 36.39,"currency": "USD"}},"status": "Complete"},{"id": "Mg==","order_date": "2020-03-18 17:25:20","total": {"grand_total": {"value": 39.64,"currency": "USD"}},"status": "Closed"},{"id": "Mw==","order_date": "2020-03-21 22:41:38","total": {"grand_total": {"value": 205.68,"currency": "USD"}},"status": "Pending"},{"id": "NA==","order_date": "2020-08-03 02:35:35","total": {"grand_total": {"value": 159.13,"currency": "USD"}},"status": "Complete"},{"id": "NQ==","order_date": "2020-09-08 03:57:11","total": {"grand_total": {"value": 132.57,"currency": "USD"}},"status": "Complete"}]}}}}
Retrieve orders based on scope argument:
The following query returns all customer orders, across all store view codes. The value of GLOBAL in the scope field overrides the store view code specified in the Store header.
Request:
Copied to your clipboard{customer {orders(pageSize: 20,scope: GLOBAL) {items {idorder_numberorder_datetotal {grand_total{ value currency }}status}}}}
Response:
Copied to your clipboard{"data": {"customer": {"orders": {"items": [{"id": "ODg=","order_number": "48000000001","order_date": "2022-07-27 18:01:38","total": {"grand_total": {"value": 15,"currency": "USD"}},"status": "Pending"}]}}}}
Retrieve detailed information about a specific order
The following example returns details about one of the customer's previous orders.
These topics contain examples with fragments and provide even more details:
- CreditMemoItemInterface attributes and implementations
- InvoiceItemInterface attributes and implementations
- OrderItemInterface attributes and implementations
- ShipmentItemInterface attributes and implementations
Request:
Copied to your clipboard{customer {orders(filter: {number: {eq: "000000001"}}) {total_countitems {idnumberorder_datestatusitems {product_nameproduct_skuproduct_url_keyproduct_sale_price {valuecurrency}quantity_orderedquantity_invoicedquantity_shippedeligible_for_return}carriershipments {idnumberitems {product_namequantity_shipped}}total {base_grand_total {valuecurrency}grand_total {valuecurrency}total_tax {value}subtotal {valuecurrency}taxes {amount {valuecurrency}titlerate}total_shipping {value}shipping_handling {amount_including_tax {value}amount_excluding_tax {value}total_amount {value}taxes {amount {value}titlerate}}discounts {amount {valuecurrency}label}}}}}}
Response:
Copied to your clipboard{"data": {"customer": {"orders": {"total_count": 1,"items": [{"id": "MQ==","number": "000000001","order_date": "2020-11-14 22:25:48","status": "Processing","items": [{"product_name": "Iris Workout Top","product_sku": "WS03-XS-Red","product_url_key": "iris-workout-top","product_sale_price": {"value": 29,"currency": "USD"},"quantity_ordered": 1,"quantity_invoiced": 1,"quantity_shipped": 1,"eligible_for_return": true}],"carrier": "Flat Rate","shipments": [{"id": "MDAwMDAwMDAx","number": "000000001","items": [{"product_name": "Iris Workout Top","quantity_shipped": 1}]}],"total": {"base_grand_total": {"value": 36.39,"currency": "USD"},"grand_total": {"value": 36.39,"currency": "USD"},"total_tax": {"value": 2.39},"subtotal": {"value": 29,"currency": "USD"},"taxes": [{"amount": {"value": 2.39,"currency": "USD"},"title": "US-MI-*-Rate 1","rate": 8.25}],"total_shipping": {"value": 5},"shipping_handling": {"amount_including_tax": {"value": 5},"amount_excluding_tax": {"value": 5},"total_amount": {"value": 5},"taxes": []},"discounts": []}}]}}}}
Retrieve the store credit history
The following example returns the store credit history for the logged-in user.
Request:
Copied to your clipboardquery {customer {firstnamelastnamestore_credit {enabledbalance_history(pageSize: 10) {items {actionactual_balance {currencyvalue}balance_change {currencyvalue}date_time_changed}page_info {page_sizecurrent_pagetotal_pages}total_count}current_balance {currencyvalue}}}}
Response:
Copied to your clipboard{"data": {"customer": {"firstname": "John","lastname": "Doe","store_credit": {"enabled": true,"balance_history": {"items": [{"action": "Updated","actual_balance": {"currency": "USD","value": 10},"balance_change": {"currency": "USD","value": -100},"date_time_changed": "2019-07-15 21:47:59"},{"action": "Updated","actual_balance": {"currency": "USD","value": 110},"balance_change": {"currency": "USD","value": 10},"date_time_changed": "2019-07-15 21:47:18"},{"action": "Created","actual_balance": {"currency": "USD","value": 100},"balance_change": {"currency": "USD","value": 100},"date_time_changed": "2019-07-15 16:31:05"}],"page_info": {"page_size": 10,"current_page": 1,"total_pages": 1},"total_count": 3},"current_balance": {"currency": "USD","value": 10}}}}}
Retrieve the customer's wish list
The following query returns the customer's wish lists. Adobe Commerce allows customers to have multiple wish lists.
Request:
Copied to your clipboard{customer {wishlists {idnameitems_countitems_v2 {items {idproduct {uidnamesku}}}}}}
Response:
Copied to your clipboard{"data": {"customer": {"wishlists": [{"id": "1","name": "Vacation Wants","items_count": 10,"items_v2": {"items": [{"id": "1","product": {"uid": "MTM=","name": "Overnight Duffle","sku": "24-WB07"}},{"id": "2","product": {"uid": "MTA=","name": "Savvy Shoulder Tote","sku": "24-WB05"}},{"id": "3","product": {"uid": "MTE=","name": "Endeavor Daytrip Backpack","sku": "24-WB06"}},{"id": "4","product": {"uid": "MTA5OA==","name": "Miko Pullover Hoodie","sku": "WH04"}},{"id": "5","product": {"uid": "MTIyNg==","name": "Stellar Solar Jacket","sku": "WJ01"}},{"id": "6","product": {"uid": "MTcyMg==","name": "Nora Practice Tank","sku": "WT03"}},{"id": "7","product": {"uid": "MTY5MA==","name": "Bella Tank","sku": "WT01"}},{"id": "17","product": {"uid": "MTg=","name": "Pursuit Lumaflex™ Tone Band","sku": "24-UG02"}},{"id": "18","product": {"uid": "MQ==","name": "Joust Duffle Bag","sku": "24-MB01"}},{"id": "20","product": {"uid": "NTI=","name": "Sprite Yoga Companion Kit","sku": "24-WG080"}}]}},{"id": "2","name": "Lose the Muffintop","items_count": 5,"items_v2": {"items": [{"id": "8","product": {"uid": "NDk=","name": "Advanced Pilates & Yoga (Strength)","sku": "240-LV08"}},{"id": "10","product": {"uid": "MTQ1MA==","name": "Layla Tee","sku": "WS04"}},{"id": "11","product": {"uid": "MTU2Mg==","name": "Radiant Tee","sku": "WS12"}},{"id": "12","product": {"uid": "MTYxMA==","name": "Electra Bra Top","sku": "WB01"}},{"id": "13","product": {"uid": "MTY0Mg==","name": "Celeste Sports Bra","sku": "WB03"}}]}}]}}}
List a company user's purchase orders
The following example returns information about all purchase orders the company user has made since January 1, 2023.
The Purchase orders topic contains additional examples that query purchase order functionality.
Request:
Copied to your clipboard{customer {purchase_orders(currentPage: 1,pageSize: 20,filter: {created_date: {from: "2023-01-21 00:00:00"}}) {total_countpage_info {current_pagepage_sizetotal_pages}items {uidnumberorder {id}created_atupdated_atcreated_by {firstnamelastname}statusorder {total {grand_total {valuecurrency}}}}}}}
Response:
Copied to your clipboard{"data": {"customer": {"purchase_orders": {"total_count": 2,"page_info": {"current_page": 1,"page_size": 20,"total_pages": 1},"items": [{"uid": "MTE=","number": "000000011","order": null,"created_at": "2023-02-01 18:01:40","updated_at": "2023-02-01 18:01:40","created_by": {"firstname": "John","lastname": "Doe"},"status": "PENDING"},{"uid": "MTA=","number": "000000010","order": null,"created_at": "2023-01-31 20:46:16","updated_at": "2023-01-31 21:10:38","created_by": {"firstname": "John","lastname": "Doe"},"status": "REJECTED"}]}}}}
List purchase order approval rules
The following example returns the list of purchase order approval rules.
The Purchase order approval rules topic contains additional examples that query approval rule functionality.
Request:
Copied to your clipboard{customer {purchase_order_approval_rules {items {nameuid}page_info {page_sizecurrent_pagetotal_pages}total_count}}}
Response:
Copied to your clipboard{"data": {"customer": {"purchase_order_approval_rules": {"items": [{"name": "Autoapprove order","uid": "OQ=="},{"name": "Over 10 SKUs","uid": "Ng=="},{"name": "Purchase order over $1000","uid": "NQ=="}],"page_info": {"page_size": 20,"current_page": 1,"total_pages": 1},"total_count": 3}}}}
Related topics
- isEmailAvailable query
- generateCustomerToken mutation
- createCustomerV2 mutation
- createCustomerAddress mutation