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

Order Metafields #1083

Open czupet opened 2 months ago

czupet commented 2 months ago

Is there a way to add Metafields to an order?

Diceble commented 2 months ago

Maybe you could elaborate a bit more on how you are using Shopifysharp now. Do you want the GraphQL API to update your order with a metafield or are you using the RestAPI? Did you try adding Metafields and didn't it work?

czupet commented 2 months ago

This is what I am doing today, I would like to change it to ShopifySharp, GraphQL would be great since they are moving towards that.

   var client = new HttpClient();
   var request = new HttpRequestMessage(HttpMethod.Put, $"https://{Username}:{Password}@{storeName}.myshopify.com/admin/api/2024-07/orders/{metaFields.Order.Id}.json");
   request.Headers.Add("Authorization", $"Basic {base64EncodedCredentials}");
   var content = new StringContent(meta, null, "application/json");
   request.Content = content;
   HttpResponseMessage response = await client.SendAsync(request);
   response.EnsureSuccessStatusCode();
Diceble commented 2 months ago

Am I correct in assuming you send credentials on every request? and the code you showed is this dev or prod code? Besides that. I'd think you should just give a look at this (https://github.com/nozzlegear/ShopifySharp/wiki/Orders) to see how shopifysharp currently handles orders. If you do want to use graphQL I'd say read upon some documentation of Shopify itself and see what kind of request you need to make. Most likely you'll end up writing some mutation.