Skip to content

Get Customer Addresses

Retrieve all saved addresses for the authenticated customer. Addresses are used for billing and shipping during checkout, and can be managed from the customer's account dashboard.

Query

graphql
query getCustomerAddresses($first: Int, $after: String) {
  getCustomerAddresses(first: $first, after: $after) {
    edges {
      cursor
      node {
        id
        _id
        addressType
        companyName
        name
        firstName
        lastName
        email
        address
        city
        state
        country
        postcode
        phone
        vatId
        defaultAddress
        useForShipping
        additional
        createdAt
        updatedAt
      }
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    totalCount
  }
}

Authentication

This query requires a valid customer authentication token in the Authorization header. Use the Customer Login API to retrieve the token.

Request Headers

HeaderValueRequiredDescription
Content-Typeapplication/jsonYesRequest content type
X-STOREFRONT-KEYpk_storefront_xxxYesStorefront API key
AuthorizationBearer {token}YesCustomer authentication token

Arguments

ArgumentTypeRequiredDescription
firstIntNoNumber of addresses to fetch (default: 10, max: 100)
afterStringNoCursor for forward pagination
lastIntNoNumber of addresses to fetch backward
beforeStringNoCursor for backward pagination

Response Fields

FieldTypeDescription
idStringIRI identifier (e.g., /api/shop/customer-addresses/2829)
_idIntNumeric database ID
addressTypeStringAddress type (e.g., customer)
companyNameStringCompany name (nullable)
nameStringFull name (computed from first + last name)
firstNameStringFirst name
lastNameStringLast name
emailStringEmail address
addressStringStreet address
cityStringCity
stateStringState/Province code
countryStringCountry code (ISO 3166-1 alpha-2)
postcodeStringPostal/Zip code
phoneStringPhone number
vatIdStringVAT identification number (nullable)
defaultAddressBooleanWhether this is the default address
useForShippingBooleanWhether this address is used for shipping
additionalJSONAdditional address data (nullable)
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp

cURL Example

bash
curl -X POST "http://localhost:8000/api/graphql" \
  -H "X-STOREFRONT-KEY: pk_storefront_your_key_here" \
  -H "Authorization: Bearer YOUR_CUSTOMER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query { getCustomerAddresses(first: 10) { edges { cursor node { _id firstName lastName address city state country postcode phone defaultAddress } } pageInfo { hasNextPage endCursor } totalCount } }"
  }'

Pagination

Uses cursor-based pagination:

  • Forward: first + after — use endCursor from pageInfo as the next after value
  • Backward: last + before — use startCursor from pageInfo as the next before value
  • Check for more: read pageInfo.hasNextPage or pageInfo.hasPreviousPage

Empty Response

When the customer has no saved addresses:

json
{
  "data": {
    "getCustomerAddresses": {
      "edges": [],
      "pageInfo": {
        "hasNextPage": false,
        "hasPreviousPage": false,
        "startCursor": null,
        "endCursor": null
      },
      "totalCount": 0
    }
  }
}

Use Cases

Use CaseApproach
Address bookFetch all addresses with first: 50 for account dashboard
Checkout selectorFetch minimal fields (_id, name, address, city, defaultAddress) for an address dropdown
Default addressLook for the entry with defaultAddress: true
Business addressesInclude companyName and vatId fields for B2B customers
Pre-fill checkoutUse defaultAddress: true entry to pre-populate shipping/billing forms

Error Responses

Unauthenticated

json
{
  "errors": [
    {
      "message": "Unauthenticated. Please login to perform this action",
      "locations": [{ "line": 2, "column": 3 }],
      "path": ["getCustomerAddresses"]
    }
  ]
}

Released under the MIT License.