SMS Shortlink API応答をペイロードではなくリンクにするにはどうすればよいですか?

Jan 06 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"}}

これは、ampscriptが正しく設定されていることを知るのに最適ですが、ユーザーにこれを見せたくありません。リンクを探しています。だから私はそれがこのようになることを探しています: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>