curl --request PUT \
--url https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: <content-type>' \
--header 'MOE-APPKEY: <moe-appkey>' \
--data '
{
"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"
}
}
'import requests
url = "https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences"
payload = { "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"
} }
headers = {
"MOE-APPKEY": "<moe-appkey>",
"Content-Type": "<content-type>",
"Authorization": "Basic <encoded-value>"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {
'MOE-APPKEY': '<moe-appkey>',
'Content-Type': '<content-type>',
Authorization: 'Basic <encoded-value>'
},
body: JSON.stringify({
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'
}
})
};
fetch('https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'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'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: <content-type>",
"MOE-APPKEY: <moe-appkey>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences"
payload := strings.NewReader("{\n \"user_preferences\": {\n \"customer_id\": \"ID_uid\",\n \"email_id\": \"john@example.com\",\n \"categories\": {\n \"category_1\": true,\n \"category_2\": false\n },\n \"opt_in_status\": \"DOUBLE_OPTED_IN\",\n \"channel\": \"email\"\n }\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("MOE-APPKEY", "<moe-appkey>")
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "Basic <encoded-value>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences")
.header("MOE-APPKEY", "<moe-appkey>")
.header("Content-Type", "<content-type>")
.header("Authorization", "Basic <encoded-value>")
.body("{\n \"user_preferences\": {\n \"customer_id\": \"ID_uid\",\n \"email_id\": \"john@example.com\",\n \"categories\": {\n \"category_1\": true,\n \"category_2\": false\n },\n \"opt_in_status\": \"DOUBLE_OPTED_IN\",\n \"channel\": \"email\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["MOE-APPKEY"] = '<moe-appkey>'
request["Content-Type"] = '<content-type>'
request["Authorization"] = 'Basic <encoded-value>'
request.body = "{\n \"user_preferences\": {\n \"customer_id\": \"ID_uid\",\n \"email_id\": \"john@example.com\",\n \"categories\": {\n \"category_1\": true,\n \"category_2\": false\n },\n \"opt_in_status\": \"DOUBLE_OPTED_IN\",\n \"channel\": \"email\"\n }\n}"
response = http.request(request)
puts response.read_bodyUpdate User Email Opt-in Preferences
Updates a user’s overall email opt-in status and/or category-level subscription preferences within MoEngage. This API is typically used after a user submits the second confirmation through MoEngage consent-seeking emails (Double Opt-in).
curl --request PUT \
--url https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: <content-type>' \
--header 'MOE-APPKEY: <moe-appkey>' \
--data '
{
"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"
}
}
'import requests
url = "https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences"
payload = { "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"
} }
headers = {
"MOE-APPKEY": "<moe-appkey>",
"Content-Type": "<content-type>",
"Authorization": "Basic <encoded-value>"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {
'MOE-APPKEY': '<moe-appkey>',
'Content-Type': '<content-type>',
Authorization: 'Basic <encoded-value>'
},
body: JSON.stringify({
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'
}
})
};
fetch('https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'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'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: <content-type>",
"MOE-APPKEY: <moe-appkey>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences"
payload := strings.NewReader("{\n \"user_preferences\": {\n \"customer_id\": \"ID_uid\",\n \"email_id\": \"john@example.com\",\n \"categories\": {\n \"category_1\": true,\n \"category_2\": false\n },\n \"opt_in_status\": \"DOUBLE_OPTED_IN\",\n \"channel\": \"email\"\n }\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("MOE-APPKEY", "<moe-appkey>")
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "Basic <encoded-value>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences")
.header("MOE-APPKEY", "<moe-appkey>")
.header("Content-Type", "<content-type>")
.header("Authorization", "Basic <encoded-value>")
.body("{\n \"user_preferences\": {\n \"customer_id\": \"ID_uid\",\n \"email_id\": \"john@example.com\",\n \"categories\": {\n \"category_1\": true,\n \"category_2\": false\n },\n \"opt_in_status\": \"DOUBLE_OPTED_IN\",\n \"channel\": \"email\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-0{X}.moengage.com/v1.0/opt-in-management/user-preferences")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["MOE-APPKEY"] = '<moe-appkey>'
request["Content-Type"] = '<content-type>'
request["Authorization"] = 'Basic <encoded-value>'
request.body = "{\n \"user_preferences\": {\n \"customer_id\": \"ID_uid\",\n \"email_id\": \"john@example.com\",\n \"categories\": {\n \"category_1\": true,\n \"category_2\": false\n },\n \"opt_in_status\": \"DOUBLE_OPTED_IN\",\n \"channel\": \"email\"\n }\n}"
response = http.request(request)
puts response.read_bodyRate Limit
The rate limit is 1000 RPM (requests per minute) and 360K requests per day.Authorizations
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_WORKSPACEID_APIKEY=="}
The username and password details can be obtained from the MoEngage Dashboard. If you're using the API for the first time, follow these steps:
- Navigate to Settings -> Account -> APIs.
- Copy the following details:
- Username: Under Workspace ID (earlier app id), click the copy icon to copy the username.
- Password: In 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.
Headers
This is the WORKSPACE ID (earlier APP ID) of your MoEngage workspace. You must pass the MOE-APPKEY in the request.
Find your Workspace ID at Settings -> Account -> APIs -> Workspace ID.
Set the Content-Type header to application/json for this API.
application/json This authentication parameter, used for access control, must be included in the request.
Body
The request body contains the user's email preference details encapsulated in a user_preferences object.
The main wrapper object for the user preferences payload.
Contains the user's opt-in preferences. Must contain either customer_id or email_id.
Show child attributes
Show child attributes
Response
The request has been processed successfully.
Success response body for the Opt-in Management API (200 OK).
The success message denoting the request was processed successfully.
"Your request has been processed successfully"
Was this page helpful?