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
743 stars 309 forks source link

Get Order list by tag #921

Closed cyrebre closed 1 year ago

cyrebre commented 1 year ago

Hi, I would like to know if there is a way to get orders by tag with ShopifySharp ?

I know it's possible to access this query through the api (please refer: https://community.shopify.com/c/customers-discounts-and-orders/get-orders-by-tags/m-p/1824313/highlight/true#M632 ) https://{store}.myshopify.com/admin/api/2021-01/orders.json?tag=readytoship&status=any

Many thanks, Cyril

nozzlegear commented 1 year ago

Hey @cyrebre! Technically this isn't supported by Shopify's REST API since it's undocumented, but as the comments in that forum post point out, it does in fact work. You could implement it in ShopifySharp using a custom OrderListFilter like so:

public class TaggedOrderListFilter : OrderListFilter
{
    /// Restricts results to those orders with the given tag. Note: when tag is used, the list will default 
    /// to orders with Status="any". Set the Status property if this behavior is undesired.
    [JsonProperty("tag")]
    public string Tag { get; set; }
}

var orderService = new OrderService(domain, token);
var filter = new TaggedOrderListFilter
{
  Tag = "readytoship",
  Status = "any"
};
var listResult = await orderService.ListAsync(filter);
cyrebre commented 1 year ago

Hi nozzlegear !

Many thanks, this is exactly what I wanted to do ! Also thank you and other contributors for ShopifySharp, this is a great piece of software.

Have a nice day ! Cyrebre