Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Auto apply discount code through Web Pixel: RestrictedUrlError

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}{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)

Shopify Staff
2677 288 737


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 or the Shopify Web Design and Development Blog