Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

subscribing and unsubscribing users from lists #65

Closed
gscott opened this issue Jul 21, 2015 · 3 comments
Closed

subscribing and unsubscribing users from lists #65

gscott opened this issue Jul 21, 2015 · 3 comments

Comments

@gscott
Copy link

gscott commented Jul 21, 2015

There are some really good docs on subscribing a user to a list here:

https://code.exacttarget.com/apis-sdks/soap-api/adding-subscribers-to-a-list.html

Because the examples use PHP, Java, and .NET -- it's a little hard to translate to fuel-node-soap.

In the edited fragment below, I can successfully subscribe someone to a list without a problem: First I i try to create the subscriber on the list; if I learn the subscriber already exists I do an update.

I have no trouble unsubscribing them from the list too (not shown here).

However, if I try to subscribe the Subscriber again, when the Subscriber already has a status of 'Unsubscribed', I am not able to set the Subscriber's status to Active unless I use the Update action.

But I don't know what state the subscriber is in -- non existent, or exists-but-unsubscribed -- therefore I don't know whether to do a create or an add. I call your attention to the SaveOptions. Isn't that supposed to give me essentially an Upsert ability? I have this feeling that I'm specifying the SaveOption incorrectly below. Any clues?

  let soapClient = new FuelSoap( fuelOptions );
  let options = {
    "SaveOptions": [{
      "SaveAction":   "UpdateAdd",
      "PropertyName": "*"
    }]
  };

  let props = {
    "EmailAddress":   [email address],
    "SubscriberKey":  [subscriber key],
    "Attributes":     [],
    "Lists":  [ {
      'ID':              [listID],
      'Status':          'Active',
      'StatusSpecified': true,
      'IDSpecified':     true,
      'Action':          'Create'
    }]
  };

  const ERR_SUBONLIST     =  "12014";
  const ERR_ONLISTALREADY =  "13006";

  soapClient.create( 'Subscriber', props, options, function( err ) {
    if (err) {
      if ( _.first( err.results ).ErrorCode === ERR_SUBONLIST ) {
        props.Lists[0].Action = 'Update';
        soapClient.update( 'Subscriber', props, options, function( e ) {
          if (!e) {
            // success
          } else {
            if ( _.first( e.results ).ErrorCode === ERR_ONLISTALREADY ) {
              // you are already on the list
            } else {
              // failure
            }
          }
        });
      } else {
        // failure
      }
    } else {
      // success
    }
  });
@balexandre
Copy link

@gscott can you share your subscribe method?

I'm new to SF Cloud API and I'm trying to subscribe an email...

ohh! and what is the SubscriberKey is that the app Data extension key?

@gscott
Copy link
Author

gscott commented Feb 21, 2018

@balexandre Wow, you're responding to an issue I sent nearly three years ago! Regrettably, I no longer remember, as the company moved on to using Campaign Monitor.

@brpsmith
Copy link

brpsmith commented Jul 10, 2020

In case someone comes across this issue in the future - the change to make to the above code is to perform an upsert by removing the prop 'Action': 'Create' from the first object in the Lists array.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants