shopify rest api admin for customers and orders

temifyapps
New Member
4 0 0

Capture.PNG

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 

0 Likes
Prabhat
Shopify Expert
74 5 15

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

Solution Expert
- Did I solved your issue? Like & Mark As Solution to help the community
0 Likes
temifyapps
New Member
4 0 0

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

0 Likes
Prabhat
Shopify Expert
74 5 15

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. 

Solution Expert
- Did I solved your issue? Like & Mark As Solution to help the community
0 Likes
temifyapps
New Member
4 0 0

can you explain more because according to you i need to compare orders and customers based on id but it will slow the performance of system if i do like this 

0 Likes
Prabhat
Shopify Expert
74 5 15

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]

Solution Expert
- Did I solved your issue? Like & Mark As Solution to help the community
0 Likes