I was trying to fire an event from the cloud page below is the code and i am getting 500 error
<script runat=server language="JavaScript">
Platform.Load("core","1");
HTTPHeader.SetValue("Access-Control-Allow-Methods","POST");
HTTPHeader.SetValue("Access-Control-Allow-Origin","*");
if (Request.Method == "POST"){
Variable.SetValue("@request_method", "POST");
}else{
Variable.SetValue("@request_method", "GET");
}
</script>
%%[
Var @body, @callstatus, @response,@accessToken
IF @request_method == 'POST' THEN
SET @token = RequestParameter('token')
SET @email = RequestParameter('email')
SET @is_valid_email = IsEmailAddress(@email)
IF @is_valid_email == 'True' THEN
SET @user_id = RequestParameter('userid')
SET @does_user_exist = Lookup("extension lookup", "UserId", "UserId", @user_id)
IF EMPTY(@does_user_exist) THEN
SET @accessToken = CONCAT('Bearer ', @token)
SET @body = '{"ContactKey": "[email protected]", "EventDefinitionKey":"APIEvent-123456789", "EstablishContactKey": "true","Data": { "UserId":"147568","Email":"[email protected]" , "PhoneNumber":"6475552102" , "FirstName":"Karam123" , "LastName":"sialka123" , "ConfirmEmailOptIn":"true" , "ConfirmedTerms":"true" , "Language":"en-ca" , "Hash":"1455855667","link":"www.google.com"}}'
HTTPPost("https://subdomainofcompany.rest.marketingcloudapis.com/interaction/v1/events", "application/json", @body, @callstatus, 'Authorization', @token)
SET @return_msg = '{"status": "ok", "message": "event fired and Record added"}'
Output(v(@return_msg))
ELSE
SET @return_msg = '{"status": "not ok", "message": "userid already exist"}'
Output(v(@return_msg))
ENDIF
ELSE
SET @return_msg = '{"status": "not ok", "message": "invalid email"}'
Output(v(@return_msg))
ENDIF
ELSE
Redirect('google.com')
ENDIF
]%%
Many thanks!
RequestParameter()
functions with constants (string values) then paste this block in an email, preview the email for a Subscriber record and see what error is returned.