Requirement -:
We need to Pass JSON Payload from one CloudPage to JSON Code resource via HTTPPOST AMPscript method and need to execute Final HTTPPOST2 function on JSON code resource to send that payload to an external API at backend to improve Performance of Thank you Page loading on web-form submission.
We are going with this approach as we need to call External API call using HTTPPOST2 ampscript function via JSON code resource to quick load of Thank you Page
Solution we are trying
So there will be 3 Components as below
- Web-form (main-cloudpage)
- Thank you Page (Landing-Page with HTTPPOST ampscript to post payload to Json code resource)
- JSON (Code resource to process final HTTPPOST2 call to external api-endpoint
Code on webform
HTML FORM with Post method we are posting FirstName , LastName and Email values entered in Web form
Code on thank you Page (Cloduapge)
%%[
set @FirstName = RequestParameter('FirstName')
set @LastName = RequestParameter('LastName')
set @email = RequestParameter('email')
set @authurl = "https://staging/SampleEndpoint/"
set @@payload = Concat('{"FirstName": "',@FirstName,'","LastName": "',@LastName,'","Email": "',@email,'"}')
set @key = "xxxxxxxxx-secret-key"
SET @httppost = HTTPPost(CloudPagesURL(1267),"application/json",@payload, @resp, 'Accept-Encoding', 'identity')
]%%
Code on JSON code resource
%%[ set @JSON = HttpGET("https://URL-of-thankyou-cloudPage/thank-you") ]%%
<script runat="server">
Platform.Load("Core", "1")
// get JSON from ampscript
var jsonObj = Variable.GetValue("@JSON");
var obj = Platform.Function.ParseJSON(jsonObj);
var Fname = obj.FirstName;
var Lname= obj.LastName;
var email= obj.Email;
Platform.Variable.SetValue("@Fname",Fname);
Platform.Variable.SetValue("@Lname",Lname);
Platform.Variable.SetValue("@email",email);
</script>
%%[
set @FirstName = @firstnamee
set @LastName = @Lname
set @email = @email
set @authurl = "https://staging/SampleEndpoint/"
set @@payload = Concat('{"FirstName": "',@FirstName,'","LastName": "',@LastName,'","Email": "',@email,'"}')
set @key = "xxxxxxxxx-secret-key"
SET @httppost = HTTPPost2(@authurl,"application/json",@payload,false,@apistatusCode,@respheader,"Key",@key)
]%%
**Issue / challenges **
- We are not able to Pass JSON payload from One Cloud page to JSON code resource
- We are not able to Parse JSON on JSON code resource
Additional Query
- Can we directly pass JSON PAyload from cloudpage to code resource and directly use that Payload in HTTPPOST2 AMPScript function ?