1

We are currently using this code block in an email

%%[
VAR @email, @customer_no, @secret, @url, @hash
SET @email = "%%email%%"
SET @customer_no = "%%customer_no%%"
SET @secret = "<secretkey>"
SET @hash = SHA256(Concat(@email,@customer_no,@secret))
SET @url = Concat("<CompanyURL>?a=",@email,"&amp;c=",@customer_no,"&amp;h=",@hash)
]%%

And vardumping with

%%=v(@email)=%%
%%=v(@customer_no)=%%
%%=v(@secret)=%%
%%=v(@hash)=%%

The url that we get has both the email address and the customer number correctly, but the hash is wrong. Looking at the vardump, the email and customer_no were returning "%%email%%" and "%%customer_no%%" respectively instead of the personalizations. The hash should be "emailcustomer_nosecret" no spaces between.

2

You're mixing inline and block AMPscript. No need for the double-percent notation in your block:

%%[

VAR @email, @customer_no, @secret, @url, @hash
SET @email = AttributeValue("email")
SET @customer_no = AttributeValue("customer_no")
SET @secret = "<secretkey>"
SET @hash = SHA256(Concat(@email,@customer_no,@secret))
SET @url = Concat("<CompanyURL>a=", @email, "&amp;c=", @customer_no, "&amp;h=", @hash)

]%%
  • Ah, I was under the impression that the double-percents were needed for any personalization strings, inside a block or outside. Thanks! – Matt Goldstein Jun 7 '18 at 16:57
0

I'm still not entirely sure why the personalization strings didn't work inside the SHA256 function, but replacing the personalization strings with Lookups made it work.

Final Code:

%%[
VAR @email, @customer_no, @secret, @url, @hash
SET @email = Lookup("DEtest","email","email",_SubscriberKey)
SET @customer_no = Lookup("DEtest","customer_no","email",_SubscriberKey)
SET @secret = "<SECRET KEY>"
SET @hash = SHA256(Concat(@email,@customer_no,@secret))
SET @url = Concat("<URL>a=",@email,"&amp;c=",@customer_no,"&amp;h=",@hash)
]%%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.