FuelSDK-Java
FuelSDK-Java copied to clipboard
Add support for Upserts to ETSoapObject#update
According to the Marketing Cloud article below (1), it is possible to do an Upsert in a DataExtension. Please, provide this option also for the Fuel Java SDK.
A suggestion: maybe offer an update method, which accepts as an argument UpdateOptions to be used during creation of the UpdateRequest.
public static <T extends ETSoapObject> ETResponse<T> update(ETClient client,
List<T> objects,
UpdateOptions updateOptions)
throws ETSdkException
{
ETResponse<T> response = new ETResponse<T>();
if (objects == null || objects.size() == 0) {
response.setStatus(ETResult.Status.OK);
return response;
}
//
// Get handle to the SOAP connection:
//
ETSoapConnection connection = client.getSoapConnection();
//
// Automatically refresh the token if necessary:
//
client.refreshToken();
//
// Perform the SOAP update:
//
Soap soap = connection.getSoap();
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setOptions(updateOptions);
for (T object : objects) {
object.setClient(client);
updateRequest.getObjects().add(object.toInternal());
}
The UpdateOptions can receive a SaveAction.UPDATE_ADD
SaveOption upsertOption = new SaveOption();
upsertOption.setSaveAction(SaveAction.UPDATE_ADD);
upsertOption.setPropertyName("dataExtensionName");
UpdateOptions option = new UpdateOptions();
List<SaveOption> saveOption = option.getSaveOptions().getSaveOption();
saveOption.add(upsertOption);
(1) https://help.marketingcloud.com/en/technical_library/web_service_guide/technical_articles/managing_data_in_data_extensions/