1

I am using the code below (just using stack exchange link for example):

%%[ 
    var @Id, @shortenUrl, @cuttlyUrl, @link, @linkName
    set @startDate = "2021-01-01 6:45 AM"
    set @endDate = Now(1)
    set @numOne = 100000
    set @numTwo = 99999
    set @randNum = random(@numOne,@numTwo)
    set @time = dateDiff(@startDate, @endDate, "MI")
    set @linkName = concat('repko-testing-',@time,@randNum)
    set @link = 'https://salesforce.stackexchange.com/questions/122185/ampscript-in-sms-how-to-use-dynamic-content-in-sms-with-ampscript-mobileconne'
    set @cuttlyUrl = Concat('https://cutt.ly/api/api.php?key=[key]&short=',@link,'&name=',@linkName,'&format=txt')
    set @shortenUrl = HTTPGet(@cuttlyUrl)
    ]%%

Everything is working, but I am receiving a success response like below:

{"url":{"status":7,"fullLink":"https:\/\/salesforce.stackexchange.com\/questions\/122185\/ampscript-in-sms-how-to-use-dynamic-content-in-sms-with-ampscript-mobileconne","date":"2021-01-06","shortLink":"https:\/\/cutt.ly\/repko-testing-741599999","title":"marketing cloud - AMPScript in SMS - How to use dynamic content in SMS with AMPScript? MobileConnect - Salesforce Stack Exchange"}}

Which is great for knowing that I've setup my ampscript correctly, but I don't want the user seeing this. I'm just looking for the link. So I'm just looking for it to be like this: https://cutt.ly/repko-testing-741599999

I feel like theres a simple solution, but this is my first time doing this so I'm not sure what the next step is now.

1 Answer 1

2

You need to parse the JSON response and select the value that you are looking to populate. You can do this fairly easily with SSJS:

<script runat="server">
Platform.Load("Core", "1");

/* GET HTTPGET RESPONSE */
var jsonResp = Platform.Function.ParseJSON(Platform.Variable.GetValue("@shortenUrl"));

/* GET SHORT LINK VALUE FROM RESPONSE */
var shortLink = jsonResp.url.shortLink;

/* OUTPUT VALUE OR ASSIGN TO AMPSCRIPT VARIABLE*/
Write(shortLink);
Platform.Variable.SetValue("@shortLink",shortLink);
</script>
1
  • Thank you! After some googling around I was getting close to this but I couldn't put all the pieces together.
    – en-rep
    Jan 6, 2021 at 17:48

You must log in to answer this question.

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