get-customers
Retrieve Shopify customer data with pagination support to manage and analyze store client information systematically.
Instructions
Get shopify customers with pagination support
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Limit of customers to return | |
| next | No | Next page cursor |
Implementation Reference
- src/index.ts:218-241 (registration)Registration of the 'get-customers' MCP tool, including Zod input schema for parameters (limit, next) and inline async handler function that instantiates ShopifyClient and calls loadCustomers, returning JSON response or error.server.tool( "get-customers", "Get shopify customers with pagination support", { limit: z.number().optional().describe("Limit of customers to return"), next: z.string().optional().describe("Next page cursor"), }, async ({ limit, next }) => { const client = new ShopifyClient(); try { const response = await client.loadCustomers( SHOPIFY_ACCESS_TOKEN, MYSHOPIFY_DOMAIN, limit, next ); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }], }; } catch (error) { return handleError("Failed to retrieve customers data", error); } } );
- src/index.ts:222-224 (schema)Zod schema defining input parameters for the get-customers tool: optional limit (number) and next page cursor (string).limit: z.number().optional().describe("Limit of customers to return"), next: z.string().optional().describe("Next page cursor"), },
- Core implementation of customer loading via Shopify Admin API REST endpoint /customers.json, supporting pagination with limit and page_info, selecting fields id/email/tags, and parsing next page cursor from Link header.async loadCustomers( accessToken: string, shop: string, limit?: number, next?: string ): Promise<LoadCustomersResponse> { const res = await this.shopifyHTTPRequest<{ customers: any[] }>({ method: "GET", url: `https://${shop}/admin/api/${this.SHOPIFY_API_VERSION}/customers.json`, accessToken, params: { limit: limit ?? 250, page_info: next, fields: ["id", "email", "tags"].join(","), }, }); const customers = res.data.customers; const nextPageInfo = ShopifyClient.getShopifyOrdersNextPage( res.headers.get("link") ); return { customers, next: nextPageInfo }; }
- Type definition for the output of loadCustomers: array of ShopifyCustomer objects with optional next pagination cursor.export type LoadCustomersResponse = { customers: Array<ShopifyCustomer>; next?: string | undefined; };