Skip to main content

Creating a page to subscribe or unsubscribe from multiple notification at once

Overview

By setting the self_only parameter in the MagazineInfo::list endpoint, you can retrieve a list of notification that you are subscribed to.
In this tutorial, we will use this endpoint to create a page that displays multiple notification and their subscription status, and allows you to subscribe or unsubscribe from them all at once.

What you'll learn

You will learn how to add and retrieve comments with a hierarchical structure using the following steps:

Prerequisites

info

This page assumes that you have already set up a project with Kuroco and Nuxt.js, and have implemented a login screen.
If you haven't done so yet, please refer to the following tutorials.
Beginner's guide to Kuroco
Building a login page using Kuroco and Nuxt.js

info

This tutorial is written with the following versions:
Nuxt2: v2.15.8
Nuxt3: v3.8.0

Preparing multiple notification

First, register multiple notification in the Kuroco admin panel.
Go to [Campaign] -> [Newsletter] to navigate to the newsletter list, and click [Add] in the upper right corner to register a newsletter.

Image from Gyazo

For this tutorial, we have prepared three notification as shown below.

Image from Gyazo

Please make a note of the notification ID as it will be set to the endpoint.

Setting up the endpoints

Add the endpoints to the API settings where the Login::login_challenge endpoint is configured.
This allows requests to be made to the endpoints using the authentication information from the logged-in user. Please note that authentication information cannot be shared between different APIs.

In this case, we will set up three endpoints: one to retrieve a list of notification that the user is subscribed to, one to subscribe to a newsletter, and one to unsubscribe from a newsletter.

Click [Add New Endpoint] to create each endpoint.

Image from Gyazo

Endpoint to retrieve a list of notification

FieldSetting
Pathmy_magazine/info
CategoryMagazine
ModelMagazineInfo
Operationlist
magazine_idEnter the notification IDs targeted for the response
7
8
9
self_onlyCheck the box

Image from Gyazo

Image from Gyazo

tip

By enabling self_only, only the notification that the user is subscribed to will be included in the response. If you want to retrieve a list of notification regardless of subscription status, create a separate endpoint for MagazineInfo::list without self_only and use it.

Endpoint to subscribe to a newsletter

FieldSetting
Pathmagazine/subscribe
CategoryMagazine
ModelMagazineSubscriber
Operationsubscribe
allow_magazine_idEnter the notification IDs to allow subscribe using the endpoint
7
8
9
self_onlyCheck the box

Image from Gyazo

Image from Gyazo

caution

If self_only is not checked, please be careful as others can be added as subscribers if they know the endpoint.

caution

If allow_magazine_id is not specified, please be aware that subscriber registration will be possible for all notification.

Endpoint to unsubscribe

ItemSetting
Pathmagazine/unsubscribe
CategoryMagazine
ModelMagazineSubscriber
Operationunsubscribe
allow_magazine_idEnter the notification IDs to allow unsubscribe using the endpoint
7
8
9
self_onlyCheck the box

Image from Gyazo

Image from Gyazo

caution

If self_only is not checked, please be careful as others can delete subscriptions of others if they know the endpoint.

caution

If allow_magazine_id is not specified, please be aware that deletion of subscriber registration will be possible for all deliveries.

tip

Although it is not used in this tutorial, you can use the MagazineSubscriber::list endpoint to get a list of subscribers for the delivery.
By applying a filter such as search_mail_address contains "@example.com", you can search by the domain name of the email address.
Please use it when implementing an administrator's management screen.

Implementing the frontend

Create the following file.

/pages/mypage/magazine/index.vue
loading...

In this example, we use radio buttons to display the subscription status and send an API request immediately when there is a change.

tip

If you add a Submit button and send a POST request all at once when submitting, it may take time to process if the number of deliveries increases.
Consider omitting requests to notification that have not changed or registering new subscription statuses in batches for processing.

Confirm the operation

After logging in and accessing the target directory, you can confirm that the list of deliveries is displayed and an API request is sent when the subscription status is updated.

Image from Gyazo


Support

If you have any other questions, please contact us or check out Our Slack Community.