Fetch the metafields of all the orders in a shop

Highlighted
New Member
2 0 0

Hello there,

 

I am new to shopify api, i want to fetch the informaiton attached to the metafields of orders. I am able to fetch the  metafields by single orderId (https://{store}/admin/orders/{id}/metafields.json) but the problem is to fetch it for all the orders or bulk pull as we have some currency data attached in the metafields and want to use it in our data warehouse. 

I also tried to pull it via graphQL but no luck. So if there is a way to do sho please let me know.. Thanks

Regards

Asad

0 Likes
Highlighted
Shopify Partner
72 12 24

Hi,

I will suggest that you have a cron job set up for this based on a time parameter(hourly or daily). You can then retrieve all orders that were created during that timeframe using this api call with the ?created_at_min=xxxxxxx and then retrieve each order's metafields. Then you can continue with your business logic.

Then on the next run, you use the last order that was retrieved created_at date as time parameter.

 

 

1 Like
Highlighted
New Member
2 0 0

Hello Jayvin,

Thanks for taking out time and replying.

I tried the solution you mentioned. But the issue is , as i understand (may be i am wrong) that the metafields of order are fetched by order id 

like {store}/admin/api/2020-07/orders/{id}/metafields.json

I tried something like this 

{store}/admin/api/2020-07/orders?created_at_min=2020-05-31T15:57:11-04:00/metafields.json  but it didn't work.

If i write the request like the following 

{store}/admin/api/2020-07/orders.json?created_at_min=2020-05-31T15:57:11-04:00 then it would fetch the orders JSON but it do not include the metafields. 

I want to reach this https://shopify.dev/docs/admin-api/rest/reference/metafield but for multiple orders.

Thanks 

 

Regards 

Asad

 

0 Likes
Highlighted
Shopify Partner
72 12 24

Hi Asad,

No that's not the way to do it. You have to first get all the orders using this endpoint:

 

 

{store}/admin/api/2020-07/orders.json?created_at_min=2020-05-31T15:57:11-04:00

 

 

You also have to take into consideration pagination when retrieving all the orders so that you can get all the orders for that period.

 

Once you get all the orders from the above response, then you can loop through each of the orders and retrieve the order metafields like this and then continue with your business logic.

 

 

{store}/admin/api/2020-07/orders/{id}/metafields.json

 

 

 

Else if you want another solution. You can have an app that listens to order.created/order.paid webhook, then you can process the order by getting it's metafields.

It all depends on your business needsand what

1 Like