How does Shopify encode discount codes in URLs?

Hi, does anyone have an idea about how Shopify encodes discount codes in URLs?

I’m trying to apply a discount through my app by sending a request to the discount URL. However, this approach fails when the discount code contains special characters like “%”

For example,

shopify encodes ‘test%10’ in the URL as:
teststore.myshopify.com/discount/test%252510

‘test%10’ gets encoded as ‘test%2510’

‘test%2510’ gets encoded as ‘test%252510’

It seems like Shopify is double encoding the discount code. Is this intentional?

The % is a reserved character. Dont use it.

I think you misunderstood me. I am not creating discounts; I am only applying the discounts created by merchants through my app. Sometimes, the discount codes contain special characters like %, and I can’t ask them to avoid using such codes since they work fine on the checkout page. I want to know how Shopify encodes them so that I can do the same.

%25 are the escape characters for % in a URL. Its not double escaping it. I’d bet “test%2510” will never work.

teststore.myshopify.com/discount/test%252510
but navigating to the above URL applies the discount correctly

:exploding_head: if thats the case, id just follow the spec and assume that is what Shopify did. You could also create discount codes to test it.