embedding a link from product page

CelloG
Tourist
8 1 1

Hello,

 

I am developing a simple app that will allow me to specify a web link in a product description. Based on initial research, it seems the best way is to use a metafield. I have working code to create the metafield, but I would like to be able to pre-populate the edit box in the app when navigating from the product page of the test store. I can see the product id in the URL, but it is not getting passed to my app at all. Is there any tutorial of setting up context from the product page? I want to edit the field directly on the product page if possible. Everything has been really easy except for the last step, I've spent 2 days fruitlessly searching for the answer to this, and I'm starting to think the only solution is to replicate the entire product creation page in the app? That's not what I want to do...

 

Thanks,

Greg

0 Likes
hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 134

Hi @CelloG ,

 

From reading your post, one thing I need to warn about is that Shopify will prevent you from making Admin API requests (e.g. like creating a metafield for a product) from your front-end online storefront webpage. Shopify will throw a CORS error preventing you from making this API request, and also it is very dangerous to do this because it means that your API Keys and Secrets will be available to anyone who inspects the webpage or opens up the Developer Console in the browser. Any Admin API requests you make must be done on the back-end from your app's server/host.

 

One work around is possible to use the ScriptTag API (https://shopify.dev/docs/admin-api/rest/reference/online-store/scripttag?api[version]=2020-04#create...) so that you can have a Javascript script that sees if information is entered on the product page of your online store and if it is it sends that information to your app's server/host. From there your app can make the API request to create the metafield.

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
CelloG
Tourist
8 1 1

found a workaround: I can just set the metafields directly for all of the products with 

https://<store>.myshopify.com/admin/bulk?resource_name=Product&edit=metafields.links.zoomLink

I've managed to get that into the confirmation email, now I'm struggling with inserting it into the order status page. Will open a new thread for that one.

0 Likes