Create or update a customer by contact
AI agents: read /llms.txt; add .md to any page URL. This page as Markdown: /reference/customers/v1-customer-upsert.md. Index of every page and the rules for every call: /llms.txt. Guides and concepts in one file: /llms-full.txt. OpenAPI: /openapi.json.
POST/
Finds a customer by one contact's email or phone and updates it, or creates a new customer with that contact. It always writes something: the public API has no read-only lookup of a customer by email or phone (see the notes for the ways to find one).
With perform_upsert: true YoPrint looks among the team's live customers for one with a contact (deleted contacts included) whose email equals contact.email, or whose phone equals contact.phone, and takes the first. To match by email, send only contact.email.
- A customer matches: every top-level customer field you send is written to it:
name,website,internal_notes,tax_exempt,vat_number,resale_number,default_payment_term_id,default_pricing_group_id,default_warehouse_id,customer_portal_payment_option,customer_portal_enabled,third_party_billing_defaultandhide. Fields you leave out keep their values. The contact is not changed and no contact is added. Thecustomer.updatedwebhook is sent even when nothing changed. - Nothing matches, or
perform_upsert: false: a new customer is created from the top-level fields, withcontactas its only contact. That contact is not made primary. Withoutname, the new customer has no name.
The answer is the customer with contacts in both cases and doesn't say which happened: a customer created by this call has a created_at from now.
Business rules
is_externalandexternal_typeare ignored on customers and their contacts: sending them (for example a value you read back) is not refused and changes nothing. Only the Shopify sync sets them. Other fields not listed here are not part of the API.contactis required and needsfirst_name,send_invoiceandis_primary, even when an existing customer is matched.- Matching looks at every live customer of the team, archived ones included, and takes the first match. Send
emailorphone, not both: with both, either may match. - With
perform_upsert: true, sendcontact.emailorcontact.phone. With neither, the first customer that has any contact is matched and updated. - A matched Shopify or system customer is refused (422), and nothing is written.
default_warehouse_idmust be a current company location.- The contact of a new customer is never made primary, whatever
is_primarysays (it is required but not used). Make it primary with Set the primary contact.
Side effects
- Sends
customer.updatedwhen a customer is matched, orcustomer.createdwhen one is created. - A new customer is assigned to you. Its contact's email is saved trimmed and in lower case.
- For a new customer: when the contact's email already belongs to a Customer Portal account on your team that can't open this customer yet, saving the contact gives that account access to this customer (active when the account is set up with a verified email or a password, invited otherwise). No email is sent.
Path parameters
Your team slug, shown as Team ID next to your API key in Profile.
- Example
your-team
- Example
Request body
application/json, required.
The contact to match on and, for a new customer, to create.
emailandphoneare what is matched.Child fields (10)
Required. The contact's first name.
Required.
Required. Stored with the contact and returned as
send_invoice.default_receive_smsbooleanWhen this contact is set on a sales order, it receives text messages about the order by default. Saved as sent; defaults to false.
emailstring (email)The contact's email. Messages you send to this contact go here.
faxstringChecked as a real number for
fax_country.fax_countrystringTwo-letter country code of
fax.last_namestringThe contact's last name.
phonestringChecked as a real number for
phone_country. Sendphone_countrywith it.phone_countrystringTwo-letter country code of
phone, such asUS. Required withphone.
True to look for an existing customer first. False always creates.
customer_portal_enabledboolean | nullfalseturns the Customer Portal off for the customer;trueor null turns it on. Null is saved as null, not dropped.customer_portal_payment_optionstring | null- One of:
"ENABLED","DISABLED"
- One of:
default_payment_term_idstring | nulldefault_pricing_group_idstring | nulldefault_warehouse_idstring | nullA current company location (store location) id.
hidebooleanTrue to archive.
internal_notesstringNotes for your team only.
namestringThe customer's name. Send it: without it, a new customer has no name.
resale_numberstringThe customer's resale or tax certificate number.
tax_exemptbooleanTrue when no sales tax applies to this customer.
How the customer's shipping labels are billed by default (see the customer object). A new customer without it gets
none.- One of:
"none","default_carrier_account"
- One of:
vat_numberstringTax number.
websitestringThe website address.
Response
200Successful response.
Child fields (45)
True when the customer is archived.
The customer id. Use it in paths and as
customer_idon sales orders and quotes.False for Shopify and system customers: they can't be changed through this API.
Null for a customer created by upsert without a name.
True when the customer is deleted.
account_warningobject | nullWhy YoPrint shows a warning next to the customer's name. Null when there is nothing to warn about.
Child fields (2)
The customer's payments under a dispute that is open or under review; null when there is none.
Child fields (2)
How many payments are disputed.
The total of the disputed payments, each counted once. Thousandths, an older encoding:
125000is 125.00. See Money and quantities.
What the customer owes back because
wallet_fundis negative, as a positive amount; null when it is not negative. Thousandths, an older encoding:125000is 125.00. See Money and quantities.
addressesarray of objectsBilling and shipping addresses that are not deleted, old copies replaced by an edit included (
is_current_source: false).Fields of each item (33)
False for deleted, replaced, Shopify or redacted addresses. Only current addresses can be picked for new documents or edited.
Goes up by one on every saved change. Send it back as
base_revision_numberwhen updating the address to protect against concurrent edits.billingorshippingfor customer addresses.address2string | nulladdress_family_idstring | nullShared by an address and the copies made when it was edited after use.
citystring | nullcopied_from_address_idstring | nullcountrystring | nullcountry_codestring | nullcustomer_idstringCustomer addresses only: the customer's id.
external_typestring | nullshopifyfor an address synced from Shopify.hold_stockbooleanCompany locations only; false for customer addresses.
is_default_warehousebooleanCompany locations only; false for customer addresses.
is_externalbooleanTrue for an address synced from Shopify; such addresses are read-only.
nexusbooleanCompany locations only; false for customer addresses.
notestring | nullowner_idstring | nullThe owner's id: for a customer address, the customer's id (the same as
customer_id).owner_typestringcustomerfor customer addresses.- One of:
"customer","team","unknown"
- One of:
postal_can_validatebooleanpostal_is_validbooleanpostal_validatedbooleanTrue once YoPrint has checked the address with its address validator.
postal_can_validatesays whether it could be checked andpostal_is_validgives the result. Any edit resets it to false.postcodestring | nullsourcestringcustomerfor customer addresses.- One of:
"customer","company_location","custom","unknown"
- One of:
statestring | nullstate_codestring | nullsuperseded_atstring (date-time) | nullsuperseded_by_address_idstring | nullSet on an old copy: the address that replaced it.
used_by_active_profilebooleanTrue when a brand profile uses it as Ship From. Sent on lists, reads, updates and customer answers; not on create or set-primary.
assigned_usersarray of objectsThe users assigned to the customer. Unlike List the users assigned to a customer, people who have left the team stay in this list.
Fields of each item (3)
contactsarray of objectsEvery contact, deleted ones included (
trashed).Fields of each item (18)
True when the contact is deleted.
customer_idstringCustomer contacts only.
default_receive_smsbooleanemailstring | nullexternal_typestring | nullfaxstring | nullfax_countrystring | nullis_externalbooleanTrue for a contact synced from Shopify; such contacts are read-only.
last_namestring | nullphonestring | nullphone_countrystring | nullsend_invoicebooleanCustomer contacts only.
vendor_idstringVendor contacts only.
customer_portal_enabledboolean | nullWhether the customer's contacts can open the Customer Portal (Portal settings > Customer portal in YoPrint).
false: the portal is off for this customer.true, or null (never set), means on.customer_portal_idstring | nullThe id used in the customer's portal address. Null for Shopify customers.
customer_portal_id_overridestring | nullAlways null: YoPrint no longer returns a portal sign-in link for the customer. The field stays for older integrations.
customer_portal_payment_optionstring | nullWhether the customer can pay online in the portal. Null follows the team setting (and is always null for Shopify customers).
- One of:
"ENABLED","DISABLED"
- One of:
customer_profilesarray of objectsBrand profiles.
Fields of each item (12)
The Ship From address, or null for a profile that has none.
New sales orders and quotes for the customer use the primary profile.
addressobject | nullThe Ship From address (an address, as in Customer addresses, without
used_by_active_profile), or null.- Same fields as
data.addresses.
- Same fields as
emailstring | nulllogoobject | nullThe newest logo file (a file, as in Customer files), or null.
Child fields (18)
Customer files:
tax_exemption,internal_fileorexternal_file. Vendor files:default,mockuporproduction_file.The display name.
Bytes.
custom_propertiesobject | arraycustomer_idstringCustomer files only.
dimensionsobject | nullPixel size of an image, read from its header; null for other files and for images uploaded before the size was recorded.
is_imagebooleanpositioninteger | nullWhere the file sorts.
previewobject | nullPreview image links
small,mediumandlarge(250, 800 and 1200 px), or null when there is no preview.preview_statestringready: the preview links work.processing: an image over 10 MB whose stored preview a worker is still making (seconds); read the file again, or in the web app wait formedia.preview_state_changedon the team channel.too_large: an image over 120 megapixels; it never gets a preview.failed: the worker gave up.none: not an image.- One of:
"ready","processing","too_large","failed","none"
- One of:
show_in_pdfboolean | nullsource_media_idstring | nullurlstring | nullWhere to download the file.
view_urlstring | nullA signed link to view the file. It expires: read it fresh, and don't store it.
phonestring | nullwebsitestring | null
default_payment_term_idstring | nulldefault_pricing_group_idstring | nulldefault_warehouse_idstring | nulldeposit_due_amountinteger | number | stringDeposits still due. Thousandths, an older encoding:
125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.The Customer Portal ID shown to people: the override when set, otherwise
customer_portal_id.-for Shopify customers.external_typestring | nullshopifyfor customers synced from Shopify.held_creditinteger | number | stringThe part of
wallet_fundheld while a payment is under an open dispute or a provider review: it can't be applied to orders or taken out until the hold ends. Never more thanwallet_fund; 0 whenwallet_fundis 0 or negative. Thousandths, an older encoding:125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.internal_notesstring | nulllast_ordered_datestring (date-time) | nullThe issue date of the customer's latest published sales order. Null when it has none.
mediaarray of objects- Same fields as
data.customer_profiles[].logo.
- Same fields as
ordered_amountinteger | number | stringTotal of the customer's published sales orders. Thousandths, an older encoding:
125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.overdue_amountinteger | number | stringUnpaid amounts past their payment due date. Thousandths, an older encoding:
125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.pdfobjectChild fields (1)
A link that downloads the customer's invoice statement PDF. Its token opens only this customer's statement and stops working 9,000 hours (about a year) after the answer was made. Anyone with the link can download the statement: don't share it.
quote_amountinteger | number | stringTotal of open quotes. Thousandths, an older encoding:
125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.resale_numberstring | nullshopify_compliance_deletionobject | nullsystem_typestring | nulltagsarray of objectsHow a shipping label for this customer is billed by default.
default_carrier_account: YoPrint's label and rate dialogs start on the customer's default carrier account (third-party billing).none: they start with no third-party billing.- One of:
"none","default_carrier_account"
- One of:
unpaid_amountinteger | number | stringWhat the customer still owes on published sales orders. Thousandths, an older encoding:
125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.vat_numberstring | nullThe customer's tax number (shown as Tax number in YoPrint).
wallet_currencyobjectThe team's default currency, the one
wallet_fundis in.isois its code.wallet_fundinteger | number | stringCustomer credit balance. Negative when the customer owes credit back, for example after a refund of a payment whose credit was already spent. Thousandths, an older encoding:
125000is 125.00. Usually a whole number; an amount finer than a thousandth comes back as a number with a fraction (1234.5is 1.2345), or as a string ("1234.5") when you sendX-Yoprint-Decimal-Format: exact-v1. See Money and quantities.websitestring | null
Errors
401The API key is missing or wrong (
unauthenticated).403You are not allowed to do this.
api_access_not_in_plan: your team's plan doesn't include API access (Pro and above, with an active subscription or trial), so every request answers this until the team upgrades. When your role lacks the permission the operation needs, the body is only{"message": "Insufficient Permission"}. Other refusals use the error envelope, withunauthorizedoruser_is_not_authorized.404Not found.
page_not_found: the team slug is unknown, you are not a member of the team, or an id in the path is not one of this team's.code: null, with a message that starts "No query results for": there is no record with that id.409
default_warehouse_idnames a company location that is deleted, synced from another system or redacted (blocked_external_or_compliance;current_addressis that location), or one replaced by an edit (blocked_superseded_historical_address;current_addressis its replacement). Not the usual error envelope:success: false,address_save_resultandmessage(thesave_mode); nostatusorerror.- When
default_warehouse_idnames a company location that was replaced by an edit (address_save_result.save_modeblocked_superseded_historical_address), or one that was deleted, is synced from another system or was redacted (blocked_external_or_compliance). Not the usual error envelope: the body hassuccess: false,address_save_resultandmessage.- Fix
- For
blocked_superseded_historical_address, useaddress_save_result.current_address.id. Forblocked_external_or_compliance,current_addressis the same location: pick another current one from List company locations.
422The request was refused and changed nothing.
validation_failedlists what to fix inerror.fields; other codes name a business rule, explained inerror.message. A few checks answer with only{"message": "..."}. An operation that calls another service (a payment provider, a carrier, an accounting app) can answerconnect_timeout("Please retry again") when that service does not answer in time: the change may or may not have happened there, so read the record back before you retry.- When
perform_upsertor a required contact field is missing, or the phone is not valid forphone_country.error.codeisvalidation_failed.- Fix
- Send
perform_upsertand acontactwithfirst_name,send_invoiceandis_primary. - When
default_warehouse_idis not a company location of the team (error.codeinvalid_default_warehouse).- Fix
- Use the id of a current company location from List company locations.
- When
- A new customer's
contact.emailis longer than 191 characters (error.codecustomer_portal_email_invalid, "Enter a valid email address using supported characters."). Nothing is saved. - Fix
- Send a valid email of at most 191 characters.
- When
- The customer comes from Shopify, or is a system customer (
error.codevalidation_error, with the reason inerror.message). - Fix
- Change Shopify customers in Shopify. System customers cannot be changed.
Notes
- The contact is not updated on a match. To change it, update it with the customer contact operations.
- To find a customer by email without writing, there is no filter or search. Either page through List customers and read each customer's contacts with List a customer's contacts (one call per customer), or run Export customers: its CSV has one row per contact, with the customer's
idandcontact_email. - Retries: with
perform_upsert: true, repeating a call that timed out matches the customer it created and writes the same fields again (and sends another webhook). Withperform_upsert: false, a repeat creates a second customer.
Related
- POSTCreate a customer
/v1/ api/ store/ {team_slug}/ customer - POSTCreate or update a customer contact by email or phone
/v1/ api/ store/ {team_slug}/ customer/ {hash_id}/ contact/ upsert - PATCHUpdate a customer (PATCH)
/v1/ api/ store/ {team_slug}/ customer/ {hash_id} - PATCHSet the primary contact
/v1/ api/ store/ {team_slug}/ customer/ {hash_id}/ contact/ {id}/ primary - POSTExport all customers to CSV
/v1/ api/ store/ {team_slug}/ data_export/ export_customer
