nodejs中怎么通过调用C4C的Odata服务创建销售订单,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
var request = require('request'); var url = "https://jerry.c4c.saphybriscloud.cn/sap/c4c/odata/cust/v1/zjerrysalesorder"; var getTokenOptions = { url: url, method: "GET", json:true, headers: { "content-type": "application/json", 'Authorization': "Basic ABCDE00ZXN0MQ==", "x-csrf-token" :"fetch" } }; function getToken() { return new Promise(function(resolve,reject){ var requestC = request.defaults({jar: true}); console.log("Step1: get csrf token via url: " + url ); requestC(getTokenOptions,function(error,response,body){ var csrfToken = response.headers['x-csrf-token']; if(!csrfToken){ reject({message:"token fetch error"}); return; } console.log("Step1: csrf token got: " + csrfToken); resolve(csrfToken); }); }); } function createSalesOrder(token, oPostData){ return new Promise(function(resolve, reject){ var requestC = request.defaults({jar: true}); var createOptions = { url: "https://jerry.c4c.saphybriscloud.cn/sap/c4c/odata/cust/v1/zjerrysalesorder/CustomerQuoteCollection", method: "POST", json:true, headers: { "content-type": "application/json", 'x-csrf-token': token }, body:oPostData }; requestC(createOptions,function(error,response,data){ if(error){ reject(error.message); }else { resolve(data); } }); }); } getToken().then(function(token) { var payload = { "Name": "Jerry Test 2019-1-12 19:52PM", "TypeCode": "2059", "BuyerID":"Jerry open ID", "PartyID":"60102", "CustomerQuoteText":[{ "Text": "test comment by Jerry Wang", "TypeCode": "10024" }], "CustomerQuoteItem":[{ "ProductID": "1042416" }], "CustomerQuoteItemProposal":[{ "ProductUUID": "00163E72-09C6-1EE8-BBDC-AC5F0CB0D795", "Quantity": "1", "unitCode": "EA" }] }; createSalesOrder(token, payload).then(function(oData){ console.log("created Sales Order by OData: " + oData.d.results.ID); }); });
关于nodejs中怎么通过调用C4C的Odata服务创建销售订单问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。