salesforce-marketingcloud / FuelSDK-Java

Salesforce Marketing Cloud Java SDK
BSD 3-Clause "New" or "Revised" License
73 stars 122 forks source link

Add a subscriber to a list #16

Closed AndrewJMiller closed 9 years ago

AndrewJMiller commented 9 years ago

How do I go about adding a subscriber to a list? I am able to create an ETList and create an ETSubscriber but I don't see how to add the subscriber to a list. I noticed that setList and setAttributes had been commented out on the ETSubscriber class.

AndrewJMiller commented 9 years ago

I was able to add a subscriber to a list in this manner based on https://help.exacttarget.com/en-US/technical_library/web_service_guide/technical_articles/adding_subscribers_to_a_list/

ETResponse response = client.retrieve(ETList.class, filter); ETList testList = response.getObject(); com.exacttarget.fuelsdk.internal.List internalList = (com.exacttarget.fuelsdk.internal.List) testList.toInternal();

SubscriberList list = new SubscriberList(); list.setList((com.exacttarget.fuelsdk.internal.List) testList.toInternal()); list.setStatus(SubscriberStatus.ACTIVE); list.setId(Integer.parseInt(testList.getId()));

Subscriber subscriber = new com.exacttarget.fuelsdk.internal.Subscriber(); subscriber.setEmailAddress("foo@bar.com"); subscriber.setSubscriberKey("foo@bar.com"); subscriber.getLists().add(list);

Soap soap = client.getSoapConnection().getSoap(); CreateOptions createOptions = new CreateOptions(); SaveOption saveOption = new SaveOption(); saveOption.setSaveAction(SaveAction.UPDATE_ADD); saveOption.setPropertyName("*"); SaveOptions saveOptions = new SaveOptions(); saveOptions.getSaveOption().add(saveOption); createOptions.setSaveOptions(saveOptions);

CreateRequest createRequest = new CreateRequest(); createRequest.getObjects().add(subscriber); createRequest.setOptions(createOptions);

CreateResponse createResponse = soap.create(createRequest);

for(CreateResult result : createResponse.getResults()) { System.out.println("Subscriber Status ::: " + result.getStatusCode() + " " + result.getStatusMessage() ); }

System.out.println("Overall Status ::: " + createResponse.getOverallStatus() );