Skip to main content

List, search and export customers

What you will build​

You list the customers of an account, one row for each with the subscription that tells its state, and narrow the list with filters. You search it by name, email, phone or reference. You then ask for the list as a CSV file and read the export until it is ready.

Before you start​

You need an access token. The sample is a vendor's: it needs a vendor's access token and a sub-account, with the sub-account's ID in the Black-Account header. See Create and act for sub-accounts and Authentication. A vendor's client without Black-Account is refused with 403 and the code account_required.

Black holds each customer's subscription, its payments and its source, bought or given for free. It does not hold bookings, spending or savings: you show them from your own bookings. It does not hold a payment method either, because your account charges its own customers.

Steps​

  1. List the customers. Send a GET request to /v1/customer-overviews. The response is a list of customers that are not deleted, newest first, with 10 rows by default and up to 100 with limit. starting_after and ending_before take a customer ID, to read the next page or the one before. Each row holds the customer, the subscription that tells its state, renews, grant and totals. See the next section for each.

  2. Narrow the list. Add filters to the query. The filters combine, and a customer must meet every one. An unknown value, a filter sent as a list or a date that is not a date is refused with 422 naming the parameter.

  3. Search the list. Add search with 2 to 100 characters, once trimmed. It combines with every filter.

  4. Read one customer. Send a GET request to /v1/customer-overviews/{id}. It answers the same row, and it reads a deleted customer too, so its history stays reachable.

  5. Ask for the list as a file. Send a POST request to /v1/customer-exports with the filters and the search of the list, as strings, and an Idempotency-Key header. The response answers 202 and the export is pending.

  6. Read the export until it is ready. Send a GET request to /v1/customer-exports/{id}, once a second. When its status is ready, it holds rows, the number of customers in the file, and file, with a url to download and its expires_at.

Read a row​

A row says what a customer holds today. subscription is the customer's live subscription, or, when it has none, the one that ended last, or null when the customer never subscribed. Its source is purchase or grant. renews is true while a renewal still comes, false when it does not, and null with no subscription. grant says who gave a free plan, when, which price and until when, and is null for a subscription that was bought. totals holds amount_paid, one entry for each currency in the smallest unit, paid_invoices, renewals_paid, last_payment_at and days_subscribed.

The response lists the rows, with has_more true while there is another page.

Narrow the list with filters​

FilterValueKeeps the customers
price, productAn ID of a price or of a productwhose subscription has an item on it
status_labelincomplete, active, pending_cancel, grace_period, expired or nonewhose subscription has that label. none keeps the customers with no subscription
sourcepurchase or grantwhose subscription was bought or given for free
renewstrue or falsewhose row reads that
flagged, blockedtrue or falsewho are flagged or blocked
email, external_referencethe exact valuewho hold it
created_from, created_untila date, as 2026-11-15created in the range
started_from, started_untila datewhose subscription started in the range
period_end_from, period_end_untila datewhose subscription renews or expires in the range
ended_from, ended_untila datewhose subscription ended in the range

A range runs from its _from, included, to its _until, excluded, in UTC. A price or a product that names nothing lists nothing.

Search by name, email, phone or reference​

search finds a customer in any of four ways. It matches the start of the customer's name or email, in any letter case: ahm finds "Ahmed Hassan" and not "Sara Ahmed". It matches the customer's external_reference when it is equal to the whole search. When the search holds only digits, spaces and the signs +, -, (, ) and ., with at least 6 digits once its leading zeros are dropped, it matches the customer's phone by its last digits, however either is written: 0501234567, 966501234567 and +966 50 123 4567 find the phone +966501234567, and 4567 finds nothing.

A %, an underscore or a backslash is matched as itself. A search with no match answers 200 with an empty data. A search of fewer than 2 or more than 100 characters, or of only spaces, is refused with 422 naming search.

Export the list as a file​

The body of the export takes the same filters and the same search, sent as strings, and no other field: any other field, limit included, is refused with 422 naming it. An export holds at most 100,000 customers. A larger one is refused with 409 and the code export_too_large, and Black writes nothing. Narrow the filters and ask again.

The export answers 202 with the export: its object is customer_export, its status is pending, its filters are the ones you sent, and rows, completed_at, file and deleted_at are null. The recorded shape of that answer is below, from a request that sends search and status_label.

HTTP/1.1 202 Accepted

{"object":"customer_export","id":"cexp_01m7fqq0cjaxnrr8sdtwp8k90x","livemode":false,"created":1794750775,"status":"pending","filters":{"status_label":"active","search":"nor"},"rows":null,"completed_at":null,"file":null,"deleted_at":null}

A repeat with the same Idempotency-Key answers the same export, with the header Idempotent-Replayed: true. Black writes the file in the background, a few seconds after the request. The export then reads ready, with rows, completed_at, a file and deleted_at. Black gives a new url each time you read it, and the link works for 15 minutes from the read: file.expires_at says when. A link whose signature was changed, or that is older than that, is refused. Read the export again for a new link.

Black deletes the file 24 hours after it made it, and the export then reads expired: deleted_at says when. The export stays in the list GET /v1/customer-exports, newest first. An export that cannot be written reads failed.

Read the file​

The file is a CSV file in UTF-8, with a byte-order mark at its start, so that a spreadsheet shows Arabic names as they are stored. It holds one header row, then one row for each customer the list gives, with 22 columns: Customer ID, Name, Email, Phone Number, Plan Type, Price ID, Subscription Start Date, Renewal Date, Payment Method, Amount Paid, Status, Spending Before Prime, Spending After Prime, Auto-renew, Flag, Blocked, Tenant, Source, Last Payment Date, Next Charge Amount, Cancellation Reason and End Reason.

Dates are written as ISO 8601 in UTC, as 2026-11-15T08:22:15Z. Amount Paid is written as text with the currency, as SAR 30.00, and several currencies are joined with ; . The text holds a no-break space between the currency and the amount, so read the amount as text. A customer that never subscribed has its subscription columns empty.

Payment Method, Spending Before Prime, Spending After Prime and Next Charge Amount are present and always empty. Black does not hold them. The amount of the next charge is on the renewal reminder: see Read the reminder before a renewal. A value that starts with =, +, - or @ is written with a leading apostrophe, so that a spreadsheet never runs it as a formula, and a phone number that starts with + shows it too.

Find each export in the activity log​

Each export is recorded in the activity log as customer_export.created, kept for good, with the actor, the export as the subject, the number of customers in count, and each filter as filters.<name>, the search text included. Read them with GET /v1/activity-entries?action=customer_export.created. See Flag a customer and read the activity log.

Handle a refusal​

Each refusal gives an error with a code. See Errors for every code.

  • parameter_invalid (422). A filter or the search is not valid, or the export holds a field that is not a filter. param names it. Fix the value, or leave the field out.
  • export_too_large (409). The filters keep more than 100,000 customers. Narrow the filters.
  • account_required (403). A vendor's client sent the request without Black-Account. Add the header with the sub-account's ID.
  • resource_not_found (404). The customer or the export is unknown, or belongs to another account.

A runnable sample​

The sample is a vendor's. It creates a sub-account, a product and a monthly price of 30 SAR, and two customers, "Nora Ali" and "Salem Nora". It subscribes Nora and reports her first invoice paid. It lists the customers, filters them by status_label, searches by the start of a name, by a phone number and by a reference, reads the overview of Nora, asks for an export of the active customers whose name starts with nor, and reads it until it is ready. It writes PLACEHOLDER_VENDOR_ACCESS_TOKEN where your access token goes, reads each ID from the response before it, and needs sed. A test environment takes five writes a second, so the sample waits a second after each write. Its names end in a number made from the time, so that it runs again.

TOKEN=PLACEHOLDER_VENDOR_ACCESS_TOKEN
RUN=$(date +%s)$RANDOM

ACCOUNT=$(curl --silent --request POST https://api.black.example/v1/vendor/accounts \
--header "Authorization: Bearer $TOKEN" \
--data name="Customer List $RUN" \
--data contact_email=owner@customer-list.example \
--data external_reference=customer-list-$RUN \
| sed -n 's/.*"id":"\(acct_[0-9a-z]*\)".*/\1/p')

PRODUCT=$(curl --silent --request POST https://api.black.example/v1/products \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data "{\"name\":\"Prime List $RUN\"}" \
| sed -n 's/.*"id":"\(prod_[0-9a-z]*\)".*/\1/p')

PRICE=$(curl --silent --request POST https://api.black.example/v1/prices \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data "{\"product\":\"$PRODUCT\",\"currency\":\"SAR\",\"unit_amount\":3000,\"recurring\":{\"interval\":\"month\",\"interval_count\":1}}" \
| sed -n 's/.*"id":"\(price_[0-9a-z]*\)".*/\1/p')

NORA=$(curl --silent --request POST https://api.black.example/v1/customers \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data "{\"name\":\"Nora Ali\",\"email\":\"nora@example.com\",\"phone\":\"+966501234567\",\"external_reference\":\"list-guest-$RUN\"}" \
| sed -n 's/.*"id":"\(cus_[0-9a-z]*\)".*/\1/p')

curl --silent --request POST https://api.black.example/v1/customers \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data '{"name":"Salem Nora","email":"salem@example.com"}'

SUBSCRIPTION_RESPONSE=$(curl --silent --request POST https://api.black.example/v1/subscriptions \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--header "Idempotency-Key: list-subscription-$RUN" \
--data "{\"customer\":\"$NORA\",\"items\":[{\"price\":\"$PRICE\"}]}")
INVOICE=$(echo "$SUBSCRIPTION_RESPONSE" | sed -n 's/.*"latest_invoice":"\(in_[0-9a-z]*\)".*/\1/p')

curl --silent --request POST https://api.black.example/v1/invoices/$INVOICE/mark-paid \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--data "{\"amount\":3000,\"currency\":\"SAR\",\"payment_reference\":\"list-payment-$RUN\"}"

curl --silent "https://api.black.example/v1/customer-overviews?limit=10" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

curl --silent "https://api.black.example/v1/customer-overviews?status_label=active" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

curl --silent "https://api.black.example/v1/customer-overviews?search=nor" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

curl --silent "https://api.black.example/v1/customer-overviews?search=0501234567" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

curl --silent "https://api.black.example/v1/customer-overviews?search=list-guest-$RUN" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

curl --silent https://api.black.example/v1/customer-overviews/$NORA \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

EXPORT=$(curl --silent --request POST https://api.black.example/v1/customer-exports \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT" \
--header "Content-Type: application/json" \
--header "Idempotency-Key: list-export-$RUN" \
--data '{"search":"nor","status_label":"active"}' \
| sed -n 's/.*"id":"\(cexp_[0-9a-z]*\)".*/\1/p')

for attempt in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
sleep 1
STATE=$(curl --silent https://api.black.example/v1/customer-exports/$EXPORT \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT")
if [[ "$STATE" == *'"status":"ready"'* ]]; then
break
fi
done

if [[ "$STATE" != *'"status":"ready"'* ]]; then
echo "The export is not ready."
exit 1
fi

curl --silent "https://api.black.example/v1/activity-entries?action=customer_export.created" \
--header "Authorization: Bearer $TOKEN" \
--header "Black-Account: $ACCOUNT"

The requests answer 200, except the creations, which answer 201, and the export, which answers 202. The list holds two customers, and the filter on status_label holds Nora alone. The searches by nor, by the phone and by the reference each hold Nora, and the first does not hold "Salem Nora". The overview answers Nora's subscription with source purchase, renews true and one entry in totals.amount_paid of 3000 SAR. The export is read until it is ready with rows 1. The link in file.url points at Black's file store, so the sample does not download it: download it from your own system, with the url you read. The last request lists the export's entry in the activity log.

What to do next​