
Let me start the story with the requirements I had then Ill come to the approach I opted and in the journey it is possible that I may have done some mistakes so I'll add a humble request to all my senior fellow to add there expertise in this blog, This will help everyone to get more insights.
Scenario:
We had to integrate an application which had a requirement to connect to and External AI application that has exposed some API to us with some documentation.
Challenge:
From the initial thoughts this looks easy, it just an API, as so as I thought , but as I mentioned above "documentation" gave us the real challenge. To complete all the call we had to send the multipart/form-data to this receiver.
Through the help of documentations we are able to successfully send the data from Postman. but when we tried to send it from CPI we faced challenges which lead us to the solution. So next I am sharing the steps we performed to send the form-data
Clearly, if such problem arrives instantly we come to SAP community and search for the answer, we found https://community.sap.com/t5/technology-q-a/sending-form-data-from-sap-cpi/qaq-p/12613755 solution that gives us a way and describe what form-data is and how well it can be passed- but solution given here was to change the type of data itself which was not a choice for us.
At least we got half way on understanding the way multipart/form-data will be constructed. To understand more about terms and functionality please refer this wonderful article https://community.sap.com/t5/technology-blogs-by-sap/what-is-form-data-and-how-to-send-it-from-sap-c... by mattisebastian this will help us to create the exact frame of data we need to post and in correct way and how much important the envelope is.
Solution:
To Solve this it is very important to understand the few terms like Content-type, Content Disposition, Accept, Boundary and all the fields that are required in Form data.
To understand this format we had to mimic the Postman request we were directly send to API.
So we created a CPI Artifact to trace the look of the form data and we were able to get the exact same results as in screenshot , but we have to append an actual JSON which had a list of json data in format of string <binary> (File). And that was actually a file upload (that we were doing from postman).
till now if we send request without this JSON file, the AI app was accepting the request but with an error as no real data was found in envelope.
So now we had to find a way to send this file in Realtime to the receiver. and for that we tried various ways like to store the payload in data store and creating Tables and so on.
But issue persisted when we have to send it in Realtime. So to get a bit more Idea we again sent this request from Postman to CPI and traced it.
To get these headers understanding we also put some effort to create Multipart/Form-data from MIME script from the blog https://community.sap.com/t5/technology-blogs-by-sap/part-6-simplify-integration-of-data-from-sap-s-... from divyamary
and we created following results:
So now we know how the file data look like and what part in payload we are missing, as we had to send the binary data we changed the header Content-Transfer-Encoding: 7bit to
Content-Transfer-Encoding: Binary and same goes for file name.
and that's it.. it worked! Just some correction on payload customization and headers and we created multipart/form-data in Content Modifier only.
Briefs and Take-aways:
Following are some key blogs from experts which we referred. a big thank them .
It was just my first blog so it will definitely have some misses, please add you comments and feedback so that ill improve.
Sap community is a Big sea and its just a drop that I added.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
5 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |