0

using Sample Java Code (Axis 1.4) from https://help.exacttarget.com/en/technical_library/web_service_guide/technical_articles/creating_an_import_definition/

there is an error on the line:

Soap stub = init();

what is this object type "Soap", where should it be imported from?

Sample Java Code (Axis 1.4)

public class ImportDefTestCase extends BaseTestCase {

public void testCreateImportDef() throws RemoteException {

    Soap stub = init();
    ImportDefinition impDef = new ImportDefinition();
    impDef.setName("ImportDefinitionSeed_1");
    impDef.setCustomerKey("ImportDefinitionSeed_1");
    impDef.setDescription("This import definition was created through the API.");

    impDef.setAllowErrors(true);

    impDef.setDestinationObject(new List());
    impDef.getDestinationObject().setID(new Integer(2464));

    // Specify the notification type (optional)

    AsyncResponse asyncResponse = new AsyncResponse();
    asyncResponse.setResponseType(AsyncResponseType.email);
    asyncResponse.setResponseAddress("[email protected]");
    impDef.setNotification(asyncResponse);

    FileTransferLocation fileTransferLocation = new FileTransferLocation();
    fileTransferLocation.setCustomerKey("ExactTarget Enhanced FTP");
    impDef.setRetrieveFileTransferLocation(fileTransferLocation);

    impDef.setUpdateType(ImportDefinitionUpdateType.AddAndDoNotUpdate);
    // Map fields (required)
    impDef.setFieldMappingType(ImportDefinitionFieldMappingType.MapByOrdinal);

    FieldMap map1 = new FieldMap();
    map1.setDestinationName("Subscriber Key");
    map1.setSourceName("1");
    //map1.setSourceOrdinal(new Integer(1));
    FieldMap map2 = new FieldMap();
    map2.setDestinationName("Email Address");
    //map2.setSourceOrdinal(new Integer(2));
    map2.setSourceName("2");

    FieldMap[] maps = {map1, map2};
    impDef.setFieldMaps(maps);
    impDef.setFileSpec("12345.csv");

    // Specify the FileType
    impDef.setFileType(FileType.CSV);

    //Assign ImportDefinition to sub-account
    ClientID clientID = new ClientID();
    clientID.setPartnerClientKey("12345");// Partner Key
    impDef.setClient(clientID);

    CreateRequest createRequest = new CreateRequest();
    createRequest.setOptions(new CreateOptions());
    APIObject[] apiObjectList = {impDef};
    createRequest.setObjects(apiObjectList);
    CreateResponse createResponse = stub.create(createRequest);
    System.out.println("CreateResponse ::: " + createResponse.getOverallStatus());

}

public void testCreateImportDefToDataExtension() throws RemoteException {

    try {
        Soap stub = init();

        DataExtension dataExtension = getDataExtension(stub);
        ImportDefinition impDef = new ImportDefinition();
        impDef.setName("Import_Definition_UpdateButDoNotAdd");
        impDef.setCustomerKey("Import_UpdateButDoNotAdd_Key");
        impDef.setDescription("Import_Definition_UpdateButDoNotAdd_Desc");

        impDef.setAllowErrors(true);

        //dataExtension.setID(new Integer(12345));
        impDef.setDestinationObject(dataExtension);

        // Specify the notification type (optional)

        AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setResponseType(AsyncResponseType.email);
        asyncResponse.setResponseAddress("[email protected]");
        impDef.setNotification(asyncResponse);

        FileTransferLocation fileTransferLocation = new FileTransferLocation();
        fileTransferLocation.setCustomerKey("ExactTarget Enhanced FTP");
        impDef.setRetrieveFileTransferLocation(fileTransferLocation);

        impDef.setUpdateType(ImportDefinitionUpdateType.UpdateButDoNotAdd);
        // Map fields (required)
        //impDef.setFieldMappingType(ImportDefinitionFieldMappingType.MapByOrdinal);
        impDef.setFieldMappingType(ImportDefinitionFieldMappingType.InferFromColumnHeadings);
        //impDef.setSubscriberImportType(ImportDefinitionSubscriberImportType.Email);

        FieldMap map1 = new FieldMap();
        map1.setDestinationName("EmailId");
        map1.setSourceOrdinal(new Integer(1));
        FieldMap map2 = new FieldMap();
        map2.setDestinationName("StatusField");
        map2.setSourceOrdinal(new Integer(2));

        FieldMap[] maps = {map1, map2};
        impDef.setFieldMaps(maps);
        impDef.setFileSpec("Test2.csv");

        // Specify the FileType
        impDef.setFileType(FileType.CSV);

        //impDef.setClient(dataExtension.getClient());

        CreateRequest createRequest = new CreateRequest();
        createRequest.setOptions(new CreateOptions());
        APIObject[] apiObjectList = {impDef};
        createRequest.setObjects(apiObjectList);
        CreateResponse createResponse = stub.create(createRequest);
        System.out.println("CreateResponse ::: " + createResponse.getOverallStatus());
    } catch (RemoteException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    } catch (IOException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }

}

This sample code creates an import definition and associates it with a specific data extension.

/**
 * Creating Import-Definition and associating it with a Data Extension
 *
 * @throws RemoteException
 */

   public void testCreateImportDefToDataExtensionMarket2Lead() throws RemoteException{
    try {
        Soap_PortType stub = init();
        ImportDefinition impDef = new ImportDefinition();
        impDef.setName("Import_To_DE");
        impDef.setCustomerKey("Import_To_DE_Key");
        impDef.setDescription("Import_To_DE");
        impDef.setAllowErrors(true);

        // Associate Data-Extenison to Import-Defintion 
    DataExtension dataExtension = new DataExtension();
        dataExtension.setCustomerKey("UsingAPI_For_Key");
        impDef.setDestinationObject(dataExtension);

        // Specify the notification 
        AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setResponseType(AsyncResponseType.email);
        asyncResponse.setResponseAddress("[email protected]");
        impDef.setNotification(asyncResponse);

    //Specify Location of File, In this case it is FTP             
    FileTransferLocation fileTransferLocation = new FileTransferLocation();
        fileTransferLocation.setCustomerKey("ExactTarget Enhanced FTP");
        impDef.setRetrieveFileTransferLocation(fileTransferLocation);
        impDef.setUpdateType(ImportDefinitionUpdateType.AddAndDoNotUpdate);

        //Map fields by Column headings.
        impDef.setFieldMappingType(ImportDefinitionFieldMappingType.InferFromColumnHeadings);
        FieldMap map1 = new FieldMap();
        map1.setDestinationName("EmailAddress");

        //map1.setSourceOrdinal(new Integer(1));
        FieldMap map2 = new FieldMap();
        map2.setDestinationName("ChannelUser");

        //map2.setSourceOrdinal(new Integer(2));
        FieldMap map3 = new FieldMap();
        map3.setDestinationName("ChannelUser_EmailAddress");
        FieldMap map4 = new FieldMap();
        map4.setDestinationName("Demographic_Address");
        FieldMap[] maps = {map1, map2, map3, map4};
        impDef.setFieldMaps(maps);
        impDef.setFileSpec("Import2L.csv");

        // Specify the FileType
        impDef.setFileType(FileType.CSV);
        CreateRequest createRequest = new CreateRequest();
        createRequest.setOptions(new CreateOptions());
        APIObject[] apiObjectList = {impDef};
        createRequest.setObjects(apiObjectList);
        CreateResponse createResponse = stub.create(createRequest);

        //ImportResultsSummary importResultsSummary = (ImportResultsSummary) createResponse.getResults();
        System.out.println("CreateResponse ::: " + createResponse.getOverallStatus());

        }
        catch (RemoteException e)
        {
        e.printStackTrace();  
        }
        catch (IOException e)
        {
        e.printStackTrace();  
        }
    }

1 Answer 1

0

If you are doing a new implementation, I would recommend using Axis2.0. Axis1.4 has known issues with handling double-byte characters. An example of creating an import definition for Axis2.0 can be found at: https://github.com/MichaelAllenClark/exacttarget-soap-java/blob/master/src/com/exacttarget/example/CreateImportDefinition.java

That GitHub Repo contains a complete project where that code example is used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .