Created
October 8, 2015 10:49
-
-
Save gayancc/edf6848c1df40bf387f7 to your computer and use it in GitHub Desktop.
Create import Definition ExactTarget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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