Pega REST Service Issue accepting/mapping the attachment when Payload is configured as JSON. Works good when payload is XML
In case of Pega SOAP Service, if we send the file as an attachment from SoapUI, Pega process the request and will create OOTB pyRequestAttachmentPage clipboard pageof class Data-ServiceMessage. I believe the content-type in the case is either Multipart/form-data or multipart/mixed. I believe that the attachment is sent in binary form using MTOM mechanism or SOAP with attachments as expalined in below article.
I could able to implement the same above explained thing in Pega REST Service when the payload is given as XML. Unfortunately, I encountered mapping error , when I tried to implement the above (sending file attachment with request) in Pega REST service with JSON Payload.
Tried to configure the Request Header of REST Service as Content-Type=Multipart/form-data. But no luck.
Do we need to configure the Service Rule anything different or do we have any limitation in pega with JSON payload?
You are sending to Pega a "main payload" that is JSON inside of a multipart message that also contains an "attachment."
By choosing "json" as "map to" you are implying that the data in the request can be mapped directly to a clipboard page. I am not positive if this is a supported use case, where Pega is expected to do that with the json Part but process the other Parts differently.
The same request (with multipart/form-data) works perfectly when payload is in XML form and also with Attachment. In this case, In REST-Service rule, I configured the POST method Request tab using XML Parse rule.
Does this mean that, REST-Service Process the mutlipart/form-data differently with different payload types (XML & JSON) ?
If we want to use JSON payload type and needs to accept the attachments, how can we achieve this?
In Soap UI, when we look at the Request Raw tab, I can see that content-transfer-encoding:binary.
Does this mean, the attachment is transferred in binary form and Pega Service will parse that binary into string format by encoding into base64?
if the answer is yes, will the same applies to Connect-REST as well, which means, can we send an attachment to an external service which is capable of multipart/form-data to send request payload in JSON and Attachment in binary form?
Your request is malformed here.the content-type header for your JSON part is "mutlipart/form-data" which is incorrect. It should be application/json.
Even if we give the Content-Type as application/json, Rest-Service is unable to map the incoming request with have both JSON payload and attachment.
Yes, the request on a whole is a multipart message, but this part inside is not a multipart.
Could you please elaborate on this. I didn't completely understood for which part of my question this applies.
Did you meant to say that in case of Connect-REST, whose corresponding external service is capable of accepting mutlipart/form-data, we can send the attachment from pega ( by populating pyRequestAttachmentPage of class Data-ServiceMessage before sending the request) and the attachment will be send in binary form and the other part (meta-data) in JSON format