> For the complete documentation index, see [llms.txt](https://docs.navigaglobal.com/naviga-subscribe/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.navigaglobal.com/naviga-subscribe/additional-resources/subscribe-apis/mg2-newsletter-widget-api.md).

# Newsletter Widget API

In this document you will learn how to consume the MG2 Newsletter Widget API.

MG2 Newsletter Widget API is a Javascript library which allows you to consume, easily and quickly, every feature in the MG2 Newsletter Widget.

## Installation

In order to consume the API, the page needs to include a reference to `MG2Widget newsletterwidget.min.js`and a container element as the following example shows:

```javascript
<head>
    <script id="scriptMg2Widget" src="{Link will be provided by MG2 team}">
    </script>
    … (the others JS references) …
</head>
<body>
     … (the others HTML elements) …
    <div id="mg2Widget-newsletter-container"></div>
</body>
```

## Parameters

| Parameter           | Description                                                                                                                                                                                                                                                                                                |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `email`             | Subscriber’s email. If this param is not specified, it will be looked for in the cookie. If it doesn’t exist, it will be asked to user.                                                                                                                                                                    |
| `categoryIdsList`   | List of Category IDs. It needs to be specified as an array list. If this param is not specified, widget will show all the categories. (Omitted in unsubscribe flow)                                                                                                                                        |
| `newsletterIdsList` | <p>List of Newsletter IDs. It needs to be specified as an array list.</p><ul><li>Open widget flow: If this param is not specified, widget will show all the newsletters.</li><li>Unsubscribe newsletters flow: If this param is not specified, widget will unsubscribe from all the newsletters.</li></ul> |
| `viewMode`          | This param specifies the view mode in which newsletters are shown. There are two options: Tabs mode (1) or List mode (2). Default mode is Tabs. (Omitted in unsubscribe flow)                                                                                                                              |
| `defaultCategoryId` | This param specifies the category that will be opened by default.                                                                                                                                                                                                                                          |
| `siteCode`          | If this param is specified, only preferences for that NewspaperId will be displayed.                                                                                                                                                                                                                       |
| `isModal`           | If this param is specified and has value 'true' then widget will be displayed in Modal mode                                                                                                                                                                                                                |
| `subscriberOnly`    | If this param is specified and has value 'true' then widget will display only Subscriber available newsletters. Otherwise only non-subscriber newsletters will be displayed.                                                                                                                               |
| `showAll`           | If this param is specified and has value 'true' and 'subscriberOnly' has value 'true' then widget will display all newsletters. Otherwise result depends on 'subscriberOnly' flag.                                                                                                                         |

## Code Examples

### **Subscribe Flow**

```
mg2WidgetAPI.openNewsletter();
```

### Filtering **Preferences**

```
var params =  {
    email: 'subscriber@email.com', // subscriber email
    newsletterIdsList: [ 5,6 ] // list of Ids of the EmailPreference
};
mg2WidgetAPI.openNewsletter(params);
```

### **Filtering Categories**

```
var params =  {
    email: 'subscriber@email.com', // subscriber email
    categoryIdsList: [ 2, 3 ] // list of Ids of the EmailPreferenceCategory
};
mg2WidgetAPI.openNewsletter(params);
```

### Unsubscribe All

```
mg2WidgetAPI.unsubscribeNewsletter();
```

### Unsubscribe Preference

```
var params =   {
    email: 'subscriber@email.com', // subscriber email  
    newsletterIdsList: [ 7, 8 ] // list of Ids of the EmailPreference
};
mg2WidgetAPI.unsubscribeNewsletter(params);
```

### Close Widget

```
mg2WidgetAPI.closeNewsletter();
```

### **Subscribe Flow Default Category**

Open default categor&#x79;**.**

```
var params =  {
    email: 'subscriber@email.com', // subscriber email
    defaultCategoryId: 3
};
mg2WidgetAPI.openNewsletter(params);
```

### View Mode

Force a View Mode for Preferences.

```
var params =  {
    email: 'subscriber@email.com', // subscriber email
    viewMode: 1 // 1: tabs view mode, 2: list view mode
};
mg2WidgetAPI.openNewsletter(params);
```

### Widget Display Mode

Display widget as modal.

```
var params =  {
    isModal: true
};
mg2WidgetAPI.openNewsletter(params);
```

### **Subscriber/Non-Subscriber Newsletters**

Displays newsletters filtered by SubscriberOnly criteri&#x61;**.**

```
var params =  {
    subscriberOnly: false
};
mg2WidgetAPI.openNewsletter(params);
```

### **Show All Newsletters**

Displays all newsletters.

```
var params =  {
    showAll: true,
    subscriberOnly: true
};
mg2WidgetAPI.openNewsletter(params);
```

## Email Campaign Links

**LINKS:** Please apply URLEncode to each QueryString parameter.

* **Change Profile:** [http://{YOUR\_WIDGET\_DOMAIN}/changeprofile?email=subscriber%40email.com](http://mg2newsletter.com/Documentationnew#)
* **Change Preferences:** [http://{YOUR\_WIDGET\_DOMAIN}/updatepreference?email=subscriber%40email.com](http://mg2newsletter.com/Documentationnew#)
* **Unsubscribe:** [http://{YOUR\_WIDGET\_DOMAIN}/unsubscribe?email=subscriber%40email.com\&preferenceid=2](http://mg2newsletter.com/Documentationnew#)
