这篇文章主要讲解了“如何使用nodejs创建Marketing Cloud的contact数据”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用nodejs创建Marketing Cloud的contact数据”吧!
源代码如下:
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); });
这里我把创建的contact的名称字段硬编码成Jerry4:
使用nodejs执行这个js文件,输出成功创建的contact guid:
在Marketing Cloud UI上看到这个创建成功的contact:
感谢各位的阅读,以上就是“如何使用nodejs创建Marketing Cloud的contact数据”的内容了,经过本文的学习后,相信大家对如何使用nodejs创建Marketing Cloud的contact数据这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。