Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Possibility to subscribe and existing user to another list #927

Closed
marcinkunert opened this issue Aug 30, 2022 · 9 comments
Closed
Labels
enhancement New feature or request

Comments

@marcinkunert
Copy link
Contributor

There are 2 private lists:

  • newsletter
  • waiting list for a product

Currently, if a user is subscribed to the newsletter, there is no way (at least I know of) to subscribe him to the waiting list without changing it directly in database or deleting the subscription and creating it again.

As of v2.2.0 sending a POST to /api/subscribers results in 409 Conflict: Email already exists if the email is already in any other list. I think in this situation, the correct answer would be to adding him to the list.

@marcinkunert marcinkunert added the enhancement New feature or request label Aug 30, 2022
@knadh
Copy link
Owner

knadh commented Aug 30, 2022

You can use the subscription management API to manage subscriber lists. I just realised that this is not in the docs. Will add.

PUT /api/subscribers/lists/:subscriberID
{
	"action": "add", // add | remove | unsubscribe
	"target_list_ids": [1, 2, 3],
	"status": "subscribed" // Status to use when 'add'ing.
}

PUT /api/subscribers/lists
{
	"subscriber_ids": [1, 2, 3, 4]
	"action": "add", // add | remove | unsubscribe
	"target_list_ids": [1, 2, 3],
	"status": "subscribed" // Status to use when 'add'ing.
}

An optional query param can be used to pass arbitrary SQL expressions to the query (instead of subscriber_ids: []) to bulk select subscriber IDs. These APIs are used on the UI when using the "Manage list" option that appears on checking checkboxes next to subscribers.

@marcinkunert
Copy link
Contributor Author

marcinkunert commented Aug 30, 2022

@knadh thanks for the quick reply. I assume the first mentioned API doesn't trigger opt-in send out?
My current go to workaround is to insert to the db directly and trigger api/subscribers/{id}/optin. This will probably trigger opt-in for all of the users not confirmed lists, but I don't really care 😅

@knadh
Copy link
Owner

knadh commented Aug 30, 2022

Ah, that's right. Bulk management does not trigger opt-in e-mails. api/subscribers/{subscriberID}/optin only triggers opt-in for that one subscriber, so that's fine.

@eljobe
Copy link

eljobe commented Sep 4, 2022

When I attempt to send a POST request to /api/subscribers/lists with listmonk version 2.0.2, I'm getting back a 405 error:

405 Method Not Allowed 405 HTTP/1.1 1 1 map[Content-Length:[33] Content-Type:[application/json; charset=UTF-8] Date:[Sun, 04 Sep 2022 13:17:56 GMT]] 0xc00006a060 33 [] false false map[] 0xc00015e100 <nil>

Do I need to enable these endpoints?

@eljobe
Copy link

eljobe commented Sep 4, 2022

Ah. I think, according to the code. It's expecting PUT not POST requests.

@eljobe
Copy link

eljobe commented Sep 4, 2022

Oh. Also, it looks like the field that you called "subscriber_ids" above is actually just called "ids"
https://github.com/knadh/listmonk/blob/master/cmd/subscribers.go#L27

@eljobe
Copy link

eljobe commented Sep 4, 2022

And finally, it looks like status should be confirmed, unconfirmed, or unsubscribed not subscribed.

@eljobe
Copy link

eljobe commented Sep 4, 2022

@knadh, I thought about forking and contributing the documentation update that would advertise these API endpoints. But, I think the docs must be in another repository. Is it public?

@knadh
Copy link
Owner

knadh commented Sep 5, 2022

Whoops.

I thought about forking and contributing the documentation update that would advertise these API endpoints.

That would be very helpful. The repo is at https://github.com/knadh/listmonk-site

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants