This is a customers data fetching from rest api and getting mostly details but i want to ask how to join customers and orders , or how can i get customers with orders details , i used orders.json but getting duplicate customers so please guide me how to get customers with orders details ...?
thnaks
Make use of graphQL that will help you easily.
Or Check this REST API
https://shopify.dev/docs/admin-api/rest/reference/customers/customer#orders-2020-10
Look for
GET /admin/api/2020-10/customers/{customer_id}/orders.json
Retrieves all orders belonging to a customer
thank you so much for your response i am already done with orders.json and customers.json using rest api but not getting what i need .
i just want to fetch customers with orders ...?
but in your reference i get customer order detail by id , in general i am looking for join or any other solution
So basically you will loop through the customer JSON and request order for each Customer and store all the data together.
Brute Force method
Use the javascript filter method to filter to create an array of orders in which the customer id is matching.
Some Optimize way would be to create a Customer Map with the orders
so something like (pseudo code )
if(customer.id == order.customer.id ){
customer_order[customer.id].push(order_details)
}
This will give you the map of the orders created by that specific customer.
Here is bit optimize way instead of
O(n)2
The below logic use
O(n)
customer_order = [];
for(order in orders ){
customer_order[order.customer.id].push(order)
}
Now you can access the customer order simply by putting
customer_order[customer_id]
User | Count |
---|---|
12 | |
12 | |
7 | |
6 | |
4 |