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>