這篇文章主要講解了“如何使用nodejs創(chuàng)建Marketing Cloud的contact數(shù)據(jù)”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“如何使用nodejs創(chuàng)建Marketing Cloud的contact數(shù)據(jù)”吧!
創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比正寧網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式正寧網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋正寧地區(qū)。費用合理售后完善,10多年實體公司更值得信賴。
源代碼如下:
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 createContact(token){ return new Promise(function(resolve, reject){ var oPostData = {"CountryCode":"CN", "City":"Chengdu", "FirstName":"Jerry4", "LastName":"Wang2", "PostalCode":"610093", "RegionCode":"", "Street":"天府軟件園", "HouseNumber":"天府軟件園", "DateofBirth":null, "ContactPersonFacets":[ {"Id":"jerry1@sap.com", "IdOrigin":"EMAIL", "Obsolete":false, "Invalid":false}, {"Id":"", "IdOrigin":"PHONE", "Obsolete":false, "Invalid":false}, {"Id":"", "IdOrigin":"MOBILE", "Obsolete":false, "Invalid":false}, {"Id":"", "IdOrigin":"FAX", "Obsolete":false, "Invalid":false} ], "IsConsumer":true, "Filter":{ "MarketingAreaId":"CXXGLOBAL" } }; var requestC = request.defaults({jar: true}); var createOptions = { url: config.createContactURL, 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 { var oCreatedContact = data; console.log("created contact ID: " + oCreatedContact.d.ContactPersonId); resolve(data); } }); }); } getToken().then(createContact).catch((error) =>{ console.log("error: " + error.message); });
這里我把創(chuàng)建的contact的名稱字段硬編碼成Jerry4:
使用nodejs執(zhí)行這個js文件,輸出成功創(chuàng)建的contact guid:
在Marketing Cloud UI上看到這個創(chuàng)建成功的contact:
感謝各位的閱讀,以上就是“如何使用nodejs創(chuàng)建Marketing Cloud的contact數(shù)據(jù)”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對如何使用nodejs創(chuàng)建Marketing Cloud的contact數(shù)據(jù)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!