使用postman修改SAP Marketing Cloud contact主数据

举报
汪子熙 发表于 2022/01/22 21:35:38 2022/01/22
【摘要】 Marketing Cloud里的contact主数据,创建成功后也不是所有字段都能够被修改。在Personal data区域的字段是可以被修改的。比如我在“客户属性”字段里维护了一些值:然后点保存:其中第二个batch操作是通过一个roundtrip读取contact模型下多个子节点的数据,和我们这个修改的场景没有关联。使用postman进行修改:body字段维护以下内容:–batch_1...

Marketing Cloud里的contact主数据,创建成功后也不是所有字段都能够被修改。在Personal data区域的字段是可以被修改的。

比如我在“客户属性”字段里维护了一些值:

然后点保存:

其中第二个batch操作是通过一个roundtrip读取contact模型下多个子节点的数据,和我们这个修改的场景没有关联。

使用postman进行修改:

body字段维护以下内容:
–batch_1f7d-bd35-caed
Content-Type: multipart/mixed; boundary=changeset_8f9e-9a44-9f9e

–changeset_8f9e-9a44-9f9e
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE Consumers(‘02000A21209F1EE99CDF1A1FC9AA8065’)?sap-client=100 HTTP/1.1
Cache-Control: max-age=360
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: fQ2Pwfmf0K_LVYoKV9QYUw==
Content-Type: application/json
Content-Length: 215

{"__metadata":{“uri”:“https://jerry.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/Consumers(‘02000A21209F1EE99CDF1A1FC9AA8065’)",“type”:“CUAN_CONTACT_SRV.Consumer”},“YY1_CustomerType_ENH”:"Jerry测试2”}
–changeset_8f9e-9a44-9f9e–

–batch_1f7d-bd35-caed–

我想修改的字段的新的值为:Jerry测试2

执行postman后,发现值已经更新了,修改成功

使用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实现OData的batch操作在Marketing Cloud里读取contact信息

我们先来看看Marketing Cloud系统里的contact信息:
一共1218374条数据。

我们用如下的nodejs代码通过OData来获取这些数据:

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);

使用node命令直接执行这个.js文件:

得到结果:

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。