cancel
Showing results for 
Search instead for 
Did you mean: 

How to fromat REST payload

davidschievers
Participant
0 Kudos

Hello,

we are facing a problem with REST receiver. We are doing the standard transformation in the REST adapter from XML to JASON. Before this we are doing an mapping for some special fields which are causing this error:

"project":"{\"key\": PLAYCOMPL}",

Does any one knows how we can remove the \ in this payload?

This is the full message after the mapping and after the REST receiver has processed it:

{"CreateIssue_In_MT":{

"project":"{\"key\": PLAYCOMPL}",

"issuetype":"{ \"name\": Complaint}",

"resolution":"{ \"name\": Incomplete}",

"priority":"{ \"name\": Major}",

"summary":"Create Issue Test 2",

"description":"Creating of an issue using project keys and issue type names using the REST API",

"customfield_15513":"[ { \"value\": No}]",

"customfield_15509":"[{ \"value\": TEST}]",

"customfield_15506":"[{ \"value\": TEST}]",

"customfield_15503":"[{ \"value\": Financial Institutions}]",

"customfield_15528":350,

"customfield_15514":351,

"customfield_15529":352,

"customfield_15523":353,

"customfield_15530":"Sales Organization",

"customfield_15525":"Purchase Order Number",

"customfield_15507":"{\"name\": test}]",

"customfield_15512":"TEST",

"customfield_15527":"2018-01-09",

"customfield_15517":"ABCDE",

"customfield_15504":123456,

"components":"{\"name\": TEST}]"}

}

We would need something like this:

{"CreateIssue_In_MT":{

"project":{"key": "PLAYCOMPL"},

"issuetype":{"name": "Complaint"},

"resolution":{"name": "Incomplete"},

"priority":{"name": "Major"},

"summary":"Create Issue Test 2",

"description":"Creating of an issue using project keys and issue type names using the REST API",

"customfield_15513":[{"value": "No}],

"customfield_15509":[{"value": "TEST"}],

"customfield_15506":"[{"value": "TEST"}],

"customfield_15503":[{"value": "Financial Institutions"}],

"customfield_15528":350,

"customfield_15514":351,

"customfield_15529":352,

"customfield_15523":353,

"customfield_15530":"Sales Organization",

"customfield_15525":"Purchase Order Number",

"customfield_15507":{"name": "test"}],

"customfield_15512":"TEST",

"customfield_15527":"2018-01-09",

"customfield_15517":"ABCDE",

"customfield_15504":123456,

"components":[{"name": "TEST"}]}

}

Regards
David

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor
0 Kudos

Hi David!

Frankly speaking, I don't understand why you build your target XML structure this way.

You either build target XML message using tree structure and element names according to your JSON desired structure and let the REST channel convert that XML to JSON or build JSON message using Java or XSLT mapping and don't use any conversion in communication channel at all.

Regards, Evgeniy.

davidschievers
Participant
0 Kudos

Hello,

I know what you mean but this is also not working for us because even if we build the target message in the right format we are still facing the issue with the “”

The REST channel is always putting a double “” into the payload:

“project”:“{\”key\”: \TEXT\”}” but we need “project”: {”key”: “TEXT”} and then there are fields which are okay after the channel converts into JASON. I think for this there is no solution on PI.

Furthermore I am not able to write JAVA or XSLT.

Regards
David

former_member190293
Active Contributor
0 Kudos

Hi, David!

It sounds strange. XML-JSON conversion in REST adapter works pretty well in most cases. Maybe, your target XML structure is incorrect or the channel settings don't fit your requirements?

Regards, Evgeniy.

davidschievers
Participant
0 Kudos

Hello,

you have been right. I rebuild the request JASON structure as an XML (with more Segments) and now it looks quit good.

Regards

David

Answers (3)

Answers (3)

davidschievers
Participant
0 Kudos

Hello all,

the problem is that the REST channel is doing the conversion from XML to JASON and the destination system need to receive some fields in special format.

For example the first filed project needs to have {"key": "PLAYCOMPL"} but the REST channel is converting this to this "project":”{\"key\": \"PLAYCOMPL\"}”,

And then there are also fields which should be send in normal JASON format like this "description":"Creating of an issue using project keys and issue type names using the REST API",

So the payload we would need should look like this for example:

"project":{"key": "PLAYCOMPL"},

"description":"Creating of an issue using project keys and issue type names using the REST API",

Regards
David

former_member190293
Active Contributor
0 Kudos

Hi David!

Wouldn't you please provide your source XML?

"Before this we are doing an mapping for some special fields" - what is your mapping? Is it a graphical mapping, java or xsl transformation?

At first sight, your ussue seems to be described in SAP Note:

2482060 - Additional escape character "\" when converting XML to JSON

This is a standard behavior of system. Jettison Library is adding the extra escape character in order to avoid misunderstanding.

Regards, Evgeniy.

davidschievers
Participant
0 Kudos

Hello,

this is how the source XML looks like:

<?xml version="1.0" encoding="UTF-8"?> <ns0:CreateIssue_Out_MT xmlns:ns0="urn:CreateIssue:100"> <PROJECT>PLAYCOMPL</PROJECT> <ISSUE_TYPE>Complaint</ISSUE_TYPE> <COMP_TYPE>LO02 Labeling error</COMP_TYPE> <RESOLUTION>Incomplete</RESOLUTION> <PRIORITY>Major</PRIORITY> <CUSTOMER>TEST</CUSTOMER> <SUMMARY>Create Issue Test 2</SUMMARY> <RECIEVED>2018-01-09</RECIEVED> <NOTIFICATION>TEST</NOTIFICATION> <MATERIAL>50249665</MATERIAL> <LONGTEXT>Creating of an issue using project keys and issue type names using the REST API</LONGTEXT> <DPR>No</DPR> <DIVISION>Financial Institutions</DIVISION> <REP_QTY>350</REP_QTY> <DLV_QTY>351</DLV_QTY> <RET_QTY>352</RET_QTY> <INT_QTY>353</INT_QTY> <VKORG>Sales Organization</VKORG> <PO>Purchase Order Number</PO> <COMP_OWNER>TEST</COMP_OWNER> <LOCATION>SW Development\/Engineering</LOCATION> <COMPONENT>TEST</COMPONENT> </ns0:CreateIssue_Out_MT>

And this is how the message looks after the mapping:

<?xml version="1.0" encoding="UTF-8"?> <ns1:CreateIssue_In_MT xmlns:ns1="urn:CreateIssue:100"> <project>{"key": PLAYCOMPL}</project> <issuetype>{ "name": Complaint}</issuetype> <resolution>{ "name": Incomplete}</resolution> <priority>{ "name": Major}</priority> <summary>Create Issue Test 2</summary> <description>Creating of an issue using project keys and issue type names using the REST API</description> <customfield_15513>[ { "value": No}]</customfield_15513> <customfield_15509>[{ "value": Labeling error}]</customfield_15509> <customfield_15506>[{ "value": SW Development\/Engineering}]</customfield_15506> <customfield_15503>[{ "value": Financial Institutions}]</customfield_15503> <customfield_15528>350</customfield_15528> <customfield_15514>351</customfield_15514> <customfield_15529>352</customfield_15529> <customfield_15523>353</customfield_15523> <customfield_15530>Sales Organization</customfield_15530> <customfield_15525>Purchase Order Number</customfield_15525> <customfield_15507>{"name": kuessf}]</customfield_15507> <customfield_15512>Raiffeisendruckerei GmbH</customfield_15512> <customfield_15527>2018-01-09</customfield_15527> <customfield_15517>TEST</customfield_15517> <customfield_15504>50249665</customfield_15504> <components>{"name": TEST}]</components> </ns1:CreateIssue_In_MT>

We need to have something like:

"project": {"key": "PLAYCOMPL"}

Regards
David

Ryan-Crosby
Active Contributor

If that is the output of your mapping then you would need to look closer at what you are doing inside your message mapping because it seems you have a combination of XML with JSON embedded.

former_member608139
Active Participant
0 Kudos

could you provide the print used in XML to JSON configuration? Did you trying the configuration below?