Skip to Content
1
Jun 25, 2020 at 05:08 AM

How to use Key and Value in Body in SAP CPI/HCI

1232 Views Last edit Jun 25, 2020 at 06:18 AM 3 rev

Hi ,

I have a requirement - where i need to send create csv file based on incoming message - But file will be created in API only when we use the keys and value (used in Body).belwo is the screenshot where we are directly uploading the file from postman to API

Here dataFile is the file.

I have gone thru the blogs

https://blogs.sap.com/2019/11/14/what-is-form-data-and-how-to-send-it-from-sap-cloud-platform-integration-cpi/

https://blogs.sap.com/2018/02/09/the-marriage-between-form-data-and-sap-cloud-platform-integration/

and tried below in content modifier in Body :

content Modifier - header and Body

--cpi Content-Disposition: form-data; name="datafile"; filename="anurag.csv" Content-Type: application/vnd.ms-excel ${property.body} --cpi Content-Disposition: form-data; name="cmisaction" createDocument --cpi Content-Disposition: form-data; name="propertyId[0]" cmis:objectTypeId --cpi Content-Disposition: form-data; name="propertyValue[0]" cmis:document --cpi Content-Disposition: form-data; name="propertyId[1]" cmis:name --cpi Content-Disposition: form-data; name="propertyValue[1]" Anurag4 --cpi--

and after that i hava e used the groovy script :

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

def Message processData(Message message)

{ //Body def body = message.getBody(String); body = body.replaceAll("\n", "\r\n");

body = """--cpi\r\nContent-Disposition: form-data; name="envelope"\r\n\r\n\r\n""" + body + """\r\n\r\n--cpi--""" message.setBody(body); return message; }

when i checked in trace i am getting result like :

and after that error is - 405 method not alowed

Attachments

m09wf.png (18.8 kB)
o4yvi.png (16.0 kB)
6dr2v.png (20.5 kB)
cgjdr.png (21.8 kB)
4m9mt.png (21.7 kB)
bmyyx.png (17.2 kB)
52jap.png (31.4 kB)
vs8lq.png (14.9 kB)