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
742 stars 308 forks source link

App crashes silently using version 5.19.0 #1014

Closed cstone-LF closed 6 months ago

cstone-LF commented 6 months ago

I am using version 5.19.0 and trying to update orders with tracking numbers from examples provided here, so I wrote a little function to do just that. But the fulfillment OrderService crashes the program at ListAsync.

Here is my code. What am I doing wrong?

    public async void updateFulfillment(long orderId, string TrackingNum, ApiCredentials credentials)
    {

        string domain = credentials.BaseUrl;
        string accessToken = credentials.AccessToken;

        var fulfillments = new FulfillmentService(domain, accessToken);
        var fulfillmentOrders = new FulfillmentOrderService(domain, accessToken);

        // Find open fulfillment orders for this order
        var openFulfillmentOrders = await fulfillmentOrders.ListAsync(orderId);
        openFulfillmentOrders = openFulfillmentOrders.Where(f => f.Status == "open").ToList();

        // Fulfill the line items
        var lineItems = openFulfillmentOrders.Select(o => new LineItemsByFulfillmentOrder
        {
            FulfillmentOrderId = o.Id.Value
            // Optionally specify a list of line items if you're doing a partial fulfillment
            // FulfillmentRequestOrderLineItems = ...
        });
        var fulfillment = await fulfillments.CreateAsync(new FulfillmentShipping
        {
            Message = "items are shipping!",
            FulfillmentRequestOrderLineItems = lineItems,
            NotifyCustomer = false,
            TrackingInfo = new TrackingInfo
            {
                Company = "FedEx",                    
                Number = TrackingNum
            }
        });

    }
nozzlegear commented 6 months ago

Hey @cstone-LF! I'm not sure why your app is crashing silently, I think that's probably related to using async void instead of async Task. You can check here on Stack Overflow for some detailed info on the differences between the two, but generally you almost always want to use async Task.

As for why the app is crashing though, I do have an answer for that! If you're using ShopifySharp v5.19.x, that means ShopifySharp is using version 2022-07 of Shopify's API. Each version of Shopify's API only lasts for one year, and after that they'll shut it down after a grace period. Once it's shut down, it'll start returning a 404 and that will cause ShopifySharp to throw an exception.

I keep a table of ShopifySharp's supported API versions here, but it's not easy to find. I don't have a great way to notify people that they're using an outdated API version, so it's easy to miss this.

To fix the issue, you'll want to upgrade ShopifySharp. Since 5.19 was the last release on the v5 branch, I'd recommend upgrading all the way up to the latest version of ShopifySharp at v6.13.0.

Let me know if you have any trouble with this, I'd be happy to help!

cstone-LF commented 6 months ago

Thank you. I was able to use the latest library (from the NuGet Package) to fill the orders. I couldn't build it from source for some reason, though. I'm just glad it worked from NuGet.