cancel
Showing results for 
Search instead for 
Did you mean: 

How to call the credentials to the REST API in "form data" format in the CPI

0 Kudos

Hi all,

Requirement: CPI needs to be connected to the open text API using a username and password to get the token.

Postman: We are passing the username and password in the body of the form-data, and it's working fine.

CPI: According to the SAP blogs below, when we build and test, we receive the error statusCode: 500.

What is form-data and how to send it from SAP Cloud Platform Integration (CPI) | SAP Blogs

The marriage between form-data and SAP Cloud Platform Integration | SAP Blogs

SAP CPI - Forwarding Raw Image Data through Integration Flow | SAP Community

Open Text API: Logs -

Currently, below is the CPI configuration in the Content Modifier - Header and Body

Kindly help me to resolve the issue.

Thanks in advance!

Kannan Selvakumar

Accepted Solutions (1)

Accepted Solutions (1)

Willem_Pardaens
Product and Topic Expert
Product and Topic Expert
0 Kudos

This could be due to the editor using \n as a line break, instead of the \r\n the form data should have. After generating the Body in your Content Modifier, add a Script step in which you do the replacement:

body.replaceAll("\n", "\r\n")
0 Kudos

Thanks for your inputs, did not work, still the same error StatusCode : 500

Answers (5)

Answers (5)

0 Kudos

Thanks to all for your prompt responses, It worked after adding the below script (as recommended in the blogs) after the content modifier. Hence closing the thread.

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");
       message.setBody(body);
       return message;
}
Willem_Pardaens
Product and Topic Expert
Product and Topic Expert

Good that you solved it, but not sure how this differs from the answer I gave you above? 🙂

maik_bosch
Contributor
0 Kudos

kannan1050 I can recommend to use with no business data: https://webhook.site

Here you can do the call from POSTMAN and then in another try the call from CPI to the generated webhook

I guess you will then see some small difference between the working call from POSTMAN and the not working call from CPI. Helped me a lot in the past 🙂

0 Kudos

Hi Maik,

I did not understand the "webhook", could you please help me in little more, how to utlilize this website to overcome the issue.

0 Kudos

anoop-jose - Yes, Credentials are in small letters, Below is the Content Modifier configuration.

0 Kudos

Thanks Anoop, Relpicated the same, No Luck, still the same error - statusCode: 500

anoop-jose
Participant
anoop-jose
Participant
0 Kudos

Hi kannan,

Can you please try boundary as below and check? Since i cant make out the number of "-" in the header. Also the double quotes for Password is missing.

like

Header

Content-Type: multipart/form-data; boundary=SapCPIBoudary12345677END

Body

surajarafath
Contributor

what Anoop mentioned should be correct.

Check your spelling and cases correctly once "username" and "password".