I'm looking to make HTTPPost request to send data to an endpoint from a CloudPage from within Marketing Cloud using Ampscript's HttpPost2 function based it's SFMC documentation. For some reason my Boolean variable's value is not being recognized as a true boolean but instead a string even though I am not wrapping quotes around it when I concatenate to build my payload variable.
Can you please review the code below and tell me if there is any way to insert the boolean value within the Concat function without it getting converted to a string.
Note: I posted the ampscript with a dummy api since I can't share our private endpoint
%%[
var @optout, @requestURL, @subscriberKey, @token, @StatusCode, @payload, @httpPost2CallStatus, @httpPost2Response
set @subscriberKey = RequestParameter("SubscriberKey")
IF EMPTY(RequestParameter("optout")) THEN
SET @optout = false
ELSE
SET @optout = true
ENDIF
set @payload = CONCAT('{"Contact":"', @subscriberKey, '",
"Token":"', @token, '",
"optout":', @optout, '}')
set @requestURL = "https://customOptoutApi"
set @contentType = "application/json"
set @StatusCode = HTTPPost2(@requestURL, @contentType, @payload, @httpPost2CallStatus,
@httpPost2Response)
]%%
payload: %%=v(@payload)=%%
<br><br>
response: %%=v(@httpPost2Response)=%%
For output values...here is what I see below including the payload and the response. It appears that the "F" is from the False value which appears to have been converted to a String from the Concatenation.
payload: {"Contact":"0022h00000jz48eZZZ", "Token":"42b95da510cbb3f8b4c874053a298644 q",
"optout":False}
response: [{"errorCode":"APEX_ERROR","message":"System.JSONException: Unexpected character
('F' (code 70)): expected a valid value (number, String, array, object, 'true', 'false' or
'null') at [line:3, column:54]\n\n(System Code)\nClass.ContactMobileUserMD5.getContact: line
11, column 1"}]