uncheck the globally unsubscribed checkbox for a contact
Hi Markus,
I have the problem that I can't uncheck the globally unsubscribed checkbox for a contact when they re-subscribe to the newsletter. I use the following code:
public bool Subscribe(SubscribeModel model)
{
var defaultMailingListKey = Guid.Parse("884E9084-26E6-411F-AD5A-0A0911075A19");
var subscribers = _newsletterStudioService.GetRecipientsByEmail(model.Email);
if (subscribers != null && subscribers.Any())
{
foreach (var subscriber in subscribers)
{
subscriber.GlobalUnsubscribed = false;
var addRecipientRequest = new AddRecipientRequest(model.Email)
.WithFirstname(model.Firstname)
.WithLastname(model.Lastname)
.SubscribeTo(defaultMailingListKey);
var result = _newsletterStudioService.AddRecipient(addRecipientRequest);
if (result.Success)
{
return true;
}
}
}
else
{
var addRecipientRequest = new AddRecipientRequest(model.Email)
.WithFirstname(model.Firstname)
.WithLastname(model.Lastname)
.SubscribeTo(defaultMailingListKey);
var result = _newsletterStudioService.AddRecipient(addRecipientRequest);
if (result.Success)
{
return true;
}
}
Can you tell me how to save the subscriber after I set subscriber.GlobalUnsubscribed = false;
I'm wondering what the "_newsletterStudioService.AddRecipient"-call in the first part of your if-statement returns? I mean you're basically trying to add a recipient that already exists right? Does it return true for result.Success?
At the moment there is not a good way to set the GlobalUnsubscribed-property of the recipient in a programmatic way since we don't expose the store-method from our internal repository.
I need to plan for some updates to the API to facilitate this. While you wait for this, maybe a simple SQL-statement to update the row in the db-table is a viable workaround?
Also, may I ask which version of Umbraco and the package you're running on?
uncheck the globally unsubscribed checkbox for a contact
Hi Markus,
I have the problem that I can't uncheck the globally unsubscribed checkbox for a contact when they re-subscribe to the newsletter. I use the following code:
Can you tell me how to save the subscriber after I set subscriber.GlobalUnsubscribed = false;
Or am I on the wrong track completely?
Thanks
Hi!
I'm wondering what the "_newsletterStudioService.AddRecipient"-call in the first part of your if-statement returns? I mean you're basically trying to add a recipient that already exists right? Does it return true for result.Success?
At the moment there is not a good way to set the GlobalUnsubscribed-property of the recipient in a programmatic way since we don't expose the store-method from our internal repository.
I need to plan for some updates to the API to facilitate this. While you wait for this, maybe a simple SQL-statement to update the row in the db-table is a viable workaround?
Also, may I ask which version of Umbraco and the package you're running on?
Cheers!
is working on a reply...