溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

nodejs中怎么對contact主數(shù)據(jù)進行修改

發(fā)布時間:2021-07-21 10:06:19 來源:億速云 閱讀:167 作者:Leah 欄目:web開發(fā)

本篇文章給大家分享的是有關(guān)nodejs中怎么對contact主數(shù)據(jù)進行修改,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

代碼如下:

var config = require("./mcConfig");var request = require('request');var url = config.tokenURL;console.log("user: " + config.user + " password: " + config.password); 
var getTokenOptions = {        url: url,        method: "GET",        json:true,     
        headers: {            'Authorization': 'Basic ' + new Buffer(config.user + ":" + config.password).toString('base64'),            "content-type": "application/json",            "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: " + error});          return;
       }       console.log("Step1: csrf token got: " + csrfToken);
       resolve(csrfToken);
      }); 
     });
}function updateContact(token){    return new Promise(function(resolve, reject){        var sPostData = "--batch_1f7d-bd35-caed" + "\n" + 
  "Content-Type: multipart/mixed; boundary=changeset_8f9e-9a44-9f9e" + "\n" + 
  "\n" + 
  "--changeset_8f9e-9a44-9f9e" + "\n" + 
  "Content-Type: application/http" + "\n" + 
  "Content-Transfer-Encoding: binary" + "\n" + 
  "\n" + 
  "MERGE Consumers('02000A21209F1EE99CDF1A1FC9AA8065')?sap-client=100 HTTP/1.1" + "\n" + 
  "Cache-Control: max-age=360" + "\n" + 
  "sap-contextid-accept: header" + "\n" + 
  "Accept: application/json" + "\n" + 
  "Accept-Language: en" + "\n" + 
  "DataServiceVersion: 2.0" + "\n" + 
  "MaxDataServiceVersion: 2.0" + "\n" + 
  "x-csrf-token: fQ2Pwfmf0K_LVYoKV9QYUw==" + "\n" + 
  "Content-Type: application/json" + "\n" + 
  //"Content-Length: 215" + "\n" + 
  "\n" + 
  "{\"YY1_CustomerType_ENH\":\"Jerry測試1\"}" + "\n" + 
  "--changeset_8f9e-9a44-9f9e--" + "\n" + 
  "\n" + 
  "--batch_1f7d-bd35-caed--";        var requestC = request.defaults({jar: true});    var createOptions = {              url: config.updateContactURL,              method: "POST",              json:false,              headers: {                  "content-type": "multipart/mixed;boundary=batch_1f7d-bd35-caed",                  'x-csrf-token': token
              },              body:sPostData
        };
        requestC(createOptions,function(error,response,data){            if(error){
                reject(error.message);
            }else {               debugger;               console.log("Contact updated successfully");
               resolve(data);
            }
        });
    });
}
getToken().then(updateContact).catch((error) =>{  console.log("error: " + error.message);
});

我在nodejs代碼里把需要更改的字段值賦為"Jerry測試1”:

執(zhí)行之后這個屬性被成功更新了:

nodejs中怎么對contact主數(shù)據(jù)進行修改

以上就是nodejs中怎么對contact主數(shù)據(jù)進行修改,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI