Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Auto apply discount code through Web Pixel: RestrictedUrlError

Auto apply discount code through Web Pixel: RestrictedUrlError

daniel-roster
Shopify Partner
2 0 0

We are trying to migrate from our own injected ScriptTag to the Web Pixel. In our current implementation, we are able ensure a discount code is applied by making a request to `https://{store}.myshopify.com/discount/{code}`. When you are in the checkout page the code will be applied.

However, when using the Web Pixel, that same request throws the following error:
`RestrictedUrlError: Request are not allowed to the same origin`. 

Is there a workaround for this? Or is this intended behavior? We need this functionality for our app.

Reply 1 (1)

Liam
Community Manager
3108 344 899

 

Hi Daniel,

 

Instead of directly making a request to apply the discount code, you can use the Checkout API to apply the discount code programmatically. Using the Checkout API, you can create a new checkout, add items, and apply a discount code with the `applied_discount` property.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog