Order token in receipt

Mark_Gangl
Shopify Partner
5 0 1

Hi,

I'm trying to customize our order receipt so that it generates a 1 time use claim link e.g.

<a href="http://mysite.com/shopify/{{ id }}/{{ token }}">Claim order</a>

However it doesn't look like `{{ token }}` is a supported liquid variable. Do 
you have any recommendations for how else we could achieve this?

Cheers

Becky_Krill
New Member
1 0 0

+1.

0 Likes
Kyle20
Shopify Staff
Shopify Staff
31 0 2

Hi Mark,

At the moment there's no liquid variable to generate any sort of token.

Can you give me a bit more insight as to what you're trying to accomplish here? I'm a bit confused by the url you've used in the example. Are you trying to create a one time use cart permalink? Or something else entirely?

Thanks,
Kyle @ Shopify

Kyle @ Shopify
0 Likes
Mark_Gangl
Shopify Partner
5 0 1

Hi Kyle,

I'm trying to access the `token` property that is exposed via the API. https://docs.shopify.com/api/order#token-property

We want the purchaser to seamlessly claim a digital asset on a separate system. We were thinking that a claim link to the separate system would be the easiest way, but are open to suggestions. We wanted to use the token to make it harder for someone to guess the claim link.

0 Likes
Kyle20
Shopify Staff
Shopify Staff
31 0 2

Hey Mark,

Thanks for clarifying. While the cart and order tokens are accessible via the api, I don't believe it's possible to output either of them with liquid.

That being said, if the store is on a Plus plan and if they're using their own dedicated domain with ssl instead of checkout.shopify.com, then it would be possible to grab the token from cart.js in an ajax request in checkout.liquid.

Using your test store as an example, you can see what I mean by viewing alexs-development-shop.myshopify.com/cart.js i.e. http://take.ms/1KYoG

Hope that helps.

Thanks,
Kyle @ Shopify

Kyle @ Shopify
0 Likes
Mark_Gangl
Shopify Partner
5 0 1

Hi Kyle,

It's a shame that the token is not available in the liquid template. Do you think it would be something that you would add? We were trying to avoid javascript as it seems like that wouldn't work in an email.

0 Likes
Kyle20
Shopify Staff
Shopify Staff
31 0 2

I can't say for sure if or when we'd implement something like that, but for now I'd recommend the javascript option either at checkout or on the cart page and then saving the token as a cart attribute.

Here's a snippet of how to pick up the token via our api.

    {{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' | script_tag }}
    {{ 'api.jquery.js' | shopify_asset_url | script_tag }}

    <script type="text/javascript">

      $(document).ready(function(){
        Shopify.cart = {};

        Shopify.cart.return = function(key, cart_items){

          $.ajax({
            async: false,
            type: 'GET',
            url: '/cart.js',
            dataType: 'json',
            success:  function (data) {
              Shopify.cart.value = data[key];
            }
          });

          if (typeof Shopify.cart.value !== "undefined") {
            return Shopify.cart.value;
          }
        } 

        Shopify.cart.return('token');
        console.log(Shopify.cart.value); // this is your cart token
      });

    </script> 

You won't need jquery if you're using this on the cart page or if it's already been included in checkout.liquid.

Cart attributes are easily accessible in notifications as well as the thank you page.

Thanks,
Kyle @ Shopify

Kyle @ Shopify
0 Likes
Mark_Garity
New Member
2 0 1

Hey Mark Gangl,

You are not alone in trying to use {{ token }} for custom urls in Order Confirmation Emails. We were using exactly this for the last year and {{ token }} worked flawlessly. In the last week or two, shopify decided to kill {{ token }} for seemingly zero reason, and they replaced it with {{ customer_url }} which is a combination of your store account url, and the order token.

The javascript response above doesn't work in emails, so here is the working liquid syntax workaround you can use until Shopify fixes this:

{% assign customer_url_parts = customer_url | split: '/' %}
{{ customer_url_parts[5] }}

It was way easier before to just use the following and I hope shopify decides to restore it:

{{ token }}

 

Mark_Garity
New Member
2 0 1

(EDIT: dupe, wont let me delete this post)

0 Likes
Mark_Gangl
Shopify Partner
5 0 1

Thank you for this!

0 Likes