1

I coded to upload image (png) to content builder from MC landing page form using HTTP.Post of SSJS. once it done, get file url from response to store in data extension. While using this page, sometimes it throws 500 internal error & every time got same error in safari browser. Anybody faced same kind of issue?

if there is any possible to expired the current accesstoken for user when new hit by other user? even I can't able to show error message in page & just getting 500 internal server error.

    <script runat="server">
        Platform.Load("Core", "1.1.1");
        try{
    </script>

    %%[
        var @body, @callstatus, @response, @obj, 
        set @submit = RequestParameter("submitted") 


        if @submit == "submitted" then 

            SET @body = '{"grant_type": "client_credentials","client_id": "*******","client_secret": "*********"}'
            HTTPPost2("https://mc************8y.auth.marketingcloudapis.com/v2/token", "application/json", @body, True, @callstatus, @response) 

        endif
    ]%% 

    <script type="text/javascript" runat="server">
            var data = Platform.Variable.GetValue('@data');//Base64-encoded string of a file
            var example = Platform.Variable.GetValue('@callstatus');
            var obj = Platform.Function.ParseJSON(example);
            var accessToken = obj.access_token;

            var url = 'https://mc************2y.rest.marketingcloudapis.com/asset/v1/content/assets';
            var contentType = 'application/json';
            var payload = '{"name":"' + ts + '","assetType": {"name":"png","id":28},"file":"' + data + '", "category": { "id": 1****9 }}';
            var headerNames = ["Authorization"];
            var headerValues = ["Bearer " + accessToken];


            try {

                var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
                var resp = Platform.Function.ParseJSON(result.Response[0]);
                var url = resp.fileProperties.publishedURL;

            } catch (exx) {
                Write("Exception Error: " + Stringify(e));

                } 

        } 

    </script>

Getting Exception :

{"message":"An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.","description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nSystem.Net.WebException: The remote server returned an error: (400) Bad Request. - from System\r\n\r\n\r\n\r\n"}

  • 1
    Judging from the fact that it works most of the time, my guess would be that there is something invalid occassionally being passed in the vars ts and data. Since these are included in the payload they are likely causing the error. For example, if the var ts includes an unescaped double quote " in it, this can break the format of the Object you are submitting and cause the Bad Request error. – Gortonington Jun 27 at 13:57
  • @Gortonington, Ts just a firstname of user from form & data is process ' var reader = new FileReader(); reader.readAsDataURL(file);' //Base64-encoded string of a file like /9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAJvAlgDAREAAhEBAxEB/8QAHQABAAEFAQEBAAAAAAAAAAAAAAUBAgMEBgcICf/EAEcQAAIBAwMCBAMFBQYFAwMEAwECAwAEEQUSIQYxBxMiQRRRYSMycYHwCBVCkaEzUrHB0eEWJGJy – Karuppasamy B Jun 28 at 7:27

Your Answer

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

Browse other questions tagged or ask your own question.