Skip to content

Instantly share code, notes, and snippets.

@gayancc
Created October 8, 2015 10:49
Show Gist options
  • Save gayancc/edf6848c1df40bf387f7 to your computer and use it in GitHub Desktop.
Save gayancc/edf6848c1df40bf387f7 to your computer and use it in GitHub Desktop.
Create import Definition ExactTarget
public string[] CreateImportDefinition(string fileName, string destinationKey, int destinationId)
{
var key = Guid.NewGuid().ToString();
var definition = new ExactTargetApi.ImportDefinition
{
Name = key,
CustomerKey = key,
Description = string.Format("This import definition was created through the API. On {0}", DateTime.Now.ToShortDateString()),
AllowErrors = true,
AllowErrorsSpecified = true,
UpdateType = ExactTargetApi.ImportDefinitionUpdateType.AddAndUpdate,
UpdateTypeSpecified = true
};
var extension = new ExactTargetApi.List { CustomerKey = destinationKey };
definition.DestinationObject = extension;
definition.DestinationObject.ID = destinationId;
definition.DestinationObject.IDSpecified = true;
definition.Notification = new ExactTargetApi.AsyncResponse
{
ResponseType = ExactTargetApi.AsyncResponseType.email,
ResponseAddress = "[email protected]",
IncludeResults = true,
IncludeResultsSpecified = true,
RespondWhen = RespondWhen.Always,
RespondWhenSpecified = true,
};
definition.RetrieveFileTransferLocation = new ExactTargetApi.FileTransferLocation { CustomerKey = "C13A1115-D720-401D-A450-E2B0F204D404" };
definition.FieldMappingType = ExactTargetApi.ImportDefinitionFieldMappingType.ManualMap;
definition.FieldMaps = SetMappingFields();
definition.FieldMappingTypeSpecified = true;
definition.FileSpec = fileName;
definition.FileType = ExactTargetApi.FileType.CSV;
definition.FileTypeSpecified = true;
using (var client = ClientFactory.Create(_config))
{
string status;
string requestId;
var createResults = client.CreateWithAuthToken(new ExactTargetApi.CreateOptions(),
new ExactTargetApi.APIObject[] { definition }, out requestId, out status);
return new string[] { createResults[0].StatusCode, createResults[0].StatusMessage };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment