Skip to main content
Glama

tag-customer

Add tags to Shopify customers to organize and segment them for targeted marketing and personalized experiences.

Instructions

Add tags to a customer

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customerIdYesCustomer ID to tag
tagsYesTags to add to the customer

Implementation Reference

  • src/index.ts:271-301 (registration)
    Registration of the 'tag-customer' MCP tool including schema and inline handler that delegates to ShopifyClient.tagCustomer
    server.tool( "tag-customer", "Add tags to a customer", { customerId: z.string().describe("Customer ID to tag"), tags: z.array(z.string()).describe("Tags to add to the customer"), }, async ({ customerId, tags }) => { const client = new ShopifyClient(); try { const success = await client.tagCustomer( SHOPIFY_ACCESS_TOKEN, MYSHOPIFY_DOMAIN, tags, customerId ); return { content: [ { type: "text", text: success ? "Successfully tagged customer" : "Failed to tag customer", }, ], }; } catch (error) { return handleError("Failed to tag customer", error); } } );
  • Core handler implementation for tagging a customer using Shopify GraphQL 'tagsAdd' mutation
    async tagCustomer( accessToken: string, shop: string, tags: string[], externalCustomerId: string ): Promise<boolean> { const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop); const graphqlQuery = gql` mutation tagsAdd($id: ID!, $tags: [String!]!) { tagsAdd(id: $id, tags: $tags) { userErrors { field message } node { id } } } `; const res = await this.shopifyGraphqlRequest<{ data: { tagsAdd: { userErrors: Array<{ field: string[]; message: string; }>; node: { id: string; }; }; }; }>({ url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`, accessToken, query: graphqlQuery, variables: { id: `gid://shopify/Customer/${externalCustomerId}`, tags, }, }); const userErrors = res.data.data.tagsAdd.userErrors; if (userErrors.length > 0) { const errorMessages = userErrors.map((error) => error.message).join(", "); throw new Error(errorMessages); } return true; }
  • Input schema using Zod for customerId (string) and tags (array of strings)
    { customerId: z.string().describe("Customer ID to tag"), tags: z.array(z.string()).describe("Tags to add to the customer"), },
  • Interface definition for the tagCustomer method in ShopifyClientPort
    tagCustomer( accessToken: string, myshopifyDomain: string, tags: string[], customerId: string ): Promise<boolean>;
  • Utility function handleError used in the tool handler for error responses
    function handleError( defaultMessage: string, error: unknown ): { content: { type: "text"; text: string }[]; isError: boolean; } { let errorMessage = defaultMessage; if (error instanceof CustomError) { errorMessage = `${defaultMessage}: ${error.message}`; } return { content: [{ type: "text", text: errorMessage }], isError: true, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/smithery-ai/shopify-mcp-server-main-1'

If you have feedback or need assistance with the MCP directory API, please join our Discord server