0

In sms, I want to add the cloud page URL with the dynamic values. When someone click on the URL it redirects to the landing page and data is inserted into the data extension using the lookup function.

What is working, I am able to shorten the dynamic cloud page URL using the bitly API.

Issue: While generating URL shorten using bitly API the data is inserted in the Data extension even when the SMS is previewed. The reason is, while bitly shortening the URL is hit to the cloud page and data is inserted.

Can anyone help with the solution?

<script runat="server" language="ampscript">
   Set @urlToShorten1 = CloudPagesURL(2545, 'identity_identifier', @ii)
    Set @access_token = Lookup("ENT.settings", "bitly_access_token", "selector", "1")
    Set @id_country = "FR"
    Set @group_guid = Lookup("ENT.settings_bitly_guid", "guid", "home_country", @id_country)
    Set @blRequest = Concat("{",char(34),"long_url",char(34),": ",char(34), @urlToShorten1, char(34), ",", char(34),"group_guid",char(34),":",char(34),@group_guid,char(34),"}")
    if (_messagecontext != 'SMS') THEN
    HTTPPost2("https://api-ssl.bitly.com/v4/shorten","application/json",@blRequest,false,@blResp,@dummy,"Authorization",CONCAT("Bearer ",@access_token))
    Endif
    if (IndexOf(@blResp,Concat(char(34),"link",char(34))) == 0) then
        Set @url1 = @urlToShorten1
    else
        Set @temp = Replace(Substring(@blResp,IndexOf(@blResp,Concat(char(34),"link",char(34))),Length(@blResp)),Concat(char(34),"link",char(34),":",char(34)),"")
        Set @blEnd = Subtract(IndexOf(@temp, char(34)),1)
        Set @url1= Substring(@temp,0,@blEnd)
    endif
</script>
3
  • _messagecontext != 'SMS' shouldn't this be testing for equality == ? Commented Aug 4, 2023 at 22:51
  • Correct, Even if I used the _messagecontext == sms, the data is inserted in the DE at the time of sent.....I mean when bitly is created the landing ampscript is running and data is inserted in DE.
    – Jain
    Commented Aug 5, 2023 at 10:05
  • Can anyone please help?
    – Jain
    Commented Aug 12, 2023 at 20:51

0

You must log in to answer this question.

Browse other questions tagged .