API Reference
GraphQL Customer API
💬Get free consultation

GraphQL Customer API

ⓘ

Who can use this feature?

  • Creating the credentials this API needs requires the Pro or Plus plan.
  • You'll need a secret key (the sk_ value) from Settings → General → Manage keys. See Generate your API key for the steps.

Overview

The GraphQL Customer API gives you read access to the contacts Chatty has collected for your store: names, emails, channels, order counts, total spend, and chat activity. Use it to sync contacts into a CRM, push segments to an email tool, or build a custom dashboard.

It's a single GraphQL endpoint, so you ask for exactly the fields you need in one request.

Two things to know before you design your integration:

  • The API is read-only. The schema exposes queries only. There is no mutation and no subscription, so you cannot create, edit, or delete a contact through it.
  • There is no server-side filtering, searching, or sorting. customers accepts pagination arguments and nothing else. To find contacts by email, channel, or spend, page through the list and filter in your own code. See Filtering and sorting.

Endpoint

POST https://graphql.chatty.net/graphql

Send requests as POST with a JSON body containing your query, plus optional variables and operationName.

The server rejects a request that carries no Content-Type header, or a Content-Type of application/x-www-form-urlencoded, multipart/form-data, or text/plain, as a possible cross-site request forgery. Always send Content-Type: application/json. GET also works for queries, with the same Content-Type rule.

Authentication

Every request needs one header:

HeaderValue
X-Api-KeyYour Secret key, the sk_ value

It comes from Settings → General → Manage keys, the same panel that issues keys for the Chat Conversations API. Both APIs read the key from the same header. Your App ID is not needed here.

A missing key returns HTTP 401 with the code UNAUTHENTICATED. An unknown or deleted key returns HTTP 401 with INVALID_API_KEY. Both arrive as a plain JSON body, not a GraphQL errors array:

{ "error": { "code": "UNAUTHENTICATED", "message": "Provide an X-Api-Key header" } }

Requests that still send the older x-api-id and x-api-secret headers get this same 401. See Errors and rate limits.

!

Keep your Secret key private. It authenticates as your store. Never expose it in front-end code or a public repository. If it leaks, delete it in Settings → General → Manage keys and create a replacement. A deleted key stops working on its next request. See Authentication.


Queries

customer: fetch one contact

ArgumentTypeRequiredDescription
idID!YesThe Chatty customer ID.

Returns null when no contact matches the ID. Because the return type is nullable, a missing contact is not an error: you get HTTP 200, "customer": null, and no errors array.

customers: list contacts (paginated)

Relay-style cursor pagination. Use first/after to page forward, last/before to page backward.

ArgumentTypeRequiredDescription
firstIntNoNumber of records to return forward.
afterStringNoCursor to start after.
lastIntNoNumber of records to return backward.
beforeStringNoCursor to end before.

These four arguments are the complete set. customers takes no filter, search, sort, or date-range argument.

Every argument is optional, so customers { totalCount } is a valid query. Without first or last, you get 10 contacts. A page never holds more than 100: a larger first or last is cut to 100 without an error.

Pair first with after and last with before. Any other mix, such as first with last or first with before, returns a BAD_REQUEST error. So does a negative first or last.

Filtering and sorting

The API returns the full contact list for your store, ordered by contact id. That order has nothing to do with when a contact was created or updated. There is no argument to narrow or reorder the list. Handle it on your side:

  • Filter by a field such as email, type, channels, ordersCount, or totalSpent after you receive each page.
  • Sort by loading the pages you need and sorting in your own code.
  • Sync incrementally by walking the full list and keeping only records whose updatedAt is later than your last sync time. The list is ordered by id, not by date, so you can't stop early when you reach an older record.
  • Look up one contact with the customer query when you already hold the ID. It is far cheaper than scanning the list.

If you need a filtered feed rather than a full scan, Webhooks push events as they happen instead.


Schema

Customer

FieldTypeDescription
idID!Chatty customer ID.
shopIdString!Your store identifier.
shopifyCustomerIdStringMatching Shopify customer ID, if any.
firstNameString!First name. Empty string when not set.
lastNameStringLast name.
emailStringEmail address.
phoneStringPhone number.
ipLocationStringLocation derived from IP.
ipAddressStringLast seen IP address.
typeCustomerType!Contact type (see enum below). CUSTOMER when not classified.
channels[Channel!]!Channels the contact has used. [ONLINE_STORE] when not set.
ordersCountInt!Number of orders placed.
totalSpentFloat!Lifetime spend.
createdAtDateTime!When the contact was first seen.
updatedAtDateTimeLast update timestamp.
lastChatAtDateTimeLast time the contact chatted.
fullNameString!Convenience full name, firstName plus lastName.

A ! means the field is never null. Every other field can come back null, so treat lastName, email, phone, ipLocation, ipAddress, shopifyCustomerId, updatedAt, and lastChatAt as optional in your own types.

Customer has no nested object field. Every field is a scalar, an enum, or a list of enums, so a contact never expands into further sub-selections.

Scalars

ScalarShape
IDOpaque string. Send it as a string, don't parse it.
StringUTF-8 text.
IntWhole number between -2,147,483,648 and 2,147,483,647.
FloatDouble-precision decimal.
Booleantrue or false.
DateTimeISO 8601 date-time string at UTC, such as 2026-08-03T12:00:00.000Z.

Connection types

customers returns a CustomerConnection:

TypeFields
CustomerConnectionedges [CustomerEdge!]!, nodes [Customer!]!, pageInfo PageInfo!, totalCount Int!
CustomerEdgecursor String!, node Customer!
PageInfohasNextPage Boolean!, hasPreviousPage Boolean!, startCursor String, endCursor String
FieldTypeDescription
edges[CustomerEdge!]!Each contact wrapped with its own cursor.
nodes[Customer!]!The same contacts without the cursors.
pageInfoPageInfo!Where you are in the list.
totalCountInt!Total contacts in the store, not the size of this page.
cursorString!Position of one contact, used with after or before.
nodeCustomer!The contact at the end of the edge.
hasNextPageBoolean!More pages exist after this one.
hasPreviousPageBoolean!More pages exist before this one.
startCursorStringCursor of the first contact on this page.
endCursorStringCursor of the last contact on this page.

Select nodes when you only walk forward with endCursor. Select edges when you need to remember a position part-way through a page, for example to resume a long sync.

Enums

CustomerType: CUSTOMER, GUEST, ANONYMOUS

ValueMeaning
CUSTOMERA registered customer with an account.
GUESTA shopper who has not created an account.
ANONYMOUSAn unidentified visitor.

Channel: ONLINE_STORE, EMAIL, WHATSAPP, FACEBOOK, INSTAGRAM

ValueMeaning
ONLINE_STOREThe online storefront.
EMAILEmail communication.
WHATSAPPWhatsApp messaging.
FACEBOOKFacebook messaging.
INSTAGRAMInstagram messaging.

These two enums are the complete set. New values can be added later, so handle an unfamiliar value instead of failing on it.

Explore the schema yourself

The endpoint answers GraphQL introspection, so you can generate typed clients from the live schema. It needs the same X-Api-Key header as any other request.

curl -s -X POST "https://graphql.chatty.net/graphql" \
  -H "X-Api-Key: YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"{ __schema { queryType { name } types { name kind } } }"}'

Introspection returns the shape only, never contact data.


Examples

List the first 25 contacts

query {
  customers(first: 25) {
    totalCount
    pageInfo { hasNextPage endCursor }
    nodes {
      id
      fullName
      email
      channels
      ordersCount
      totalSpent
      lastChatAt
    }
  }
}

Page to the next 50

query NextPage($after: String!) {
  customers(first: 50, after: $after) {
    pageInfo { hasNextPage endCursor }
    nodes { id email }
  }
}

Page backward from a cursor

query PreviousPage($before: String!) {
  customers(last: 50, before: $before) {
    pageInfo { hasPreviousPage startCursor }
    nodes { id email }
  }
}

Keep a cursor for every contact

query WithCursors {
  customers(first: 25) {
    edges {
      cursor
      node { id email }
    }
    pageInfo { hasNextPage endCursor }
  }
}

Count contacts without reading them

query ContactCount {
  customers(first: 1) {
    totalCount
  }
}

Fetch a single contact

query {
  customer(id: "CUSTOMER_ID") {
    fullName
    email
    totalSpent
    ordersCount
  }
}

Pull the fields a CRM sync needs

query CrmSync($after: String) {
  customers(first: 25, after: $after) {
    pageInfo { hasNextPage endCursor }
    nodes {
      id
      email
      firstName
      lastName
      phone
      shopifyCustomerId
      ordersCount
      totalSpent
      updatedAt
    }
  }
}

Send "after": null on the first call and the cursor from the previous page after that.

Call it with curl

curl -s -X POST "https://graphql.chatty.net/graphql" \
  -H "X-Api-Key: YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"{ customers(first: 10) { nodes { id email totalSpent } } }"}'

Send variables with curl

curl -s -X POST "https://graphql.chatty.net/graphql" \
  -H "X-Api-Key: $CHATTY_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"query":"query NextPage($after: String!) { customers(first: 50, after: $after) { pageInfo { hasNextPage endCursor } nodes { id email } } }","variables":{"after":"'"$NEXT_CURSOR"'"},"operationName":"NextPage"}'

operationName is optional with a single operation and required when your document holds more than one.


Pagination

The API uses Relay-style cursor pagination. To walk the full list:

  1. Request customers(first: N).
  2. Read pageInfo.endCursor and pageInfo.hasNextPage.
  3. While hasNextPage is true, request customers(first: N, after: endCursor).

Points worth knowing:

  • totalCount counts the whole store, not the page. Use it for a progress bar, and still stop on hasNextPage.
  • A page can hold fewer contacts than you asked for. Contacts waiting to be deleted are skipped, but totalCount still counts them.
  • Cursors are opaque. Pass back exactly what you received and don't build one yourself. A cursor the server can't read returns BAD_REQUEST.
  • A cursor does not expire. It marks a position in the list, so you can store one and resume a walk later.
  • Choose the page size by cost, not by habit. A page holds 10 contacts by default and 100 at most. A query whose estimated cost is over 500 is rejected before it runs, so a page with a handful of fields can be much larger than a page with every field. See Rate limiting.
  • Backward paging needs a cursor to start from. last without before returns the first contacts of the list, not the last ones. Pass a startCursor as before to move toward the front. While you page backward, hasNextPage is always true.

Errors

Errors arrive in two shapes. A request stopped before it reaches GraphQL gets a plain JSON body with an error object. That happens when the key is missing or wrong, or your IP sends too many requests. Everything else comes back as a GraphQL envelope with an errors array, and the HTTP status depends on where the request failed.

{
  "data": null,
  "errors": [
    {
      "message": "Cannot use both \"first\" and \"last\" at the same time.",
      "locations": [{ "line": 1, "column": 3 }],
      "path": ["customers"],
      "extensions": { "code": "BAD_REQUEST" }
    }
  ]
}
  • message is human-readable and can change. Branch on extensions.code instead.
  • path points at the field that failed. It is absent when the request never reached a field.
  • locations marks the spot in your query text.
StatusCodeWhen
401UNAUTHENTICATEDNo X-Api-Key header. Plain JSON body.
401INVALID_API_KEYThe key is unknown or deleted. Plain JSON body.
429RATE_LIMITEDYour IP sent more than 300 requests in a minute. Plain JSON body.
400BAD_REQUESTThe body carries no query.
400GRAPHQL_PARSE_FAILEDThe query text is not valid GraphQL syntax.
400GRAPHQL_VALIDATION_FAILEDThe syntax parses but the query is wrong: an unknown field, a missing required argument, or an argument of the wrong type.
400BAD_USER_INPUTA variable has the wrong type, or the query has more than 10,000 selections.
400MAX_COMPLEXITY_EXCEEDEDThe query's estimated cost is over 500.
429THROTTLEDYour store's cost budget can't cover the query right now.
200BAD_REQUESTcustomers got a mix of pagination arguments it does not accept, a negative first or last, or a cursor it can't read. data is null.

The 400 cases are bugs in your query and fail the same way on every retry. Fix the query rather than retrying it. For MAX_COMPLEXITY_EXCEEDED, lower first or select fewer fields. The 429 cases are about pace: wait, then retry.

A BAD_REQUEST from customers is the case that catches integrations out. It arrives as HTTP 200 with "data": null, so a client that only checks the status treats a rejected request as a successful empty one. Check for an errors array on every response.

A query can also succeed in part. If one field resolves and another fails, you get HTTP 200 with both data and errors populated, and the failed field is null. Read errors even when data is present. See Errors and rate limits.


Rate limiting

This API is metered by query cost, not by request count. It uses a token bucket per store: every query spends from a budget of 2,000 points that refills at 100 points per second.

Before a query runs, the server estimates its cost. Every field costs 1 plus the fields inside it. customers costs the page size times the fields inside it, plus 1, with the page size capped at 100. A query estimated over 500 is rejected with MAX_COMPLEXITY_EXCEEDED. After the query runs, your store is charged the actual cost, which counts only the contacts that came back.

For example, the 25-contact list in Examples selects 12 fields inside customers and estimates at 301. The same query with first: 50 estimates at 601 and is rejected. Lower first before you drop fields.

Three signals tell you where you stand:

  • extensions.cost on every admitted response. It carries requestedQueryCost, actualQueryCost, and throttleStatus with maximumAvailable, currentlyAvailable, and refillRate. Watch currentlyAvailable.
  • THROTTLED with HTTP 429 when the budget can't cover a query. Its extensions.cost.throttleStatus.currentlyAvailable shows what is left, so you can wait until the bucket refills to requestedQueryCost.
  • X-RateLimit-Limit and X-RateLimit-Remaining headers. These count requests from your IP address, 300 a minute, not query cost. Going over returns HTTP 429 with RATE_LIMITED.

In practice: page in modest sizes, run one walk at a time rather than several in parallel, and back off before retrying any failure you cannot trace to your own query.


Need help?

If you run into issues with your key or a query, contact the Chatty support team from your dashboard. For no-code options, see Klaviyo, Zendesk, or Joy.