페이로드가 아닌 링크로 SMS Shortlink API 응답을 받으려면 어떻게해야합니까?

Jan 07 2021

아래 코드를 사용하고 있습니다 (예 : 스택 교환 링크 사용).

%%[ 
    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)
    ]%%

모든 것이 작동하지만 다음과 같은 성공 응답을 받고 있습니다.

{"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"}}

내 앰프 스크립트를 올바르게 설정했음을 아는 것이 좋지만 사용자가 이것을 보지 않기를 바랍니다. 링크를 찾고 있습니다. 그래서 나는 다음과 같은 것을 찾고 있습니다.https://cutt.ly/repko-testing-741599999

간단한 해결책이있는 것 같은데 이번이 처음이라서 지금 다음 단계가 뭔지 잘 모르겠습니다.

답변

2 JasonHanshaw Jan 07 2021 at 00:38

JSON 응답을 구문 분석하고 채우려는 값을 선택해야합니다. 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>