curl --request POST \
--url https://api-0{dc}.moengage.com/v1.0/custom-templates/osm \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"basic_details": {
"payload": "<html><body><h1>Your HTML Content Here</h1></body></html>",
"template_type": "BANNER"
},
"meta_info": {
"created_by": "testuser@moengage.com",
"template_id": "123123123",
"template_name": "Test",
"template_version": "1"
}
}
'import requests
url = "https://api-0{dc}.moengage.com/v1.0/custom-templates/osm"
payload = {
"basic_details": {
"payload": "<html><body><h1>Your HTML Content Here</h1></body></html>",
"template_type": "BANNER"
},
"meta_info": {
"created_by": "testuser@moengage.com",
"template_id": "123123123",
"template_name": "Test",
"template_version": "1"
}
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
basic_details: {
payload: '<html><body><h1>Your HTML Content Here</h1></body></html>',
template_type: 'BANNER'
},
meta_info: {
created_by: 'testuser@moengage.com',
template_id: '123123123',
template_name: 'Test',
template_version: '1'
}
})
};
fetch('https://api-0{dc}.moengage.com/v1.0/custom-templates/osm', 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{dc}.moengage.com/v1.0/custom-templates/osm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'basic_details' => [
'payload' => '<html><body><h1>Your HTML Content Here</h1></body></html>',
'template_type' => 'BANNER'
],
'meta_info' => [
'created_by' => 'testuser@moengage.com',
'template_id' => '123123123',
'template_name' => 'Test',
'template_version' => '1'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$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{dc}.moengage.com/v1.0/custom-templates/osm"
payload := strings.NewReader("{\n \"basic_details\": {\n \"payload\": \"<html><body><h1>Your HTML Content Here</h1></body></html>\",\n \"template_type\": \"BANNER\"\n },\n \"meta_info\": {\n \"created_by\": \"testuser@moengage.com\",\n \"template_id\": \"123123123\",\n \"template_name\": \"Test\",\n \"template_version\": \"1\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-0{dc}.moengage.com/v1.0/custom-templates/osm")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"basic_details\": {\n \"payload\": \"<html><body><h1>Your HTML Content Here</h1></body></html>\",\n \"template_type\": \"BANNER\"\n },\n \"meta_info\": {\n \"created_by\": \"testuser@moengage.com\",\n \"template_id\": \"123123123\",\n \"template_name\": \"Test\",\n \"template_version\": \"1\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-0{dc}.moengage.com/v1.0/custom-templates/osm")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"basic_details\": {\n \"payload\": \"<html><body><h1>Your HTML Content Here</h1></body></html>\",\n \"template_type\": \"BANNER\"\n },\n \"meta_info\": {\n \"created_by\": \"testuser@moengage.com\",\n \"template_id\": \"123123123\",\n \"template_name\": \"Test\",\n \"template_version\": \"1\"\n }\n}"
response = http.request(request)
puts response.read_body{
"external_template_id": "d05a44f0-a7cf-471a-bcb6-63054800a367"
}{
"error": {
"code": "400 Bad Request",
"message": "Duplicate - template_id and template_version",
"details": [
{
"code": "InvalidValue",
"target": "Duplicate - template_id and template_version",
"message": "template_id:13343440 template_version:1 is already present."
}
],
"request_id": "xZLmJvUi"
}
}{
"title": "Authentication required",
"description": "MOE-APPKEY missing in Authentication Header"
}{
"title": "Unsupported media type",
"description": "Content type is not supported"
}{
"response_id": "OUUkHvcn",
"type": "custom_template",
"error": {
"code": "Too Many Requests",
"message": "API rate limit breached. Current limit: n/m mins"
}
}{
"title": "Internal Server Error",
"message": "An unexpected error was encountered while processing this request. Please contact MoEngage Team"
}Create OSM Template
Creates a new On-Site Messaging (OSM) template. This API helps you upload templates created outside the MoEngage ecosystem to MoEngage and use them for campaign creation.
curl --request POST \
--url https://api-0{dc}.moengage.com/v1.0/custom-templates/osm \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"basic_details": {
"payload": "<html><body><h1>Your HTML Content Here</h1></body></html>",
"template_type": "BANNER"
},
"meta_info": {
"created_by": "testuser@moengage.com",
"template_id": "123123123",
"template_name": "Test",
"template_version": "1"
}
}
'import requests
url = "https://api-0{dc}.moengage.com/v1.0/custom-templates/osm"
payload = {
"basic_details": {
"payload": "<html><body><h1>Your HTML Content Here</h1></body></html>",
"template_type": "BANNER"
},
"meta_info": {
"created_by": "testuser@moengage.com",
"template_id": "123123123",
"template_name": "Test",
"template_version": "1"
}
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
basic_details: {
payload: '<html><body><h1>Your HTML Content Here</h1></body></html>',
template_type: 'BANNER'
},
meta_info: {
created_by: 'testuser@moengage.com',
template_id: '123123123',
template_name: 'Test',
template_version: '1'
}
})
};
fetch('https://api-0{dc}.moengage.com/v1.0/custom-templates/osm', 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{dc}.moengage.com/v1.0/custom-templates/osm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'basic_details' => [
'payload' => '<html><body><h1>Your HTML Content Here</h1></body></html>',
'template_type' => 'BANNER'
],
'meta_info' => [
'created_by' => 'testuser@moengage.com',
'template_id' => '123123123',
'template_name' => 'Test',
'template_version' => '1'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$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{dc}.moengage.com/v1.0/custom-templates/osm"
payload := strings.NewReader("{\n \"basic_details\": {\n \"payload\": \"<html><body><h1>Your HTML Content Here</h1></body></html>\",\n \"template_type\": \"BANNER\"\n },\n \"meta_info\": {\n \"created_by\": \"testuser@moengage.com\",\n \"template_id\": \"123123123\",\n \"template_name\": \"Test\",\n \"template_version\": \"1\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-0{dc}.moengage.com/v1.0/custom-templates/osm")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"basic_details\": {\n \"payload\": \"<html><body><h1>Your HTML Content Here</h1></body></html>\",\n \"template_type\": \"BANNER\"\n },\n \"meta_info\": {\n \"created_by\": \"testuser@moengage.com\",\n \"template_id\": \"123123123\",\n \"template_name\": \"Test\",\n \"template_version\": \"1\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-0{dc}.moengage.com/v1.0/custom-templates/osm")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"basic_details\": {\n \"payload\": \"<html><body><h1>Your HTML Content Here</h1></body></html>\",\n \"template_type\": \"BANNER\"\n },\n \"meta_info\": {\n \"created_by\": \"testuser@moengage.com\",\n \"template_id\": \"123123123\",\n \"template_name\": \"Test\",\n \"template_version\": \"1\"\n }\n}"
response = http.request(request)
puts response.read_body{
"external_template_id": "d05a44f0-a7cf-471a-bcb6-63054800a367"
}{
"error": {
"code": "400 Bad Request",
"message": "Duplicate - template_id and template_version",
"details": [
{
"code": "InvalidValue",
"target": "Duplicate - template_id and template_version",
"message": "template_id:13343440 template_version:1 is already present."
}
],
"request_id": "xZLmJvUi"
}
}{
"title": "Authentication required",
"description": "MOE-APPKEY missing in Authentication Header"
}{
"title": "Unsupported media type",
"description": "Content type is not supported"
}{
"response_id": "OUUkHvcn",
"type": "custom_template",
"error": {
"code": "Too Many Requests",
"message": "API rate limit breached. Current limit: n/m mins"
}
}{
"title": "Internal Server Error",
"message": "An unexpected error was encountered while processing this request. Please contact MoEngage Team"
}Rate Limit
The rate limit is 100 RPM. You can upload a maximum of 100 templates per minute.Authorizations
The API request is authenticated through Basic Authentication. This 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:
{"Authorization: "Basic Base64_ENCODED_WORKSPACEID_APIKEY=="}
Follow these steps to obtain the username and password from the MoEngage Dashboard:
- Navigate to Settings > Account > APIs.
- Copy the following details:
- Username: Under Workspace ID (earlier App ID), click the copy icon.
- Password: In the API keys section, click the copy icon in the Campaign report/Business events/Custom templates/Catalog API tile.
Body
The details of the OSM template to be created.
Response
Template created successfully.
The unique ID assigned to the newly created template by MoEngage. This ID is used for subsequent updates or searches.
Was this page helpful?