Legacy Dev Forum Posts

 View Only

Sign Up

Transform failed to process result using 'successTemplate'

  • 1.  Transform failed to process result using 'successTemplate'

    Posted 06-05-2025 18:42

    jsegil | 2021-04-10 02:44:53 UTC | #1

    Good morning, please support us with the following: I need to convert a part of my JSON Response to a string, and store it in a variable of type string.

    The configuration I currently have is:

    Request Configuration: { "requestUrlTemplate": "requestType": "GET", "headers": { "x-vtex-api-appToken": "${input.x-vtex-api-appToken}", "x-vtex-api-appKey": "${input.x-vtex-api-appKey}", "Content-Type": "application/json" }, "requestTemplate": "${input.rawRequest}" }

    Response Configuration: { "translationMap": { "itemsval": "$.clientProfileData" }, "translationMapDefaults": {}, "successTemplate": "{\"clientProfileData\":$esc.jsonString(${itemsval})}" }

    The result I want is a string like this:

    {\ "clientProfileData \": {\ r \ n \ "email \": \ "jsegil.rodriguez@gmail.com \", \ r \ n \ "firstName \": \ "JUlio \", \ r \ n \ "lastName \": \ "Segil \", \ r \ n \ "document \": \ "12345678 \", \ r \ n \ "documentType \": \ "DNI \", \ r \ n \ " phone \ ": \" + 541111213213 \ ", \ r \ n \" corporateName \ ": null, \ r \ n \" tradeName \ ": null, \ r \ n \" corporateDocument \ ": null, \ r \ n \ "stateInscription \": null, \ r \ n \ "corporatePhone \": null, \ r \ n \ "isCorporate \": false, \ r \ n \ "profileCompleteOnLoading \": false, \ r \ n \ "profileErrorOnLoading \": false, \ r \ n \ "customerClass \": null \ r \ n}

    But when executing my data action: { "message": "Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('\\' (code 92)): was expecting double-quote to start field name\n at [Source: (String)\"{\"clientProfileData\":{\\n \\\"email\\\" : \\\"jsegil.rodriguez@gmail.com\\\",\\n \\\"firstName\\\" : \\\"JUlio\\\",\\n \\\"lastName\\\" : \\\"Segil\\\",\\n \\\"document\\\" : \\\"12345678\\\",\\n \\\"documentType\\\" : \\\"DNI\\\",\\n \\\"phone\\\" : \\\"+541111213213\\\",\\n \\\"corporateName\\\" : null,\\n \\\"tradeName\\\" : null,\\n \\\"corporateDocument\\\" : null,\\n \\\"stateInscription\\\" : null,\\n \\\"corporatePhone\\\" : null,\\n \\\"isCorporate\\\" : false,\\n \\\"profileCompleteOnLoading\\\" : false,\\n \\\"profileErrorOnLoading\\\" : false,\\n \\\"customerClass\"[truncated 13 chars]; line: 1, column: 24]'\n Template:'{\"clientProfileData\":$esc.jsonString(${items_val})}'.", "code": "bad.request", "status": 400, "messageParams": {}, "contextId": "f5527546-1d13-49d0-95ea-a18f0b5aa864", "details": [ { "errorCode": "ACTION.PROCESSING" } ], "errors": [] }

    What would I be missing? I appreciate her support.

    Greetings.


    Jason_Mathison | 2021-04-10 14:45:06 UTC | #2

    HI Julio,

    I think that the forum made some changes to slashes or quotes. Could you repost your action configuration and an example response from the web service. Before posting it, please highlight those sections and hit the "Preformatted Text" button </> to make sure that the forum doesn't make any changes to your configuration.

    --Jason


    jsegil | 2021-04-10 15:47:14 UTC | #3

    Configuration Request:

    Preformatted text { "requestUrlTemplate": "https://xxxxxxxxxxxxx.xxx.com/api/checkout/pub/orderForm/${input.orderFormId}", "requestType": "GET", "headers": { "x-vtex-api-appToken": "${input.x-vtex-api-appToken}", "x-vtex-api-appKey": "${input.x-vtex-api-appKey}", "Content-Type": "application/json" }, "requestTemplate": "${input.rawRequest}" }

    Configuration Response:

    { "translationMap": { "itemsval": "$.clientProfileData" }, "translationMapDefaults": {}, "successTemplate": "{\"clientProfileData\":$esc.jsonString(${itemsval})}" }

    Example execution (error):

    10. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('\' (code 92)): was expecting double-quote to start field name at [Source: (String)"{"clientProfileData":{\n \"email\" : \"jsegil.rodriguez@gmail.com\",\n \"firstName\" : \"JUlio\",\n \"lastName\" : \"Segil\",\n \"document\" : \"12345678\",\n \"documentType\" : \"DNI\",\n \"phone\" : \"+541111213213\",\n \"corporateName\" : null,\n \"tradeName\" : null,\n \"corporateDocument\" : null,\n \"stateInscription\" : null,\n \"corporatePhone\" : null,\n \"isCorporate\" : false,\n \"profileCompleteOnLoading\" : false,\n \"profileErrorOnLoading\" : false,\n \"customerClass"[truncated 13 chars]; line: 1, column: 24]' Template:'{"clientProfileData":$esc.jsonString(${items_val})}'.

    This is the full response frame:

    1. Resolve translation map

    { "items_val": "{\n \"email\" : \"jsegil.rodriguez@gmail.com\",\n \"firstName\" : \"JUlio\",\n \"lastName\" : \"Segil\",\n \"document\" : \"12345678\",\n \"documentType\" : \"DNI\",\n \"phone\" : \"+541111213213\",\n \"corporateName\" : null,\n \"tradeName\" : null,\n \"corporateDocument\" : null,\n \"stateInscription\" : null,\n \"corporatePhone\" : null,\n \"isCorporate\" : false,\n \"profileCompleteOnLoading\" : false,\n \"profileErrorOnLoading\" : false,\n \"customerClass\" : null\n}"}

    I appreciate your support.


    jsegil | 2021-04-10 15:50:42 UTC | #5

    This is the full response frame:

    [9. Resolve translation map]

    { "items_val": "{\n \"email\" : \"jsegil.rodriguez@gmail.com\",\n \"firstName\" : \"JUlio\",\n \"lastName\" : \"Segil\",\n \"document\" : \"12345678\",\n \"documentType\" : \"DNI\",\n \"phone\" : \"+541111213213\",\n \"corporateName\" : null,\n \"tradeName\" : null,\n \"corporateDocument\" : null,\n \"stateInscription\" : null,\n \"corporatePhone\" : null,\n \"isCorporate\" : false,\n \"profileCompleteOnLoading\" : false,\n \"profileErrorOnLoading\" : false,\n \"customerClass\" : null\n}"}

    I appreciate your support.


    Jason_Mathison | 2021-04-12 13:54:20 UTC | #6

    It looks like the "clientProfileData" value is escaped JSON. We currently don't have a built-in tool to unescape the JSON, but I do provide an approach you can try here: https://developer.mypurecloud.com/forum/t/microsoft-dynamics-data-action-problem/10497/4

    --Jason


    jsegil | 2021-04-12 14:38:59 UTC | #7

    Hi Jason, thanks for the reply. My goal is to convert a part of the normal JSON to a variable of type string (JSON Escape), and for that I am using the tool "$esc.jsonString()". But I am unsuccessful because of an error it shows me in the transformation. Would I be missing ?, or is there another tool to escape a normal JSON ?.

    The case you indicated to me is the reverse of what I require.

    Thanks for your help. Julio S.


    Jason_Mathison | 2021-04-12 14:58:05 UTC | #8

    Items_val appears to already be escaped JSON. Try getting rid of the $esc.jsonString()} around it.


    Jerome.Saint-Marc | 2021-04-12 15:03:58 UTC | #9

    Hello,

    I think you can change your configuration response to:

    { "translationMap": { "itemsval": "$.clientProfileData" }, "translationMapDefaults": {}, "successTemplate": "{\"clientProfileData\": \"$esc.jsonString(${itemsval})\"}" }

    Regards,


    jsegil | 2021-04-12 15:42:35 UTC | #10

    Hello Jerome.

    With the changes you indicated, it no longer returns an error. Thank you! it helped me a lot.

    Thank you all.


    system | 2021-05-13 15:42:35 UTC | #11

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 10581