Early Access This is an Early Access feature. To enable it for your account, contact your CSM or raise a support ticket. |
Overview
The Email Optin Management API enables you to update the users' opt-in status in MoEngage after they submit the second confirmation through MoEngage consent-seeking emails.
API Endpoint
Method: PUT
https://api-{{0X}}.moengage.com/v1/opt-in-management/user-preferences
The 'X' in the API Endpoint URL refers to the MoEngage Data Center (DC). MoEngage maintains different data centres for different clients. You can find your DC number (value of X) and replace the value of 'X' in the URL by referring to the DC and API endpoint mapping here.
Authentication
The API request will be authenticated through Basic Authentication. Basic Authentication sends a Base64-encoded string containing your username and password with every API request. It encodes a 'username: password' string in Base64 and appends the encoded string with 'Basic '. This string is included in the authorization header as shown below:
{"Authorization: Basic Base64_ENCODED_APPKEY_APIKEY=="}
You can obtain the username and password details from the MoEngage dashboard.
- On the left navigation menu in the MoEngage dashboard, go to Settings > Account > APIs.
- Copy the following details:
- Username: Under Workspace ID (earlier app id), click the copy icon to copy the username.
- Password: On the API keys section, click the copy icon in the Data tile to copy the API key.
- Use these details to authenticate the API requests.
Request Headers
Key | Required | Sample Values | Description |
---|---|---|---|
Content-Type |
Required |
{"Content-Type": "application/json"} |
Set the Content-Type header to application/json. |
Authorization |
Required |
{"Authorization": "Basic Base64_ENCODED_APPKEY_APIKEY"} |
This authentication parameter, used for access control, must be included in the request. For more information on generating the authentication header, refer to Authentication. |
MOE-APPKEY
|
Required |
{“MOE-APPKEY”: “Workspace ID”} |
This is the workspace ID (earlier APP ID) of your MoEngage workspace. You must pass the MOE-APPKEY in the request. You can find your MoEngage Workspace ID in the MoEngage dashboard: Settings -> Account -> APIs -> Workspace ID (earlier app id) For more information, refer to Authentication. |
Request Body
{
"user_preferences": {
"customer_id": "ID_uid",
"email_id": "john@example.com",
"categories": {
"category_1": true,
"category_2": false
},
"opt_in_status": "DOUBLE_OPTED_IN",
"channel": "email"
}
}
Key | Data Type | Required | Description |
---|---|---|---|
user_preferences | JSON Object | Required | This field contains the preferences of the user. For more information, refer to User Preferences. |
User Preferences
The following user preferences are tracked for the Email Optin Management API in MoEngage.
Key | Data Type | Required | Description |
---|---|---|---|
customer_id | String | Optional, if email_id is passed. |
This field denotes the unique identifier used to identify a user in MoEngage. Note:
|
email_id | String | Optional, if customer_id is passed. |
This field denotes the email ID of the user. Note:
|
categories | JSON Object | Optional |
This field denotes the categories in your dashboard. The values of each category will be true or false based on whether the end-user subscribed to it or not. For example:
Note:
|
opt_in_status | String | Required |
This field denotes the opt-in status of the user. Supported values are:
Note:
|
channel | String | Required | This field denotes the channel that you are using. Example: email. |
info |
Information
|
Response Body
Status | Key | Data Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Success | message | String | This field denotes the success message. | ||||||||
Failure | code | String | Each error codes are unique and serve as a shorthand representation for the type of error, providing a quick reference that can be used to diagnose, troubleshoot, and address the problem based on a predefined set of error conditions. | ||||||||
message | String | This field contains the message that denotes the type of error. | |||||||||
details | JSON Object |
This field contains error details.
|
Refer to the Sample Response section for examples.
Response Codes
Status Code | Request State | Description |
---|---|---|
200 |
Success |
This response is returned when the request is processed successfully. |
400 |
Bad Request |
This response is returned when the required parameters are missing from the request, attributes are not found, or incorrect values are passed. |
401 |
Unauthorized |
This response is returned when the request does not have valid authentication credentials. |
403 |
Forbidden |
This response is returned when the Email Opt-in Management feature is not enabled for the workspace. |
429 |
Too Many Requests |
Too Many requests, there won't be any response body for this. |
500 |
Internal Server Error |
This response is returned when the system runs into an unexpected error. |
Sample Response
{
"message": "Your request has been processed successfully"
}
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid.",
"details": {
"target": "customer_id",
"message": "Wrong data type was used for <customer_id> - Value must be of type (<class 'str'>,), passed type: <class 'bool'> : False."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "['customerid']",
"message": "Extra key passed in the request"
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "opt_in_status",
"message": "Opt-In status can only be 'DOUBLE_OPTED_IN' or 'OPTED_OUT' (case-insensitive). Please provide the correct value."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "channel",
"message": "Channel can only be ['email'] (case-insensitive). Please provide the correct channel."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "customer_id or email_id",
"message": "Either customer_id or email_id is mandatory. Please provide at least one of them."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "customer_id",
"message": "customer_id is mandatory when unsubscribe on email is not enabled."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "categories",
"message": "There are no active categories found. Please remove the categories from the request data or setup the subscription categories in MoEngage Email settings."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "categories",
"message": "All provided categories are either invalid or not active in the Workspace. Please check the categories in the request."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "categories",
"message": "Categories A, B, C are either invalid or not active in the Workspace. Please check the categories in the request."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "400 Bad Request",
"message": "Request Data is invalid",
"details": {
"target": "customer_id or email_id",
"message": "No users found with the provided customer_id or email_id. Please check the same."
}
}
}
--------------------------------------------------------------------------------
{
"message": "Sentry check failed"
}
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed.",
"details": {
"target": "Authorization Header",
"message": "Authorization header is missing"
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "Authorization Header",
"message": "Invalid Authorization type or neither username nor password provided. Please use Basic Auth with correct username and password."
}
}
}
-------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "Authorization Header",
"message": "Workspace ID is missing or wrong. Please provide correct Workspace ID as username."
}
}
}
-------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "Authorization Header",
"message": "Data API key is missing or wrong. Please provide correct Data API Key as password."
}
}
}
-------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "MOE-APPKEY",
"message": "Workspace ID is missing in header. Please provide correct Workspace ID in header."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "Header Mismatch",
"message": "Workspace ID provided in header and username is not matching. Please provide correct Workspace ID."
}
}
}
-------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "Workspace ID",
"message": "Workspace ID is wrong. Please provide correct Workspace ID as username."
}
}
}
--------------------------------------------------------------------------------
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication failed",
"details": {
"target": "Data key",
"message": "Data API key is wrong. Please provide correct Data API Key as password."
}
}
}
{
"error": {
"code": "403 Forbidden",
"message": "Feature not enabled",
"details": {
"target": "Email Opt-in Management",
"message": "Email Opt-in Management feature not enabled for the workspace. Please reach out to MoEngage to get it enabled."
}
}
}
{
"error": {
"code": "429 Too Many Requests"
}
}
{
"error": {
"code": "500 Internal Server Error",
"message": "Something went wrong, Please contact MoEngage Team."
}
}
Rate Limit
The rate limit is 1000 RPM and 360k per day.
Sample cURL Request
curl --location --globoff --request PUT 'https://api-{{0X}}.moengage.com/v1.0/opt-in-management/user-preferences' \
--header 'MOE-APPKEY: {{DATA API ID}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic e3tEQVRBIEFQSSBJRH19Ont7REFUQSBBUEkgS0VZfX0=' \
--data-raw '{
"user_preferences": {
"customer_id": "ID_uid",
"email_id": "john@example.com",
"categories": {
"category_1": true,
"category_2": false
},
"opt_in_status": "DOUBLE_OPTED_IN/OPTED_OUT/OPT_IN_PENDING",
"channel": "email"
}
}'
Postman Collections
We have made it easy for you to test the APIs. Click here to view it in Postman.
FAQs
The user attribute specified in the General Settings of email will be used to search for users matching the provided email ID.
Email ID is given higher priority, and MoEngage finds all users with the same email ID and updates them with the passed opt-in status value. However, if you have requested not to carry forward the opt-in status or unsubscribe information across profiles with the same email ID, MoEngage picks the customer_id and uses it to update the opt-in status.
Yes, they are carried forward by default. If User A and B have the same email ID and MoEngage received consent from A, both A and B are marked as double-opted in. This can always be controlled. To do so, contact the MoEngage team.
If the API payload has even one category that is not active or present in your workspace, MoEngage throws an error and drops the request.
No, it is not mandatory. If required, you can always track this at the global level.
Suppose API key rotation is practiced, and the workspace has more than one active API key for a smoother transition. In that case, you can use any active API key associated with Email Double optin for authorization purposes.
Whenever a user's opt-in status is updated using this API, the Resubscribe API, the Update Subscription Preference API, or via the end-user interaction, MoEngage raises an event called Email Optin Status Updated with the necessary information.
- If you use PII Tokenization for your emails, ensure you pass the user ID when calling the Email Opt-in Management API. MoEngage uses this user ID to locate the user and update their opt-in status. Passing the email ID is ineffective in this case, as MoEngage does not store it.
- If you use PII Encryption to send emails, ensure you pass either the user ID or the decrypted email ID. MoEngage uses this information to locate the associated user and update their opt-in status, or to update the opt-in status of all users having that email ID.