1

I am trying to create a URL shortener API to SMS.

I follow the instructions of recommendations present in the question 161055 (Is there any way to shorten URL in SMS in Marketing Cloud?).

I am doing almost equal but i always receive and server error and the sms sending fails.

The code that i am using is this:

%%[
var  @shortenUrl, @bitlyUrl, @link
set @link = URLEncode('https://www.example.com')
set @bitlyUrl = 'https://api-ssl.bitly.com/v3/shorten?access_token=ACCESS_TOKEN&longUrl='
set @shortenUrl = HTTPGet(Concat(@bitlyUrl,@link,"&format=txt"))
]%%
%%=RedirectTo(@shortenUrl)=%%

Is it possible that this method is no longer available? Or am i doing something wrong?

Thanks in advance, Pedro Pereira

1 Answer 1

2

The method still works. For SMS, you don't use the RedirectTo() - That's just for tracked links in emails. Simply output the shortened URL:

%%[
var  @shortenUrl, @bitlyUrl, @link
set @link = URLEncode('https://www.example.com')
set @bitlyUrl = 'https://api-ssl.bitly.com/v3/shorten?access_token=replaced&longUrl='
set @shortenUrl = HTTPGet(Concat(@bitlyUrl,@link,"&format=txt"))
]%%
%%=TRIM(@shortenUrl)=%%
8
  • Hi Macca, thanks for the help but unfortunately it didn't work. The same error message appear: "An internal server error has occurred". My Bitly account is the free version, can this be a problem? Commented Jul 10, 2019 at 10:53
  • Yes. That could be a problem, if you've spent all your credits and can't shorten any more URLs. I'd paste your code into an email and send-preview to retrieve what @shortenUrl contains, grab it and paste it into your browser to see what happens. Your code looks pretty good to me and very similar to what I have in a number of SMSs.
    – Macca
    Commented Jul 10, 2019 at 23:25
  • I still could not make a first successful call, so the credits limits is not the problem, Do you know if could be some settings issue? I am a API user. Commented Jul 15, 2019 at 8:30
  • If you place your script in an email, output the @shortenUrl at the bottom of your script ("%%=v(@shortenUrl)=%%"), do a send preview and then place that URL in your browser's address bar, what response do you get from bit.ly?
    – Macca
    Commented Jul 16, 2019 at 1:23
  • 1
    Try getting rid of the actual HttpGet() line in your script and just output the value of shortenUrl and then paste that into your browser to see what the error might be. The line where shortenUrl is set should be changed to this "set @shortenUrl = Concat(@bitlyUrl,@link,"&format=txt")"
    – Macca
    Commented Jul 18, 2019 at 2:58

You must log in to answer this question.

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