Get Customer Information from a purchase

I’ve inherited a Square site for an app. How do I get customer information from a purchase in a webhook? order.created or order.updated events don’t have customer information. Sometimes payment.update has customer_id or buyer_email_address but not all the time. Obviously they are stored somewhere because all purchases have an address and email.

Specifically what I’m looking for is the contact email. Is it possible to download it from the API?

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Customers API Workflows
Orders API
Customer API: Securely Manage Customer Data

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

To get customer information from a purchase, you can use the Customers API. When a purchase is made, Square creates a customer profile which can be retrieved using the customer ID. This profile contains information such as the customer’s name, email, address, and phone number.

However, not all events will include the customer ID. For instance, the order.created and order.updated events do not include customer information. The payment.updated event might include a customer_id or buyer_email_address, but not always.

If a customer_id is not provided in a payment event, Square attempts to infer the associated customer. First, Square checks the customer_id field in the corresponding order. If this field isn’t set, Square searches the Customer Directory for a matching profile using payment or related information. If one cannot be found, Square attempts to create an instant profile.

If Square cannot find a matching customer profile and cannot create an instant profile, the customer_id field of the payment remains unset. In such cases, you might not be able to retrieve the customer information directly from the webhook event.

To ensure you always have the customer information, you could consider implementing a process where you use the Customers API to create or update a customer profile at the time of purchase, and store the customer_id with the order or payment data. This way, you can always retrieve the customer information using the customer_id when you receive a webhook event.

This answer was reviewed by @Bryan-Square.