Skip to content
Cartly Developers

GraphQL

Query exactly the data you need with the Cartly GraphQL Storefront API.

Endpoint

The GraphQL API is available at a single endpoint. All requests must bePOST with a JSON body containing the query field.

bashPOST /graphql
curl -X POST "https://cartly.pro/graphql" \
  -H "Content-Type: application/json" \
  -H "X-Shop-ID: {store_id}" \
  -d '{
    "query": "{ products(limit: 5) { edges { id title slug basePrice } pageInfo { hasNextPage } } }"
  }'

Required headers:

  • Content-Type: application/json
  • X-Shop-ID — your Store ID: the shop UUID shown in the admin under Settings → Store Information. Your store slug (my-store) or its storefront host (my-store.mycartly.pro) are accepted too. You can also send it as the shop_id query parameter.

A missing or malformed value answers 400. An unknown store slug or host answers 404. Both carry a message that says what to send.

Queries

Products

Fetch products page by page (page, limit); pageInfo carries the totals. Prices are integers in the shop currency's minor units (cents). Request only the fields you need.

graphqlProducts query with pagination
query GetProducts($page: Int, $limit: Int) {
  products(page: $page, limit: $limit) {
    edges {
      id
      title
      slug
      description
      basePrice
      thumbnail
      images
      variants {
        id
        title
        sku
        price
        available
        stockStatus
      }
    }
    pageInfo {
      total
      page
      pages
      hasNextPage
    }
  }
}

Search

Full-text search powered by Typesense. Returns matching products ranked by relevance.

graphqlSearch products
query SearchProducts($query: String!, $limit: Int) {
  searchProducts(query: $query, limit: $limit) {
    total
    products {
      id
      title
      slug
      basePrice
      thumbnail
    }
  }
}

Collections

Fetch a collection and its products in a single query.

graphqlCollection with products
query GetCollection($slug: String!) {
  collection(slug: $slug) {
    id
    title
    description
    productCount
    products(limit: 20) {
      edges {
        id
        title
        basePrice
        thumbnail
      }
      pageInfo {
        hasNextPage
      }
    }
  }
}

Mutations

Mutations are available for cart operations. The cart is keyed by the X-Cart-Session header: generate a random value once and send it with every cart request. Errors come back in the standard GraphQL errors array.

graphqlAdd to cart mutation
mutation AddToCart($variantId: ID!, $quantity: Int) {
  addToCart(variantId: $variantId, quantity: $quantity) {
    id
    totalItems
    subtotal
    items {
      variantId
      quantity
      variant {
        title
        price
      }
      product {
        title
        slug
      }
    }
  }
}

JavaScript Client

A minimal client for making GraphQL requests:

javascriptSimple GraphQL client
async function graphqlQuery(shopId, query, variables = {}) {
  const response = await fetch("https://cartly.pro/graphql", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Shop-ID": shopId,
    },
    body: JSON.stringify({ query, variables }),
  });

  const json = await response.json();

  if (json.errors) {
    throw new Error(json.errors.map(e => e.message).join(", "));
  }

  return json.data;
}

// Usage
const data = await graphqlQuery("store-id", `
  query {
    products(limit: 10) {
      edges { id title basePrice }
    }
  }
`);

Rate Limiting

The GraphQL API enforces rate limits to ensure fair usage:

  • Mutations: 30 per minute per shop and client IP — over the limit a mutation returns an error with extensions.code RATE_LIMITED
  • All requests: the API-wide per-IP limit — over it the API answers 429 Too Many Requests

The API-wide limit reports itself in the response headers:

  • X-RateLimit-Limit — maximum requests per window
  • X-RateLimit-Remaining — remaining requests
  • Retry-After — seconds to wait (on a 429)

Playground

In development mode, a GraphQL playground is available at /graphql in your browser. Open https://your-dev-url/graphql and use the interactive editor to explore the schema, write queries, and test mutations.

The playground includes full schema documentation, autocomplete, and query history.