无法使用其他 ID 创建联系人

Unable to create contact with additional id

我目前正在使用 API_MKT_CONTACT 服务定义的 SDK 版本 3.39.0 和版本 0004 尝试使用以下代码在 Marketing Cloud 中创建一个具有 AdditionalID 的新联系人:

ODataRequestUpdate contactRequest = 
  contactService
    .updateContactOriginData(contact)
    .withHeader("Sap-Cuan-RequestTimestamp", getFormattedTime(System.currentTimeMillis()))
    .withHeader("Sap-Cuan-SequenceId", "UpdatePatch")
    .withHeader("Sap-Cuan-SourceSystemType", "EXT")
    .withHeader("Sap-Cuan-SourceSystemId", "sdk-test")
    .toRequest();

var additionalId = 
  AdditionalID.builder()
    .externalContactID(pii.getId().toString())
    .originOfContact(origin)
    .originOfContact_2("EMAIL") //ContactAdditionalOrigin
    .externalContactID_2(pii.getEmail()) //ContactAdditionalID
    .build();

var additionalIdRequest = contactService
  .updateAdditionalIDs(additionalId)
  .replacingEntity()
  .withHeader("Sap-Cuan-RequestTimestamp", getFormattedTime(System.currentTimeMillis()))
  .withHeader("Sap-Cuan-SourceSystemType", "EXT")
  .withHeader("Sap-Cuan-SourceSystemId", "sdk-test")
  .toRequest();

// use low level API as a work around for https://github.com/SAP/cloud-sdk/issues/156
ODataRequestBatch requestBatch =  new ODataRequestBatch(ContactService.DEFAULT_SERVICE_PATH, ODataProtocol.V2);
requestBatch
  .beginChangeset()
  .addUpdate(contactRequest)
  .addUpdate(additionalIdRequest)
  .endChangeset();

HttpClient httpClient = HttpClientAccessor.getHttpClient(contactsDestination);
ODataRequestResultMultipartGeneric batchResult = requestBatch.execute(httpClient);
batchResult.getResult(additionalIdRequest);

这会导致以下错误:

{
  "error": {
    "code": "SY/530",
    "message": {
      "lang": "en",
      "value": "Inline component is not defined or not allowed (HTTP PUT)"
    },
    "innererror": {
      "application": {
        "component_id": "CEC-MKT-DM-IC",
        "service_namespace": "/SAP/",
        "service_id": "API_MKT_CONTACT_SRV",
        "service_version": "0004"
      },
      "transactionid": "3B63A2A6CC9205E0E00604E1D31F1CDF",
      "timestamp": "20210315142401.8432680",
      "Error_Resolution": {
        "SAP_Transaction": "For backend administrators: use ADT feed reader \"SAP Gateway Error Log\" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details",
        "SAP_Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)",
        "Batch_SAP_Note": "See SAP Note 1869434 for details about working with $batch (https://service.sap.com/sap/support/notes/1869434)"
      },
      "errordetails": []
    }
  }
}

我正在使用 this documentation 作为构建请求的指南(在“使用其他 ID 创建联系人”部分下)。当我 运行 Postman 中的示例代码时,它按预期工作。请注意,AdditionalIDs 的负载是一个空的 JSON 对象。

所以我启用了 HTTP 线路日志并注意到 SDK 似乎包含以下负载:

PUT AdditionalIDs(ContactAdditionalOrigin='EMAIL',ContactAdditionalID='wade.watts@theoasis.com',ContactID='ae46e174-52a3-4de6-8caa-57213151b295',ContactOrigin='<CONTACT_ORIGIN>') HTTP/1.1
Sap-Cuan-SourceSystemId: sdk-test
Accept: application/json
Sap-Cuan-SourceSystemType: EXT
Content-Type: application/json
Sap-Cuan-RequestTimestamp: '2021-03-15T14:24:00.828'

{"ContactOrigin":"<CONTACT_ORIGIN>","ContactID":"ae46e174-52a3-4de6-8caa-57213151b295","ContactAdditionalOrigin":"EMAIL","ContactAdditionalID":"wade.watts@theoasis.com","ContactAdditionalIdUUID":null,"ContactUUID":null,"ContactAddlIDIsInvalid":null,"MarketingAreas":[]}

不幸的是,我似乎找不到在使用 SDK 时省略 payload/inline 组件以使其与示例代码匹配的方法。这是 SDK 的问题还是我做错了什么?任何帮助将不胜感激!

干杯!

更新

应用@matkuhr 建议的解决方法,我将上面的 additionalIdRequest 更改为这个并且它起作用了:

ODataEntityKey key = new ODataEntityKey(ODataProtocol.V2)
        .addKeyProperty(AdditionalID.EXTERNAL_CONTACT_ID.getFieldName(), mcContact.getContactId())
        .addKeyProperty(AdditionalID.ORIGIN_OF_CONTACT.getFieldName(), origin)
        .addKeyProperty(AdditionalID.ORIGIN_OF_CONTACT_2.getFieldName(), "EMAIL")
        .addKeyProperty(AdditionalID.EXTERNAL_CONTACT_I_D_2.getFieldName(), mcContact.getEmailAddress());
    var request = new ODataRequestUpdate(
        ContactService.DEFAULT_SERVICE_PATH,
        "AdditionalIDs",
        key,
        "{}",
        UpdateStrategy.REPLACE_WITH_PUT,
        null,
        ODataProtocol.V2);
    request.addHeader("Sap-Cuan-RequestTimestamp", getFormattedTime(System.currentTimeMillis()));
    request.addHeader("Sap-Cuan-SourceSystemType", "EXT");
    request.addHeader("Sap-Cuan-SourceSystemId", "sdk-test);

不是你做错了,也不是SDK,是服务。该服务似乎大大偏离了 OData V2 约定以及基本 HTTP 约定。

您可以通过更多地利用 SDK 的低级 API 来解决此问题。使用服务所需的负载完全手动创建更新请求,例如:

ODataEntityKey key = new ODataEntityKey(ODataProtocol.V2)
                .addKeyProperty(Contact.XYZ.getFieldName(), contact.getXyz())
request = new ODataRequestUpdate(
                contactService.getServicePath(),
                contact.getEntityCollection(),
                key,
                "{ }",  // this will be the payload
                UpdateStrategy.REPLACE_WITH_PUT,
                null,
                ODataProtocol.V2);
request.addHeader("key", "val");
// add more headers & parameters if needed and execute