1

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)=%%

1 Answer 1

0

According to this Callback Handling for Asynchronous Calls page, at least for the HTTPPost function, it states

If an HTTPPost throws an exception, the system logs an error and stops the process. The system does not retry the call.

If we make the inference that a similar action occurs when you ask for an exception to be raised upon error for the HTTPPost2 function (where it's set to "true" in parameter 4 which "Indicates whether call returns an exception for error"), we can presume it halts the execution of the rest of the script, therefore it will not write anything to the data extension as further defined in your if condition.

HTTPPost does not have a parameter that lets you control whether a system exception is raised, meaning it is raised by default, which explains the need for a note in the documentation, and we can assume the exception thrown between HTTPPost and HTTPPost2 with "true" set, is similar or identical.

I suggest you change that fourth paramter in the @request variable HTTPPost2 call to "false" and see if you are able to capture the failing response and continue executing the rest of the script.

1
  • Thanks for reviewing the issue, Devon. Your fix did the trick! Commented Oct 6, 2023 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .