findOrdersByTrackingNumber
Introduction
The findOrdersByTrackingNumber
function allows you to locate orders associated with a provided tracking number. When executed in the Execute JavaScript block, it checks for the existence of orders in the system and, if found, returns a response array containing full details of the orders associated with the tracking number — including customer information, tracking details, purchased items, and payment status.
How to Use
-
First, you need to use the advanced configuration options in our WhatsApp messages to request the tracking number from the customer, saving the provided response into a variable — in this case,
payload.tracking
.
Note: To learn more about the advanced configuration options in our WhatsApp messages, access our help center article: Help Center – Understanding the Logic, Time, Chat, and Advanced Actions in Automations
-
Next, once the customer provides the tracking number, within the automation structure, use the Execute JavaScript block to run the
findOrdersByTrackingNumber
function and search for the orders associated with the provided tracking number. -
In the Execute JavaScript block, we use the code
payload.orders = await findOrdersByTrackingNumber(payload.tracking)
to search for orders associated with the tracking number provided by the customer. This way, the tracking number saved in thepayload.tracking
variable is used by thefindOrdersByTrackingNumber
function to retrieve the orders linked to that tracking number. The result is stored inpayload.orders
as an array containing the orders. -
The response from the search may return, in the following messages, information about the orders found.
Example Code
Example Code
Note: In the example code, if no orders are found for the provided phone number, the message “No orders found” will be displayed.
To structure the response message containing the order data in this example, we use the Reportana® Script template language, which supports for
and if/else
structures. These commands allow for detailed and conditional formatting of the displayed information. To deepen your understanding of Reportana® Script and explore additional examples, refer to the full documentation: Reportana® Script - Documentation.
Return of the findOrdersByTrackingNumber
Function
Response Data
The search returns various detailed information about the orders, including:
- Customer Data: Name, phone number, email used to place the order, etc;
- Order Information: Order ID, payment status (e.g., paid, pending), payment method (e.g., boleto, credit card), order creation date, etc;
- Address Data: Billing and shipping address, including city, state, ZIP code, etc;
- Order Items: Product name, variant (e.g., color), quantity, unit price, product image URL, etc;
- Payment Information: Boleto URL, boleto digitable line, due date, Pix copy and paste code, total order value, etc;
- Useful URLs: Tracking link and any other relevant URLs.
This data enables composing personalized messages to inform the customer about the details of the orders associated with the phone number used in the search.