How to use nodejs to consume Web service on SAP Cloud for Customer
This article introduces how to use nodejs to consume Web service on SAP Cloud for Customer. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Look at a specific example: Individual Customers in C4C can maintain Social User Profile. In the official account article above Jerry, it is to maintain the open ID of Wechat users to the SocialMediaAccountUserID field of Social User Profile, as shown in the following figure.
So now that we know a Social Profile ID, how can we use nodejs to get the Profile details through Web Service?
First, go to Administrator- > Input and Output Management- > Service Explorer to get the web service of the standard query Social User profile:
Https:///sap/bc/srt/scs/sap/requestforsocialmediauserprofi
Then use nodejs module request to send a HTTP post request to the url.
You can refer to my source code on github.
Var request = require ('request'); var config = require (".. /.. / config.js"); function getSocialMediaProfile (profileID) {console.log ("Jerry trace begin * *"); console.log ("url:" + config.socialMediaProfileGetEndPoint); console.log ("config.credential_qxl:" + config.credential_qxl) Var ogetSocialMediaProfileOptions = {url: config.socialMediaProfileGetEndPoint, method: "POST", headers: {"content-type": "text/xml", 'Authorization':' Basic'+ new Buffer (config.credential_qxl) .toString ('base64')}, body:' +'I'+'1' +'+ profileID +'+'}; console.log ("body:" + ogetSocialMediaProfileOptions.body) Console.log ("Jerry trace end * *"); return new Promise (function (resolve,reject) {request (ogetSocialMediaProfileOptions,function (error,response,body) {console.log ("Jerry web service response:" + body); var soapreg = /. * (. *); var soapresult = soapreg.exec (body) If (soapresult.length = 2) {resolve (soapresult [1]);}});});} module.exports = getSocialMediaProfile
Save the above code as a file getSocialMediaProfileTest.js and execute it directly using node getSocialMediaProfileTest.js.
From console, you can observe the body of the HTTP post request sent and the response content returned:
On how to use nodejs to consume Web service on SAP Cloud for Customer to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.