3

When passing a subscriber.patch call to change the Status, I get a successful response but querying the email address at https://mc.exacttarget.com/cloud/ shows no change. I've tried setting the Status value in the Attributes as well but no luck.

EDIT: Added code snippet

module ExactTarget
  class Gateway
    class ExactTargetSubscriptionError < StandardError; end

    attr_reader :member_id

    def initialize(options = {})
      @client = FuelSDK::Client.new({'client' => { 'id' => options[:client_id], 'secret' => options[:secret] }})
      @member_id = options[:member_id]
    end

    def subscribe(email, attrs, list_ids)
      subscriber = build_subscriber(email, "Active", attrs, list_ids)
      response = perform_api_call(subscriber, "post")
      unless response.success?
        if response.subscriber_already_exists?
          response = update_subscriber(email, "Active", {"Status" => "Active"}, list_ids)
        end
      end
      response
    end

    def unsubscribe(email, list_ids)
      subscriber = build_subscriber(email, "Unsubscribed", {}, list_ids)
      response = perform_api_call(subscriber, "patch")
      response.success?
    end

    def update_subscriber(email, status, attrs, list_ids)
      subscriber = build_subscriber(email, status, attrs, list_ids)
      response = perform_api_call(subscriber, "patch")
      response.success?
    end

   private

   def build_subscriber(email, status, attrs, list_ids)
     subscriber = FuelSDK::Subscriber.new
     subscriber.authStub = @client
     subscriber.props = {
       "EmailAddress" => email,
       "SubscriberKey" => email,
       "Status" => status,
       "Attributes" => build_attributes(attrs),
       "Lists" => build_lists(list_ids)
     }
     subscriber
   end

   def build_attributes(attrs)
     attributes = [{ "Name" => "ChannelMemberID", "Value" => member_id }]
     attrs.each do |key, value|
       attributes.push({ "Name" => key, "Value" => value })
     end
     attributes
   end

   def build_lists(list_ids)
     list_ids.map { |list| {"ID" => list } }
   end

   def perform_api_call(subscriber, method)
     begin
       results = subscriber.send(method.to_sym)
       response = Response.new(results)
       #unless results.success?
       #  raise ExactTargetSubscriptionError, results.status
       #end
       response
     end
   end
 end

end

10
  • Please paste your code and we'll have a look.
    – Timothy
    Commented Jul 10, 2014 at 21:34
  • Added code snippet Commented Jul 11, 2014 at 14:54
  • Just to make sure I understand... it NEVER works in your code. You cannot make a status change, neither from active -> unsubscribed nor from unsubscribed -> active. Is this the correct understanding?
    – Timothy
    Commented Jul 11, 2014 at 16:09
  • Hey Timothy, I can subscribe a new user and then unsubscribe them. But once they are unsubscribed I can not change their Status to Active in order to re-subscribe them. Commented Jul 11, 2014 at 17:46
  • A thought: I do not believe you can set anyone to an active a list if they are currently unsubscribed in the All Subscribers list. So, you would want to do that first before looping through the rest.
    – Timothy
    Commented Jul 11, 2014 at 17:59

1 Answer 1

1

Here is my hunch, after a weekend to sleep on it. My guess is the status tied to the subscriber object is tied to the All Subs list ONLY. That's why you can update that list but nothing else. The LIST object is going to maintain who is subscribed to it. I would start there. See the SOAP version at http://help.exacttarget.com/en/technical_library/web_service_guide/objects/list/

2
  • Hey Timothy, you definitely sent me in the right direction. I was able to resolve the problem by setting the Status on the List property for a Subscriber. So for example "Lists" => [ { "ID" => 123456, "Status" => "Active" } ] will resubscribe a user to the list. Commented Jul 14, 2014 at 18:53
  • Resubscribing a user this way doesn't appear to work anymore. Has the API changed in some way? Commented Nov 25, 2015 at 19:49

You must log in to answer this question.

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