ndimatteo / HULL

💀 Headless Shopify Starter – powered by Next.js + Sanity.io
https://hull.dev
MIT License
1.36k stars 167 forks source link

Shopfiy snyc verification failed after changing Shopify Store URL #113

Closed ansmlc closed 1 year ago

ansmlc commented 1 year ago

Hi,

Client is switching to a different Shopify Store (new URL). I've changed the appropriate ENV variables in Vercel with new API keys, including the new signature verification string.

The issue:

But when I try to manually update or delete a Shopify product, Vercel functions gives error "Unable to verify from Shopify".

On the other hand, I'm seeing a GET method in the function log show up on their own without error, and I'm seeing the new products show up in Sanity Studio.

[GET] /api/shopify/product-inventory?id=6992490299481
15:53:28:90
[GET] /api/shopify/product-inventory?id=6992449437785
15:53:27:16

[POST] /api/shopify/product-delete
15:46:37:49
2022-11-28T14:46:38.466Z    a99547a4-b63f-495a-aedf-518b0be6469d    ERROR   Unable to verify from Shopify

Side-question: The new Shopify Store has all the products data cloned and identical to previous Store, but product IDs seem to have changed. At the same time, Sanity Studio already contains the products from before, along with a lot of custom content added via Studio, tied to those products.

So now we have duplicate products in the Studio, with and without Sanity-added custom content. Is there a way to make Sanity Studio automatically merge these products, so that content doesn't have to be re-added?

ndimatteo commented 1 year ago

Hey there @ansmlc,

I'm not sure exactly what's going on here, but if you changed stores completely, the old products are not going to be related to the new store. You'll want to remove any Sanity documents associated with the old products and let the new store sync it's products into Sanity. Any subsequent changes to the new products in Shopify will update automatically in Sanity.

Let me know if that makes sense!

ansmlc commented 1 year ago

Hi @ndimatteo

Here is an example from the functions log, showing ERROR Unable to verify from Shopify:

image

The manual product update/create fails every time, as shown above. However, some products did sync, somehow. I'm wondering if it's because of theapi/shopify/product-inventory , which appears in functions log seemingly at random:

[GET] /api/shopify/product-inventory?id=6992490299481
15:53:28:90
[GET] /api/shopify/product-inventory?id=6992449437785
15:53:27:16 

Not sure why it synced some products, and other not.

This was the migration process so far:

This is what else is expected to happen:

Does the Vercel production branch need to be deployed with latest Git changes that include new ENV variables and Shopify Store ID in Sanity config files, in order for this Shopify sync to work?

I did update env. variables in Vercel, but did not actually deploy the production code yet. I'm trying to refrain from re-deploying the production branch until the client properly migrates content in Studio to the newly synced products from new Store.

ansmlc commented 1 year ago

The problem was the production branch was not deployed with new changes (we were intentionally avoiding this), so the Shopify signature verification key did not match. I mistakenly assumed that it was enough to merely update this key in Vercel env. variables.

Fixed by deploying a dev (preview) branch with the latest update from local, and changing Shopify Webhooks to preview-build URLs. Now the Sanity products are successfully synced when updated. Once the content migration is finished, I'll just update the production build and add production URL back to Shopify webhooks.

ansmlc commented 1 year ago

Hi @ndimatteo since we migrated to a new Shopify Store with same products, the client wanted to keep the "old" products content in Sanity while they copy-paste it to the newly-sourced products form the new Shopify instance.

The issue now is we have duplicate products. We can't publish the new ones because of "slug already exists" error, and we can't delete the old ones because "this document is referenced elsewhere". I tried deleting the references, but that didn't help. I also tried deleting the products via Sanity CLI but that produces the same error.

It seems to be related to this issue: https://github.com/sanity-io/sanity/issues/1850

I also tried converting the reference fields to weak: true; but that doesn't update the existing references. I'd appreciate any advice on how to go about removing the old, duplicate products from Sanity Studio.

ndimatteo commented 1 year ago

Hey there @ansmlc if Sanity is not allowing you to delete products due to existing references, I usually try to delete those references first. They should give you some indication of where those exist, and once you remove all of them and publish those changes, you will be able to remove the old products.

I'd start by removing them from any Collection pages, as well as any links to those products from other areas of the site.

Once that is all done the new products should sync in just fine!