Technical Articles
SAP PI/PO Salesforce integration: PATCH Requests with REST Adapter
This blog tackles a small hurdle that you might come across when your aim is to integrate an SAP system with Salesforce (SFDC) using SAP PI/PO as a middleware.
I was tasked to develop an S/4 to SFDC integration on PO using the SFDC REST API. That API is strongly making use of the http PATCH operation. This short blog explains two ways to achieve this.
Problem
In case you’re on an older PO version before 7.50 SP09, the REST adapter doesn’t support this HTTP operation:
Operations of REST Receiver Adapter in the NWDS GUI
The Integration Directory (IB or NWDS) GUI doesn’t list the PATCH request as an option.
Solutions
There are two solutions to this:
- Since SP09 of PO 7.50, it is possible to issue PATCH calls in a REST receiver channel by setting an adapter module parameter (of module sap.com/com.sap.aii.adapter.rest.app/RESTAdapterBean). Unfortunately, the method was not added to the GUI, as shown above. Nevertheless, you can configure the following module parameter to enable the PATCH method in the REST receiver adapter (excerpt from SAP note 2498897 (S-user log-in required)):
Parameter Name: overrideHttpMethod
Parameter Value: PATCH Also add the following parameters (as per note 2483432)
Parameter Name: useSAPHttpLibrary
Parameter Value: apacheBy doing this, you switch the http client library from SAP’s native to the one form Apache.
- Now there is another and easier option you can use in case your system is not yet on the required SP level or you maybe face other issues with the Apache library. The trick is pertaining to Salesforce (and obviously can’t be used with other receivers than that). It is applied by simply adding the parameter ?_HttpMethod=PATCH to the target URL, and selecting POST as the HTTP operation in the channel.Quoting from the SFDC docs:
If you use an HTTP library that doesn’t allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter _HttpMethod.
Conclusion
Although No. 2 is a proprietary feature of a third party vendor and SAP offers a way on patched PI/PO systems to achieve the same with their own means, it might still help the developers which are facing the above mentioned restrictions, or would like to avoid setting the adapter module parameter.
If you have questions or remarks, let me know in the comments.
Thank you,
Philippe Addor
Good blog, we use the Advantco SFDC adapter to integrate with salesforce. It isn't cheap but it makes it easier.
I have to say that the Salesforce documentation is very good. Comprehensive.
Thanks for your comment. Yes that's right. And there's by the way another issue when using the standard REST adapter instead of the third-party one: token caching. The built in mechanism doesn't work with Salesforce because the server doesn't response with the "expires_in" header that PO's REST adapter seems to require to do the caching. I have written an adapter module that takes over this part too. Might post it in another blog later on.
Hi Philippe,
We are exactly facing the token caching issue in our production PI 7.5 system on the integrations with Salesforce. Can you please provide the adapter module details to fix this issue.
Thanks,
Sarat
Hi Sarat,
Here is the link to the github repository which contains the adapter module code: https://github.com/fippu82/sap-xpi-adapter-module-add-dynamic-configuration
Hope you can make it work.
Philippe
Hi Philippe
Great hack.
How about just set PUT in the dynamic properties.
Hi Daniel,
Thanks for your comment.
Do you mean PATCH or really PUT? I'm not sure, but I don't think we could overwrite the http Operation (e.g. POST) that is set by the REST adapter, or could we?
Philippe
yes
Hello Philippe Addor
I implemented the first solution, I see that PO puts PATCH, but I am getting the below errors. Can you please let me know if you have any ideas?
MP: exception caught with cause java.lang.RuntimeException: Error while overriding HTTP operation:
Exception caught by adapter framework: Error while overriding HTTP operation:
Thank you
BR,
Aleksandrs
Hi Aleksandrs, sorry for the late reply, I was not notified about your comment. I can't tell why this error occurs, I'm sorry. Did you find it out in the meantime?
Where do you see that PO puts the PATCH operation?
Hi Aleksandrs,
Did you figure out this, I am also facing the same issue.
Thanks!
Sonu
Hi Philippe,
I have used the first solution but gettign HTTP override exception and the 2nd solution which you mentioned is not clear is it possible to pass the HTTP operation via Query string? if yes could please share the information how to implement in the Receiver REST adapter
Hi Vishnu, sorry for the late reply, I wasn't notified about your comment. Yes it works with the query string, but pay attention that this is only for Salesforce!
Hi Philippe,
We are currently facing the token caching issue in our production PI 7.5 system on the integrations with Salesforce. Can you please provide the adapter module details to fix this issue.
Thanks,
Sarat
Hi Sarat,
Here is the link to the github repository which contains the adapter module code: https://github.com/fippu82/sap-xpi-adapter-module-add-dynamic-configuration
Hope you can make it work.
Philippe
Hi Philippe,
Even I have similar requirement and with the option one getting error as below:
MP: exception caught with cause java.lang.RuntimeException: Error while overriding HTTP operation:
Exception caught by adapter framework: Error while overriding HTTP operation:
Transmitting the message using connection SOAP_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.lang.RuntimeException: Error while overriding HTTP operation:
Could you please help.
Thanks!
Sonu
Hi Sonul, I assume you're using the REST receiver adapter and added the module parameter, right? can you add a screenshot of your configuration?
Hi Philippe,
Yes we are using REST receiver adapter, please find screenshot attached,
Thanks!
Sonu
Module Parameter
Comm Channel
You're right, I tested it and it doesn't work anymore for me neither on an SP 22 system. I assume it's a bug. Because the log correctly shows "Calling server: PATCH https://..." after adding the module parameter. But the error still occurs. I suggest to open an OSS support ticket with reference to note 2498897.
Since I went for option 2 (with Successfactors), I didn't realize that option 1 doesn't work (anymore).
Best regards,
Philippe
Thanks for quick response Philippe. Yes we are on SP22 and also raise the OSS to SAP, let's see what they come up with.
Thanks!
Sonu
Ok thank you Sonu! I would appreciate it if you could update us here once you have a response.
I think I found the problem! We need to tell the adapter explicitly to change to the Apache library! Like that it works. Just add a second parameter:
Name: useSAPHttpLibrary
Value: apache
Hope it helps.
Yes Philippe!