Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
the simple jsonString =
{
"product": {
"title": "Some Suit",
"body_html": "You should wear this",
"vendor": "Top Vendor",
"product_type": "Womens Suit",
"status": "draft"
}
}
//The code is using System.Net.WebClient myWebClient
byte[] bytes = myWebClient.UploadData(STORE_URL_PREFIX + @"products.json", "POST", System.Text.Encoding.ASCII.GetBytes(jsonString));
Json_Returned = System.Text.Encoding.ASCII.GetString(bytes);
The headscratcher here is that the Json_Returned is a JSON list of all products that already exist, instead of the single product intended. The new product WASN"T created. I get no error code.
NOTE: The API works fine for getting the full list of products using the GET products.json so I know the api keys are configured correctly.
NOTE: The exact same command + json payload works perfectly on another site I have access to, but doesn't work for this site.
NOTE: The "write_products" permission is assigned
I feel there must be something different about this site that won't let the product be created through the API.
Any help would be appreciated.
Solved! Go to the solution
This is an accepted solution.
I found the problem, although, it seems like a Shopify bug. We had changed the name of the website store name from example "the-store-name" to "the-store" a while back. Keeping this in mind, I changed the URL in my code from:
"https://the-store-name.myshopify.com/admin/api/2023-01/"
to
"https://the-store.myshopify.com/admin/api/2023-01/"
However, unsuspectedly, the URL stayed the same and I didn't notice for a while.
The GET products.json worked just fine, so I assumed all was good with the new URL, but later I ran into the issue in my first post. Once I noticed the URL hadn't actually change, I put the original correct URL in my http call and it worked.
Strange that the GET worked at all with the wrong prefix...
This is an accepted solution.
I found the problem, although, it seems like a Shopify bug. We had changed the name of the website store name from example "the-store-name" to "the-store" a while back. Keeping this in mind, I changed the URL in my code from:
"https://the-store-name.myshopify.com/admin/api/2023-01/"
to
"https://the-store.myshopify.com/admin/api/2023-01/"
However, unsuspectedly, the URL stayed the same and I didn't notice for a while.
The GET products.json worked just fine, so I assumed all was good with the new URL, but later I ran into the issue in my first post. Once I noticed the URL hadn't actually change, I put the original correct URL in my http call and it worked.
Strange that the GET worked at all with the wrong prefix...
We are facing the same issue with one of our stores. The store URL has not been changed but still getting this issue. However, this is working fine for other stores.