nodejs中怎么通過調(diào)用C4C的Odata服務(wù)創(chuàng)建銷售訂單,針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
創(chuàng)新互聯(lián)建站專注于望奎企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城建設(shè)。望奎網(wǎng)站建設(shè)公司,為望奎等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站策劃,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)
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); }); });
關(guān)于nodejs中怎么通過調(diào)用C4C的Odata服務(wù)創(chuàng)建銷售訂單問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。