-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when creating new product #723
Comments
Thanks for the bug report @flgatormike! This package has unit tests that run with every new release, including ones for creating a new product, and they don't seem to have this issue. Could you possibly post the full exception with stack trace so I can take a look? It might also help if you can post the code you're using to create a product. |
Thanks for the reply! I am trying to create a product by getting a product and just changing the id and title and then creating the product. I have also tried manually building the product. The stack trace is below but it looks like it doesn't step into the relevant code. Any idea what I might be doing wrong?
at ShopifySharp.ShopifyService.<>c__DisplayClass27_0 |
I also just tried copying the code in the unit test and get the same exception:
|
Hmm you're right, that stack trace doesn't really give us anything to go on. Let's take another approach: when ShopifySharp throws an exception, the exception will have a property on it named try
{
product = await service.CreateAsync(product);
}
catch (ShopifySharp.ShopifyException ex)
{
Console.WriteLine(ex.RawBody);
throw;
} |
Hmm, just tested and the ShopifyException isn't thrown, just the standard Exception. |
Ah that's interesting, so it's unlikely to be something related to Shopify's response itself unless it's simply not returning the expected JSON. I think our best bet at the moment is for you to clone this project and include it in your own project directly and see what happens when you debug it. That should at least point you to the source of the problem and hopefully I'll be able to write a fix for it. Let me know if you need any help cloning ShopifySharp and including it in your project! |
Something else to try: I know you've copied the code from the test project and had it break there too, but in the other sample code you provided above it looks like you've got a method named var product = await service.GetAsync(7550715560151);
product.Id = 7550715560133;
product.Title = "TEST";
product = await service.CreateAsync(product); |
Thanks! So it is the response json causing the problem. Could you post that raw result value here? I’ll run it in a unit test and see what happens.
…--
Josh Harms
On Mon, Mar 14, 2022, at 17:12, flgatormike wrote:
so here is where I am getting the error. rawResult looks like it is valid json, but I am getting an error on deserialization: image <https://user-images.githubusercontent.com/47644612/158269343-df36b5d2-edb5-46a5-852d-772b96d8038c.png>
—
Reply to this email directly, view it on GitHub <#723 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASOE7HFWIK3AVNAJO7NSNLU762TTANCNFSM5P4DLBGA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Yes, the problem in the json is the root element. The root of the json is "product" but the code is looking for "products" with an s.. not sure if this mismatch is a problem with the shopify store or my code? |
That would definitely be the source of the problem. The |
"products" (with the s) is coming back from shopify, so maybe this is a problem with the store configuration? |
Below is the code I am using to create a test product, which makes a call to executerequestasync which returns the json below which is a list of products and that is where I am getting the error. Not sure why I am getting a list of products here, and that is where I am getting the error...
{"products":[{"id":7553612677335,"title":"Case OPC-8301-3","body_html"]}} |
When I get orders, I get a root element of "orders" |
Honestly it's very strange behavior. Just to confirm, which version of ShopifySharp are you using? And have you extended the ProductService with your own class/override methods at all? |
No I haven't extended it. The store owner says it is "Store 2.0", could it be something with the way the store was configured? |
Thanks! As far as I know that shouldn't affect anything unless it uses a different version of the API. Which version of ShopifySharp do you have installed in your project? Once we know that we'll know which version of Shopify's API is being used by the package.
…--
Josh Harms
On Mon, Mar 21, 2022, at 09:09, flgatormike wrote:
> Honestly it's very strange behavior. Just to confirm, which version of ShopifySharp are you using? And have you extended the ProductService with your own class/override methods at all?
>
No I haven't extended it. The store owner says it is "Store 2.0", could it be something with the way the store was configured?
—
Reply to this email directly, view it on GitHub <#723 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASOE7ECT2E6F5IWHIF3RQLVBB7IJANCNFSM5P4DLBGA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
So when I call the different ProductService methods, I took a look at the url that is being called in ExecuteRequestAsync. They are all fine except for CreateAsync which is posting to products.json.. the content looks fine, it is posting the product data but the uri doesn't look right. Not sure where that is being set? ProductService > ListAsync ProductService > GetProduct ProductService > UpdateAsync ProductService > CreateAsync |
That shouldn't be an issue, the 2021-10 version we're using right now is still supported until October 2022. I just had a thought though! In the email you sent me earlier today, the shop website you're using looks like the "real" domain but it's not the shop's *.myshopify.com domain.
I think Shopify is redirecting the request to the shop's *.myshopify.com domain by returning a 301 or 302 redirect. The HttpClient might be following that redirect but not preserving the POST method, instead turning it into a GET request which is why Shopify would return a list of products (because listing products and creating a new product both use the same `products.json` endpoint).
Can you try changing your code to use your shop's *.myshopify.com domain?
var service = new ProductService("example.myshopify.com", accessToken);
…--
Josh Harms
On Mon, Mar 21, 2022, at 20:03, flgatormike wrote:
I guess that endpoint is correct for creating a new product, however mine is 2021-10 and the one in the shopify documentation is 2022-01, just a difference of 3 months, that couldn't be my problem could it?
image <https://user-images.githubusercontent.com/47644612/159387091-0aa973ff-8118-4cfb-99e4-da67e247bb98.png>
—
Reply to this email directly, view it on GitHub <#723 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASOE7AYTHWDG5HWYUMYLD3VBEL7RANCNFSM5P4DLBGA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Hey, that worked! Thanks so much! It is strange that the update PUT worked with the other domain but the create POST didn't... |
Awesome, glad to hear it worked! I’m not sure why the put request didn’t break like the post request did, but I think I’ll modify this package to make sure it doesn’t follow redirects in the future. That should help pinpoint this kind of problem more quickly.
Thanks for your patience and for working with me while we debug the problem!
…--
Josh Harms
On Tue, Mar 22, 2022, at 10:05, flgatormike wrote:
Hey, that worked! Thanks so much! It is strange that the update PUT worked with the other domain but the create POST didn't...
—
Reply to this email directly, view it on GitHub <#723 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASOE7GGY7HXRIMW6AJ2SBLVBHOVLANCNFSM5P4DLBGA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
A little note for myself here, I've added an FAQ to the readme that mentions these domain problems. |
I am having a very similar issue, though I have made sure to use *.myshopify.com as the domain. When I try to create a product, I receive back an 'Object reference not set to an instance of an object.' that is being thrown at {T DeserializeWithNewtonsoft[T](System.String, System.String, System.Nullable`1[Newtonsoft.Json.DateParseHandling])}. GETing the products works correctly. This is the first time I have tried to create anything (POST for order, customer, product, etc.). Any ideas? |
@pmartinciibo It sounds like that could be something slightly different then, especially since it's pointing to our special date time serialization attribute. Could you create a new issue for your error, and include the full error message, stack trace and example code if possible? |
This library is great. I can get products, orders, customers, and even update a product, but when I try to create a product using CreateAsync, I get:
"Object reference not set to an instance of an object"
Any idea what the problem might be?
Thanks!
The text was updated successfully, but these errors were encountered: