0

I am using the below code in SMS. However somehow the "+" sign in URL is being converted into %20, which is not being recognized by website.

URL should look like this..

https://abc/apex/ValidateCase?token=JD8XB07if/zK/DcgU3ht3IC4BzRA1WGQFBF9A5R8/ATJyqV/1ma3D+Bho+

But when I click on Bitly Link the final URL look like this

https://abc/apex/ValidateCase?token=JD8XB07if/zK/DcgU3ht3IC4BzRA1WGQFBF9A5R8/ATJyqV/1ma3D%20Bho%20

Here is the code

%%[ 
var @shortenUrl, @bitlyUrl, @link 
set @link = URLEncode(case_link_custom) 
set @bitlyUrl = 'https://api-ssl.bitly.com/v3/shorten?access_token=abcd&longUrl=' 
set @shortenUrl = HTTPGet(Concat(@bitlyUrl,@link,"&format=txt")) 
]%% 
Please click %%=TRIM(@shortenUrl)=%%. Msg&Data Rates May Apply. 4msg/month.

I also tried removing the URLEncode but still the same issue. I did one more test rather using API i just manually pick the url and converted and that works. So seems like it's not Bitly but some of function in Ampscript.

Any suggestion?

1
  • Any suggestion... Anyone ????
    – Sohail
    Commented Aug 5, 2020 at 23:09

2 Answers 2

1

It's a bit hacky, but if you know you have no actual spaces in your case urls, why not just replace '%20' with a URLEncoded plus symbol ("%2B")?

%%[ 
var @shortenUrl, @bitlyUrl, @link

/* Replace %20 in URLEncoded string with %2B */
set @link = Replace(URLEncode(case_link_custom,1,1)'%20','%2B')
set @bitlyUrl = 'https://api-ssl.bitly.com/v3/shorten?access_token=abcd&longUrl=' 
set @shortenUrl = HTTPGet(Concat(@bitlyUrl,@link,"&format=txt")) 
]%%Please click %%=TRIM(@shortenUrl)=%%. Msg&Data Rates May Apply. 4msg/month.

If you do have spaces in your URLs, drop using the URLEncode function and just manually replace all the illegal characters in your URL with their URLEncoded counterparts using the Replace() function, commonly (:/.:,?=&#+).

2
  • No this one also didn't work.The final link is still have %20
    – Sohail
    Commented Aug 6, 2020 at 12:55
  • The issue was actually with the URLEncode function. It accepts another couple of params to correctly URL encode. That's why the replace function couldn't find any %20... The url hadn't been encoded. I've updated the answer adding the two supplementary URLEncode params
    – Macca
    Commented Aug 7, 2020 at 2:36
0

Ok i made it work by

set @link = Replace(URLEncode(case_link_custom),'+','%2B')

Thanks @Macca.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .