I'm using Short.io to shorten personalized URLs in MobileConnect. I have the API working without issue, but I am running into roadblocks while trying to figure out how to log an error to a DE if the API responds with any code other than 200. It seems to me that as soon as a code other than 200 is received, all scripts within the SMS are stopped. Has anyone found a workaround for this?
Here is the example SMS body:
%%[
set @endpoint = "https://api.short.io/links"
set @contentType = "application/json"
set @URLToShorten = "https://google.com"
set @payload = Concat('{"originalURL": "',@URLToShorten,'","domain": "DOMAIN"}')
set @APIKey = "API KEY"
set @headerKey1 = "authorization"
set @headerVal1 = @APIKey
set @surveyName = "SURVEY"
set @currentTime = Now()
SET @request = HTTPPost2(@endpoint,@contentType,@payload,true,@responseJSONStr,@responseRows,@headerKey1,@headerVal1)
set @responseRowCount = rowcount(@responseRows)
/* START - Pulled in from content block */
<script runat="server" language="JavaScript">
/* SSJS to parse JSON payload */
var responseJSONStr = Platform.Variable.GetValue("@responseJSONStr")
var responseJSONObj = Platform.Function.ParseJSON(responseJSONStr);
var shortURL = Platform.Variable.SetValue("@shortURL", responseJSONObj.shortURL);
</script>
/* END - Pulled in from content block */
IF (empty(@URLToShorten) OR empty(@shortURL) OR @request != 200) then
UpsertData("SMS_Survey_ErrorLog",3,
"ErrorDate", @currentTime,
"SurveyName", @surveyName,
"ResponseCode", @request,
"Payload", @payload,
"ResponseJSONStr", @responseJSONStr,
"ResponseRowCount", @responseRowCount
)
ENDIF
]%%
shortURL: %%=v(@shortURL)=%%