Use Nodejs to consume the Web service on SAP Cloud for customer

Source: Internet
Author: User
Tags glob http post

Jerry used Nodejs to consume the standard webservice provided by C4C in the public article C4C and integrated series tutorials.

See a specific example: C4C individual customers can maintain social user profile, in the public article above Jerry, is to maintain the user's open ID to social users The Socialmediaaccountuserid field of the profile goes as shown.

So what is known as a social profile ID, how can I get that profile by using a Web service Nodejs?

First get the standard query social User profile's web Service to Administrator->input and Output Management->service Explorer:

Https://

Then use the Nodejs module request to send an HTTP POST request to this URL.

You can refer to the source code on my 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", head ERs: {"Content-type": "Text/xml", ' Authorization ': ' Basic ' + new Buffer (CONFIG.CREDENTIAL_QXL). ToS Tring (' base64 ')}, Body: ' <soapenv:envelope xmlns:soapenv= ' http://schemas.xmlsoap.org/soap/envelope/' xml ns:glob= "Http://sap.com/xi/SAPGlobal20/Global" ><soapenv:header/><soapenv:body><glob:                      Socialmediauserprofilerequest_sync> ' + ' <SocialMediaUserProfileSelectionByElements> ' + ' <SelectionBySocialMediaUserProfileID> ' + ' <inclusiOnexclusioncode>i</inclusionexclusioncode> ' + ' <intervalboundarytypecode>1</interval Boundarytypecode> ' + ' <lowerboundarysocialmediauserprofileid > ' + profileID + ' </lowerboun                      Darysocialmediauserprofileid> ' + ' </SelectionBySocialMediaUserProfileID> ' + ' </SocialMediaUserProfileSelectionByElements> ' + ' </glob:socialmediauserprofilerequest_syn  C></soapenv:body></soapenv:envelope> '};  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 =/.*<socialmediauseraccountid> (. *) <\/SocialMediaUserAccountID>.*/; 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 directly using node getsocialmediaprofiletest.js.

The body of the HTTP POST request sent and the response content returned from the console can be observed:

To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:

Use Nodejs to consume the Web service on SAP Cloud for customer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.