使用nodejs实现OData的batch操作在Marketing Cloud里读取contact信息
生活随笔
收集整理的這篇文章主要介紹了
使用nodejs实现OData的batch操作在Marketing Cloud里读取contact信息
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
我們先來看看Marketing Cloud系統(tǒng)里的contact信息: 一共1218374條數(shù)據(jù)。
我們用如下的nodejs代碼通過OData來獲取這些數(shù)據(jù):
var request = require('request'); var config = require("./mcConfig");var url = config.getContactBatchURL;var sBody = "--batch_c914-a60c-1877" + "\n" + "Content-Type: application/http" + "\n" + "Content-Transfer-Encoding: binary" + "\n" + "\n" + "GET InteractionContacts?sap-client=100&$skip=0&$top=2&$select=ImageURL%2cName%2cContactLevelName%2cCountryName%2cCity%2cEMailAddress%2cPhoneNumber%2cMobilePhoneNumber%2cCorporateAccountName%2cInteractionContactUUID%2cRelationship%2cType&$inlinecount=allpages HTTP/1.1" + "sap-cancel-on-close: true" + "\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" + "\n" + "\n" + "--batch_c914-a60c-1877--";var getContactOptions = {url: url,method: "POST",json:false,headers: {"content-type": "multipart/mixed;boundary=batch_c914-a60c-1877",'Authorization': 'Basic ' + new Buffer(config.user + ":" + config.password).toString('base64')},body: sBody };function getContact() {return new Promise(function(resolve,reject){var requestC = request.defaults({jar: true});console.log("Step1: get contact via url: " + url );requestC(getContactOptions,function(error,response,body){if( error){console.log("error occurred: " + error);reject(error);}console.log("response:" + body);var nStartIndex = body.indexOf("{");var nLastIndex = body.lastIndexOf("}");if( nStartIndex < 0 || nLastIndex < 0)return;var sPayload = body.substring(nStartIndex, ++nLastIndex);resolve(JSON.parse(sPayload));}); }); }function displayResult(oResult){console.log(oResult); }getContact().then(displayResult); 復(fù)制代碼使用node命令直接執(zhí)行這個.js文件:
得到結(jié)果:
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的使用nodejs实现OData的batch操作在Marketing Cloud里读取contact信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【题解】弃疗Nim (2019,5.23
- 下一篇: C# Console类学习笔记