const response = await fetch('https://api.emailit.com/v2/templates', {
method: 'POST',
headers: {
'Authorization': 'Bearer em_test_51RxCWJ...vS00p61e0qRE',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Вітальний лист',
alias: 'welcome-email',
from: 'Підтримка <support@company.com>',
subject: 'Ласкаво просимо до нашого сервісу!',
reply_to: ['support@company.com'],
html: '<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>',
text: 'Ласкаво просимо! Дякуємо, що приєдналися до нас.',
editor: 'html'
})
});
const result = await response.json();
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.emailit.com/v2/templates',
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([
'name' => 'Вітальний лист',
'alias' => 'welcome-email',
'from' => 'Підтримка <support@company.com>',
'subject' => 'Ласкаво просимо до нашого сервісу!',
'reply_to' => ['support@company.com'],
'html' => '<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>',
'text' => 'Ласкаво просимо! Дякуємо, що приєдналися до нас.',
'editor' => 'html'
]),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer em_test_51RxCWJ...vS00p61e0qRE',
'Content-Type: application/json'
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "Помилка cURL #:" . $err;
} else {
$result = json_decode($response, true);
print_r($result);
}
import requests
response = requests.post(
'https://api.emailit.com/v2/templates',
headers={
'Authorization': 'Bearer em_test_51RxCWJ...vS00p61e0qRE',
'Content-Type': 'application/json'
},
json={
'name': 'Вітальний лист',
'alias': 'welcome-email',
'from': 'Підтримка <support@company.com>',
'subject': 'Ласкаво просимо до нашого сервісу!',
'reply_to': ['support@company.com'],
'html': '<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>',
'text': 'Ласкаво просимо! Дякуємо, що приєдналися до нас.',
'editor': 'html'
}
)
result = response.json()
print(result)
require 'net/http'
require 'json'
uri = URI('https://api.emailit.com/v2/templates')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer em_test_51RxCWJ...vS00p61e0qRE'
request['Content-Type'] = 'application/json'
request.body = {
name: 'Вітальний лист',
alias: 'welcome-email',
from: 'Підтримка <support@company.com>',
subject: 'Ласкаво просимо до нашого сервісу!',
reply_to: ['support@company.com'],
html: '<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>',
text: 'Ласкаво просимо! Дякуємо, що приєдналися до нас.',
editor: 'html'
}.to_json
response = http.request(request)
result = JSON.parse(response.body)
puts result
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://api.emailit.com/v2/templates"
data := map[string]interface{}{
"name": "Вітальний лист",
"alias": "welcome-email",
"from": "Підтримка <support@company.com>",
"subject": "Ласкаво просимо до нашого сервісу!",
"reply_to": []string{"support@company.com"},
"html": "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
"text": "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
"editor": "html",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer em_test_51RxCWJ...vS00p61e0qRE")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
use reqwest;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let response = client
.post("https://api.emailit.com/v2/templates")
.header("Authorization", "Bearer em_test_51RxCWJ...vS00p61e0qRE")
.header("Content-Type", "application/json")
.json(&json!({
"name": "Вітальний лист",
"alias": "welcome-email",
"from": "Підтримка <support@company.com>",
"subject": "Ласкаво просимо до нашого сервісу!",
"reply_to": ["support@company.com"],
"html": "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
"text": "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
"editor": "html"
}))
.send()
.await?;
let result: Value = response.json().await?;
println!("{:?}", result);
Ok(())
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import java.net.http.HttpRequest.BodyPublishers;
public class CreateTemplate {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String jsonBody = """
{
"name": "Вітальний лист",
"alias": "welcome-email",
"from": "Підтримка <support@company.com>",
"subject": "Ласкаво просимо до нашого сервісу!",
"reply_to": ["support@company.com"],
"html": "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
"text": "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
"editor": "html"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.emailit.com/v2/templates"))
.header("Authorization", "Bearer em_test_51RxCWJ...vS00p61e0qRE")
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(jsonBody))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class CreateTemplate
{
public static async Task Main()
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization",
"Bearer em_test_51RxCWJ...vS00p61e0qRE");
var data = new {
name = "Вітальний лист",
alias = "welcome-email",
from = "Підтримка <support@company.com>",
subject = "Ласкаво просимо до нашого сервісу!",
reply_to = new[] { "support@company.com" },
html = "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
text = "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
editor = "html"
};
var json = JsonConvert.SerializeObject(data);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(
"https://api.emailit.com/v2/templates", content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
}
curl -X POST https://api.emailit.com/v2/templates \
-H "Authorization: Bearer em_test_51RxCWJ...vS00p61e0qRE" \
-H "Content-Type: application/json" \
-d '{
"name": "Вітальний лист",
"alias": "welcome-email",
"from": "Підтримка <support@company.com>",
"subject": "Ласкаво просимо до нашого сервісу!",
"reply_to": ["support@company.com"],
"html": "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
"text": "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
"editor": "html"
}'
Створення шаблону
const response = await fetch('https://api.emailit.com/v2/templates', {
method: 'POST',
headers: {
'Authorization': 'Bearer em_test_51RxCWJ...vS00p61e0qRE',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Вітальний лист',
alias: 'welcome-email',
from: 'Підтримка <support@company.com>',
subject: 'Ласкаво просимо до нашого сервісу!',
reply_to: ['support@company.com'],
html: '<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>',
text: 'Ласкаво просимо! Дякуємо, що приєдналися до нас.',
editor: 'html'
})
});
const result = await response.json();
{
"data": {
"id": "tem_47TaFwzJx6mD7NeJYvLjFxVwbgT",
"name": "Вітальний лист",
"alias": "welcome-email",
"from": "Підтримка <support@company.com>",
"subject": "Ласкаво просимо до нашого сервісу!",
"reply_to": ["support@company.com"],
"html": "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
"text": "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
"editor": "html",
"published_at": "2025-12-24T10:30:00.000000Z",
"preview_url": null,
"created_at": "2025-12-24T10:30:00.000000Z",
"updated_at": "2025-12-24T10:30:00.000000Z"
},
"message": "Шаблон успішно створено."
}
{
"message": "Помилка валідації",
"errors": {
"name": ["Назва є обов'язковою"],
"alias": ["Псевдонім може містити лише малі літери (a-z), цифри (0-9), підкреслення (_) та дефіси (-)"]
}
}
Відповіді
{
"data": {
"id": "tem_47TaFwzJx6mD7NeJYvLjFxVwbgT",
"name": "Вітальний лист",
"alias": "welcome-email",
"from": "Підтримка <support@company.com>",
"subject": "Ласкаво просимо до нашого сервісу!",
"reply_to": ["support@company.com"],
"html": "<h1>Ласкаво просимо!</h1><p>Дякуємо, що приєдналися до нас.</p>",
"text": "Ласкаво просимо! Дякуємо, що приєдналися до нас.",
"editor": "html",
"published_at": "2025-12-24T10:30:00.000000Z",
"preview_url": null,
"created_at": "2025-12-24T10:30:00.000000Z",
"updated_at": "2025-12-24T10:30:00.000000Z"
},
"message": "Шаблон успішно створено."
}