Shopify Customer API 2026: Create Customers, Tags & Customer Segments from Your App

2026-11-30来源 dev.toEnglish

Shopify customer API tutorial (2026): create customers from your own Shopify app with the GraphQL Admin API - name, email, phone, address, tags and email marketing consent - then search them, edit tags, build a customer segment with a ShopifyQL query, and delete customers (and why some can't be deleted). Shopify app development series, episode 14 - everything shown is real, nothing skipped.

What you'll learn

  • Scope write_customers + protected customer data
  • customerCreate (+ marketing consent)
  • Customer search: tag:vip
  • customerUpdate tags
  • segmentCreate + customerSegmentMembers
  • 6 real errors

💻 Free source code for this episode: https://github.com/fayyaz315/shopify-app-development-2026/tree/ep14

3 quick fixes from this episode

Shopify Create Customer API: 5 Errors You'll Hit (and the Fixes)

Shopify create customer API (2026-10), five real errors: email already taken, email invalid, phone invalid, no name/email/phone at all, and a customer with orders can't be deleted. Each one from a real store test.

▶ 60-second video: https://youtube.com/shorts/bDFTjelG-lM

Shopify Customer Segments API: Build a VIP Segment with One Query

Shopify customer segments API (2026-10): segmentCreate takes a name and a ShopifyQL query - customer_tags CONTAINS 'vip' - and customerSegmentMembers lists who is in it. A wrong filter ('tags = vip') returns line and column errors.

▶ 60-second video: https://youtube.com/shorts/_MvZ3Zraf-Q

Shopify Customer API: My 'vip' Tag Became 'VIP' - Here's Why

Shopify customer API (2026-10): I sent the tag 'vip' and the customer got 'VIP'. The store already had a VIP tag, and Shopify reused that spelling. Plus: customerUpdate replaces ALL tags - send the full list, or use tagsAdd.

▶ 60-second video: https://youtube.com/shorts/1zzaKHL9--o

Step by step

Preview + intro (0:00)

In the next ten minutes, your app creates Shopify customers, tags them, and groups them into a segment. You'll see the tag I typed in small letters come back in capitals, and the customer Shopify refuses to delete. This is the Shopify customer API at work.

Our app just created this customer, with tags and email consent. This is episode fourteen of the Shopify app development series. Last time, shipping.

Today: customers and segments. The full code is free on GitHub, and the link is in the description.

Customer data (0:35)

Customers are protected data: names, emails, phones and addresses. So there are two parts to access. First, the scope: write customers.

Second, protected customer data. A public app asks Shopify for it in the dashboard and explains why. On my development store, it worked without a review.

When does an app create customers? Importing them from another platform, a wholesale sign up form, or keeping a C R M in sync. As before, I restarted the dev server and opened the app once to grant the scope.

Read customers (1:09)

The new Customers page. The latest customers, with their email, orders and tags. One query reads them, newest change first, with a search query when there is one.

The search box puts the query in the page's address, and the loader passes it straight to Shopify. The same query also reads the segments, and the members of one segment when you pick it. Email and phone now live in their own objects: defaultEmailAddress, with its marketing state, and defaultPhoneNumber.

numberOfOrders comes back as a string, because it can be a very large number. The loader turns it into a normal number. The table shows a green subscribed badge when the email's marketing state is subscribed.

Create a customer (1:54)

Add a customer: Ayesha Malik. Her email and phone number. Lahore, Pakistan.

Tags: v i p, and wholesale, in small letters. And she agreed to receive marketing emails. Add customer.

Customer created. There she is: Lahore, subscribed, with her tags. That's customer create.

Name, email and phone, the tags as a list, and an address. The address is a list, because customers can have several. The first one became her default address, which is where the table's city comes from.

Phone numbers go in international format, with the country code. In my tests, a full number worked, and a two digit one was refused. Marketing consent is its own object, not a yes or no.

Marketing state subscribed, with an opt in level. We only send it when the box is ticked. The tags box is comma separated, so a tiny helper splits it into a list.

Every action returns userErrors, and the page shows Shopify's message in a red toast. Coming up: a customer Shopify won't let you delete.

Duplicate email (3:09)

What if I press add customer again, with the same email? Email has already been taken. One email, one customer.

In my tests: a bad email is email is invalid, a short phone is phone is invalid, and no name, email or phone at all is refused too.

Search and tags (3:27)

Now search: tag:v i p. Two customers. And look at Ayesha's tag.

I typed v i p in small letters, and Shopify saved it in capitals. Russell already had a V I P tag, and Shopify reused that spelling. In my tests, wholesale with a capital W came back in small letters the same way.

Edit her tags: v i p, wholesale, and lahore. The Tags button swaps the cell for a small form with the current tags already filled in. Tags saved.

That's customer update with the full list. Update replaces all the tags, so always send every tag you want to keep. To add one tag without touching the others, there's tags add.

Customer segments (4:12)

Now a segment. Name: V I P customers. And the query, in Shopify's segment language: customer tags contains v i p.

Create segment. Segment created. The page can list a segment's members too, with customerSegmentMembers.

We'll look at them in GraphiQL in a moment. What are segments good for? A discount only for V I P customers, a win back email, or a report of your best buyers.

Segment create takes just a name and a query. The segment language has filters like numberOfOrders, amount spent, customer tags and email subscription status. And members come from a separate query, only when a segment is chosen.

One thing from my tests: a customer created a second ago can take a moment to join a segment. Search finds them at once.

Delete (5:04)

Last, delete. Ayesha first. Customer deleted.

Now Russell. Customer can't be deleted because they have associated orders. Shopify keeps customers who have orders.

That's customer delete. For customers with orders, a real app would tag them, or remove their marketing consent, instead.

In GraphiQL (5:25)

Now GraphiQL. The same search, tag V I P, with each email's marketing state. Russell, with his orders and his V I P tag.

The segment's members, with a total count. One member so far: Russell. A brand new customer can take a moment to join.

A segment with the wrong filter: tags equals wholesale. Shopify answers with the line and column, and says the tags filter cannot be found. The right one is customer tags.

And a customer with only a note: a name, phone number, or email address must be present. Want to practise? Make a segment of customers with more than one order, and compare it with Shopify's own.

Honest notes (6:09)

A few honest notes before the recap. One: our list shows ten customers. Real stores have thousands, so a real app pages through them with cursors.

Two: only set marketing consent when the customer really agreed. That's the law in many countries, not just a field. Three: the customers you saw are Shopify's sample customers on a development store, with example.com emails.

Four: logins and customer accounts on the storefront are a different API, the Customer Account API. Today was the Admin API. And everything you saw was tested on my real development store, on API version 2026-10, before I pressed record.

Recap (6:51)

So, the recap. Create customers with customer create, and consent as its own object. Find them with search queries, like tag:v i p.

Update replaces the tags, and Shopify keeps one spelling per tag. And group them with a segment query. That's the Shopify customer API in 2026, inside a real app, on a real store.

The full code for this episode is free on GitHub. The link is in the description. Next episode: orders.

Draft orders, real orders, payments and cancelling. See you there.

📖 The full written tutorial with every episode: https://www.wixob.com/shopify-create-customer-api-tutorial/
📚 Course page: https://www.wixob.com/shopify-app-development-2026/
🔔 New episodes on YouTube: https://www.youtube.com/@fayyaz-ahmed-shopify-developer?sub_confirmation=1

Questions about the Shopify GraphQL Admin API? Ask in the comments — I answer every one.

原文:https://www.a8q9.cn/en/article/shopify-customer-api-2026-create-customers-tags-customer-segments-from-your-app-36ec53.html

相关文章