我在SAPUI5应用程序(在Web IDE中)上工作,该应用程序在Hybris Marketing中创建交互。因此我使用OData服务CUAN_IMPORT_SRV。我已经尝试了一个简单的Postman请求,它工作正常。这种互动是在Hybris Marketing中创建的。
上传的示例JSON正文如下所示(由Call OData Service定向):
{
"Id" : "",
"Timestamp" : "/Date(1506014140593)/",
"UserName" : "UNAME",
"SourceSystemId" : "ANY",
"Interactions" : [
{
"Key" : "",
"CampaignId" : "",
"CommunicationMedium" : "BUSINESS_DOCUMENT",
"ContactId" : "005056966DBE1EE4B299CD12B99F60C4",
"ContactIdOrigin" : "SAP_HYBRIS_MKT_IC",
"ContentData" : "First Event",
"ContentTitle" : "",
"InitiativeId" : "100001622",
"InitiativeVersion" : 0,
"InteractionType" : "CRM_ACTIVITY",
"IsAnonymous" : false,
"MarketingOrchestrationId" : 0,
"Quantifier" : 1,
"Timestamp" : "/Date(1506014140283)/"
}
]
}
如果数据有意义,则不予讨论。它现在只是一个测试案例。在我的SAPUI5应用程序中,我开始编写一个简单的函数来处理数据上传。我以this topic为导向。
这是我的功能:
onPressScan: function() {
sap.ndc.BarcodeScanner.scan(
function(mResult) {
if (!mResult.cancelled) {
// begin POST Interaction with OData
var oModel = new sap.ui.model.odata.v2.ODataModel("https://host:port/sap/opu/odata/sap/CUAN_IMPORT_SRV/", true, "UNAME", "PASSWORD");
oModel.setHeaders({
"X-CSRF-Token" : "Fetch"
});
var jsonString = '{ "Id" : "", "Timestamp" : "/Date(1506014140591)/", "UserName" : "UNAME", "SourceSystemId" : "ANY", "Interactions" : [ ' +
'{ "Key" : "" , "CampaignId" : "" , "CommunicationMedium" : "BUSINESS_DOCUMENT" , "ContactId" : "005056966DBE1EE4B299CD12B99F60D4" ' +
', "ContactIdOrigin" : "SAP_HYBRIS_MKT_IC" , "ContentData" : "Try from Scanner App", "ContentTitle" : "Scan", "InitiativeId" : "100001622" ' +
', "InitiativeVersion" : 0, "InteractionType" : "CRM_ACTIVITY", "IsAnonymous" : false, "MarketingOrchestrationId" : 0, "Quantifier" : 1, "Timestamp" : "/Date(1506014140281)/" }]}';
var json = JSON.parse(jsonString);
// get X-CSRF-Token for POST request
oModel.read("/$metadata", null, null, true, function(oData, oResponse) {
var xcsrfToken = oResponse.headers["x-csrf-token"];
oModel.setHeaders({
"X-CSRF-Token" : xcsrfToken,
"Content-Type" : "application/json"
});
// POST interaction to yMarketing
oModel.create("/ImportHeaders", json, null, function() {
alert("Create successful");
}, function(){
alert("Create failed");
});
}, function() {
alert("Read failed");
});
}}, function(Error) {
sap.m.MessageBox.error("Scanning failed due to following error: " + Error, {
title: "Error while scanning"
});
}
);
}
当我尝试应用程序时,我收到以下错误:
声明OData模型时,我使用正确的系统UNAME和PASSWORD进行读写。我做错了什么?
任何提示都很受欢迎!
答案 0 :(得分:0)
点击Chrome图标>选项>将其添加到目标路径后面:
- disable-web-security --user-data-dir