import { Migma } from 'migma';
const migma = new Migma('YOUR_API_KEY');
const { data, error } = await migma.export.pushToKlaviyo(
'CONVERSATION_ID',
{ name: 'Spring sale' },
{ idempotencyKey: 'push-spring-sale-1' }
);
// data.editorUrl opens the template in Klaviyo; data.images.kept lists images still on Migma.curl --request POST \
--url https://api.migma.ai/v1/export/klaviyo/{conversationId}/push \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"name": "Spring sale"
}
'import requests
url = "https://api.migma.ai/v1/export/klaviyo/{conversationId}/push"
payload = { "name": "Spring sale" }
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.migma.ai/v1/export/klaviyo/{conversationId}/push",
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' => 'Spring sale'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$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.migma.ai/v1/export/klaviyo/{conversationId}/push"
payload := strings.NewReader("{\n \"name\": \"Spring sale\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "<api-key>")
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.migma.ai/v1/export/klaviyo/{conversationId}/push")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Spring sale\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.migma.ai/v1/export/klaviyo/{conversationId}/push")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Spring sale\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"templateId": "WJ3kbV",
"name": "Spring sale",
"editorUrl": "https://www.klaviyo.com/email-editor/WJ3kbV/edit",
"connectionId": "6735f0c2a1b2c3d4e5f60718",
"images": {
"hosted": 4,
"kept": []
}
},
"error": "<string>"
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}Create Klaviyo template
Create an HTML template in the brand’s connected Klaviyo account from a Migma email. Migma images are copied into the account’s image library and the template links the copies; an image Klaviyo does not take keeps its Migma address and is listed under images.kept with the reason. Countdown timers and images on other sites stay as they are. Use this when the email should live in Klaviyo: the download from GET /v1/export/klaviyo/{conversationId} keeps images on Migma.
The brand is the conversation’s brand, and its owner must have connected Klaviyo in Migma. Needs the email:read and campaign:write scopes, a paid plan, and permission to publish the brand’s emails. An Idempotency-Key header is required: send the same key when retrying, so a retry returns the first template instead of creating another. A server error is not stored for replay, so after a 5xx check the account’s templates before retrying.
import { Migma } from 'migma';
const migma = new Migma('YOUR_API_KEY');
const { data, error } = await migma.export.pushToKlaviyo(
'CONVERSATION_ID',
{ name: 'Spring sale' },
{ idempotencyKey: 'push-spring-sale-1' }
);
// data.editorUrl opens the template in Klaviyo; data.images.kept lists images still on Migma.curl --request POST \
--url https://api.migma.ai/v1/export/klaviyo/{conversationId}/push \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"name": "Spring sale"
}
'import requests
url = "https://api.migma.ai/v1/export/klaviyo/{conversationId}/push"
payload = { "name": "Spring sale" }
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.migma.ai/v1/export/klaviyo/{conversationId}/push",
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' => 'Spring sale'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$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.migma.ai/v1/export/klaviyo/{conversationId}/push"
payload := strings.NewReader("{\n \"name\": \"Spring sale\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "<api-key>")
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.migma.ai/v1/export/klaviyo/{conversationId}/push")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Spring sale\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.migma.ai/v1/export/klaviyo/{conversationId}/push")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Spring sale\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"templateId": "WJ3kbV",
"name": "Spring sale",
"editorUrl": "https://www.klaviyo.com/email-editor/WJ3kbV/edit",
"connectionId": "6735f0c2a1b2c3d4e5f60718",
"images": {
"hosted": 4,
"kept": []
}
},
"error": "<string>"
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}Authorizations
Headers
Required key of at most 100 characters. Same key and same body within 24 hours replays the created template, so no second one is made; same key with a different body after a success returns 409 IDEMPOTENCY_CONFLICT. Refusals are not stored, so after connecting Klaviyo or choosing an account, retry with the same key. Scoped per API key. Use a new key for a new template.
100Body
Response
Template created in Klaviyo
Was this page helpful?