nozzlegear / ShopifySharp

ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores.
https://nozzlegear.com/shopify-development-handbook
MIT License
764 stars 313 forks source link

GetCustomerOrders Returns No Orders #1084

Open shafaqat-ali-cms365 opened 4 months ago

shafaqat-ali-cms365 commented 4 months ago

I am trying to get customer orders, here is my code

var filter = new CustomerSearchListFilter { //Searches for a customer from the United States with a name like 'Jane'. Query = $"email:{emailAddress}" }; var customer = (await customerService.SearchAsync(filter)).Items.FirstOrDefault(); if (customer != null) { var customerOrders =await customerService.ListOrdersForCustomerAsync(customer.Id.Value); }

but it is returning 0 orders.

Diceble commented 4 months ago

Have you tried using postman to do a similar api call and see if that does return a value?

shafaqat-ali-cms365 commented 4 months ago

No, I don't have postman setup, otherwise I would have tried.

nozzlegear commented 4 months ago

Hey @shafaqat-ali-cms365! I've just tested this myself and it seems to work fine. I've added it to ShopifySharp's integration tests in this commit and they pass without issue.

I think it might be a permission issue. Both the customers and orders are protected by special permissions that may not necessarily return errors. Off the top of my head, you'd need the following:

shafaqat-ali-cms365 commented 4 months ago

image

image

I have checked permissions again and looks every thing ok. I have also noticed that I can get non archived orders only and as soon as I fulfill them, I can't retrieve them. So it is something related to order status.

nozzlegear commented 4 months ago

Your permissions look good, and so does the customer data privacy stuff. The fulfillment/order status thing is an interesting observation though, that sounds like it could be the problem. On the list filter, there's a property named Status I think, try setting the value to "any" and see if that returns some orders?

Note: I marked Status property as obsolete at some point because there was no mention of it in Shopify's documentation. Maybe that has changed now, I'll have to check.

shafaqat-ali-cms365 commented 4 months ago

I have added the status field in the filter and I can confirm that I get orders returned but If I remove the status field, I don't get any order returned for the same customer. So looks like by default it returns open order only.