0

The snippet below displays Code Snippetit prints blank. The URL variable is not setting to 'test URL' I have declared the variable @res_code at the top(not visible in snippet) Also I have tried using Platform.Variable.SetValue("@res_code",url); Still it doesn't work

%%[var @payload, @ecn , @res_code ,@res_response 
set @payload = '{
         "CustomerConsent":{
         "firstName":"Mark",
         "lastName":"Smith",
         "userId":"m.smith",
         "applicationId":"1212121",
         "termCondVersion":"0.1",
         "Fcc_disclaimerMsg":"Any disclaimer message shown to the user",
         "pageTitle":"CSS-Web Contact Us Page",
         "PEWC":[
            {
               "phoneNumber":"XXX-XXX-XXX2",
               "type":"Home Telephone",
               "startDate" : "2017-07-24 14:14:31.794",
               "endDate" : "",
               "consent":"Y",
               "reason":"CS"
            }
            ]
      }
}' set @ecn = '234567']%%

<script runat=server language="JavaScript" executioncontexttype="Post" executioncontextname=test>

Platform.Load("core", "1.1.1");

var url = 'https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var contentType = "application/json";
var payload = '{
         "CustomerConsent":{
         "firstName":"Mark",
         "lastName":"mith",
         "userId":"K.smith",
         "applicationId":"1212121",
         "termCondVersion":"0.1",
         "Fcc_disclaimerMsg":"Any disclaimer message shown to the user",
         "pageTitle":"CSS-Web Contact Us Page",
         "PEWC":[
            {
               "phoneNumber":"XXX-XXX-XXX2",
               "type":"Home Telephone",
               "startDate" : "2017-07-24 14:14:31.794",
               "endDate" : "",
               "consent":"Y",
               "reason":"CS"
            }
            ]
      }
}'

var headerNames = ["frms_tid","frms_appid","frms_source","frms_transactiontimestamp","client_id", "client_secret"];
var headerValues = ["123232","9898989","SFMC","2017-07-24 14:14:31.794","XXXX","YYYY"];
var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
Variable.SetValue("@res_code",url);
</script>
<Html lang="en">
<Head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<Body>
<!-- Print URL -->
%%=v(@res_code)=%%
<br>
<br>

</Body>
</Head>
</Html>
  • I preformed a test of my own and was successful. Can you provide a non-image based code example? So, I can insure I am not missing anything. – David Devoy Aug 17 '17 at 20:54
  • @DavidDevoy: I have updated the code in my question above – kunal gidwani Aug 17 '17 at 21:07
2

The following code works. I removed the executioncontexttype and executioncontextname attributes from the script tag. And I fixed the syntax issue with the payload javascript variable. I assume this should be a JSON object and not a string.

%%[var @payload, @ecn , @res_code ,@res_response
set @payload = '{
         "CustomerConsent":{
         "firstName":"Mark",
         "lastName":"Smith",
         "userId":"m.smith",
         "applicationId":"1212121",
         "termCondVersion":"0.1",
         "Fcc_disclaimerMsg":"Any disclaimer message shown to the user",
         "pageTitle":"CSS-Web Contact Us Page",
         "PEWC":[
            {
               "phoneNumber":"XXX-XXX-XXX2",
               "type":"Home Telephone",
               "startDate" : "2017-07-24 14:14:31.794",
               "endDate" : "",
               "consent":"Y",
               "reason":"CS"
            }
            ]
      }
}'
set @ecn = '234567'
]%%

<script runat=server language="JavaScript" executioncontexttype="Post" executioncontextname=test>


Platform.Load("core", "1.1.1");

var url = 'https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var contentType = "application/json";

var payload ={
         "CustomerConsent":{
         "firstName":"Mark",
         "lastName":"mith",
         "userId":"K.smith",
         "applicationId":"1212121",
         "termCondVersion":"0.1",
         "Fcc_disclaimerMsg":"Any disclaimer message shown to the user",
         "pageTitle":"CSS-Web Contact Us Page",
         "PEWC":[
            {
               "phoneNumber":"XXX-XXX-XXX2",
               "type":"Home Telephone",
               "startDate" : "2017-07-24 14:14:31.794",
               "endDate" : "",
               "consent":"Y",
               "reason":"CS"
            }
            ]
      }
};
/*
var headerNames = ["frms_tid","frms_appid","frms_source","frms_transactiontimestamp","client_id", "client_secret"];
var headerValues = ["123232","9898989","SFMC","2017-07-24 14:14:31.794","XXXX","YYYY"];
var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
*/
Variable.SetValue("@res_code",url);
</script>
<Html lang="en">
<Head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<Body>
<!-- Print URL -->
%%=v(@res_code)=%%
<br>
<br>

</Body>
</Head>
</Html>
| improve this answer | |
  • one additional question. Now that i am triggering HTTP.Post i am getting the following error: " Error Message: Unable to retrieve security descriptor for this frame. Line: 1768 Char: 8 responseDetails.StatusCode = Platform.Function.HTTPPost(url, contentType, payload, headerNames, headerValues, response) Description: An unexpected error occurred during the execution of the page." Do you know what the security descriptive error is? – kunal gidwani Aug 17 '17 at 22:41
  • As you may see in the code snippet above..my Header contains the Clientid and secret. Not sure what the security descriptive error is – kunal gidwani Aug 17 '17 at 22:47
  • You may need to post a new question. Have you been able to make a successful API call? When I've done this in the past, it has required 2 call. First API call to request a Token using the ClientID/ClientSecret. Second API call will include the returned Token as a parameter. – David Devoy Aug 23 '17 at 21:17
  • Can you please share the example of the 2 calls you are referring to. I am still facing issues with the call @DavidDevoy – kunal gidwani Aug 23 '17 at 22:33
  • @kunalgidwani you can refer to the online documentation to request a token. developer.salesforce.com/docs/… – David Devoy Aug 31 '17 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.