Integrate our email API
in minutes... literally.

See how easy it is to integrate our email API using your favorite language.

C#PythonPHPGoJavaNode.js
using System.Dynamic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Console.Write(CreateTransaction());
const string apikey = "0123456789012345678901263456789012345678901234567890123456789012";
const string accountId = "012345678901234567";
var txRequest = CreateTransaction();

using HttpClient client = new();
client.BaseAddress = new Uri("https://api.tarvent.com/graphql");
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Content-Type", "application/json");
client.DefaultRequestHeaders.Add("X-API-KEY", apikey);
client.DefaultRequestHeaders.Add("Account", accountId);
var apiResult = await client.PostAsync("", txRequest, new CancellationToken());
var responseBody = apiResult.Content.ReadAsStringAsync(new CancellationToken()).Result;
Console.Write(responseBody);

static StringContent CreateTransaction()
{
    dynamic tarventTxSettings = new
    {
        tracking = new
        {
            opens = true,
            clicks = true,
        },
        ignoreSuppressCheck = false,
    };
    dynamic tarventTxHeader = new
    {
        from = new
        {
            name = "Tarvent Team",
            emailAddress = "hello@yoursendingdomain.com"
        },
        subject = "Tarvent Email Test"
    };
    dynamic tarventTxContents = new
    {
        templateId = "null",
        contentBodies = new List<dynamic> {
    new {
      clickTracking = true,
      mimeType = "HTML",
      charset = "UTF8",
      bodyContent = "<html><body><p>Hello {{Tx.VariableData.FirstName}},</p><p>OMG, it's working!</p></body></html>"
      }}
    };
    var recipientList = new List<ExpandoObject>
  {
    AddRecipient("The Developer", "developer@tarvent.com", null, "TO", new List<dynamic>(), new List<dynamic> {
      new { name = "FirstName", value = "Developer" } })
    };
    dynamic transactionRequest = new
    {
        settings = tarventTxSettings,
        header = tarventTxHeader,
        content = tarventTxContents,
        recipients = recipientList
    };
    var options = new JsonSerializerOptions
    {
        DefaultIgnoreCondition = JsonIgnoreCondition.Never,
        DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
        WriteIndented = true,
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase
    };
    var graphqlCall = "{\"query\": \"mutation createTransaction($input: CreateTransactionInput!) { createTransaction(input: $input) { emailAddress errorCode errorMsg requestId transactionId }}\"," +
      "\"variables\": {\"input\": " + JsonSerializer.Serialize(transactionRequest, options) + "}}";
    var txRequest = new StringContent(graphqlCall, Encoding.UTF8, "application/json");
    return txRequest;
}

static ExpandoObject AddRecipient(string name, string email, string contactId, string type, List<dynamic> metadata, List<dynamic> variables)
{
    dynamic recipient = new ExpandoObject();
    recipient.name = name;
    recipient.emailAddress = email;
    recipient.contactId = contactId;
    recipient.type = type;
    recipient.metadata = metadata;
    recipient.variables = variables;
    return recipient;
}

Github
import json
import requests

def create_transaction():
  tarvent_tx_settings = {
    "tracking": {
      "opens": True,
      "clicks": True,
    },
    "ignoreSuppressCheck": False
  }
  tarvent_tx_header = {
    "from": {
      "name": "Tarvent Team",
      "emailAddress": "hello@yoursendingdomain.com"
    },
    "subject": "This is a test",
  }
  tarvent_tx_contents = {
    "templateId": "null",
    "contentBodies": [{
      "clickTracking": True,
      "mimeType": "HTML",
      "charset": "UTF8",
      "bodyContent": "<html><body><p>Hello {{Tx.VariableData.FirstName}},</p><p>OMG, it's working!</p></body></html>"
    }]
  }
  recipient_list = [
    add_recipient("Developer", "developer@tarvent.com", "", "TO", [{ "name": "FirstName", "value": "Developer"}], [])
  ]
  transaction_request = {
    "groupName": "",
    "settings": tarvent_tx_settings,
    "header": tarvent_tx_header,
    "content": tarvent_tx_contents,
    "recipients": recipient_list
  }
  graphql_call = {
    "query": "mutation createTransaction($input: CreateTransactionInput!) { createTransaction(input: $input) { emailAddress errorCode errorMsg requestId transactionId }}",
    "variables": {"input": transaction_request}
  }
  return json.dumps(graphql_call)

def add_recipient(name, email, contactId, type, metadata, variables):
  recipient = {
    "name": name,
    "emailAddress": email,
    "contactId": contactId,
    "type": type,
    "metadata": metadata,
    "variables": variables
  }
  return recipient

apikey = "0123456789012345678901263456789012345678901234567890123456789012"
account_id = "012345678901234567"
tx_request = create_transaction()
url = "https://api.tarvent.com/graphql"
headers = {
  "Accept": "application/json",
  "Content-Type": "application/json",
  "X-API-KEY": apikey,
  "Account": account_id
}
response = requests.post(url, data=tx_request, headers=headers)
response_body = response.text
print(response_body)

Github
<?php
$apiKey = "0123456789012345678901263456789012345678901234567890123456789012";
$accountId = "012345678901234567";
$txRequest = createTransaction();

$baseUri = "https://api.tarvent.com/graphql";
$headers = [
    "Accept: application/json",
    "Content-Type: application/json",
    "X-API-KEY: $apiKey",
    "Account: $accountId",
];

echo $txRequest;

$ch = curl_init($baseUri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $txRequest);

$response = curl_exec($ch);
curl_close($ch);

if ($response === FALSE) {
    echo "cUrl error (#%d): %s
\n"; } echo $response; function createTransaction() { $tarventTxSettings = [ "tracking" => [ "opens" => true, "clicks" => true ], "ignoreSuppressCheck" => false ]; $tarventTxHeader = [ "from" => [ "name" => "Tarvent Team", "emailAddress" => "hello@yoursendingdomain.com" ], "subject" => "This is a test" ]; $tarventTxContents = [ "templateId" => "null", "contentBodies" => [ [ "clickTracking" => true, "mimeType" => "HTML", "charset" => "UTF8", "bodyContent" => "<html><body><p>Hello {{Tx.VariableData.FirstName}},</p><p>OMG, it's working!</p></body></html>" ] ] ]; $recipientList = [ addRecipient("Developer", "developer@tarvent.com", null, "TO", [], [[ "name" => "FirstName", "value" => "Developer" ]]) ]; $transactionRequest = [ "groupName" => "", "settings" => $tarventTxSettings, "header" => $tarventTxHeader, "content" => $tarventTxContents, "recipients" => $recipientList ]; $graphqlCall = [ "query" => 'mutation createTransaction($input: CreateTransactionInput!) { createTransaction(input: $input) { emailAddress errorCode errorMsg requestId transactionId }}', "variables" => ["input" => $transactionRequest] ]; $txRequest = json_encode($graphqlCall); return $txRequest; } function addRecipient($name, $email, $contactId, $type, $metadata, $variables) { $recipient = new stdClass(); $recipient->name = $name; $recipient->emailAddress = $email; $recipient->contactId = $contactId; $recipient->type = $type; $recipient->metadata = $metadata; $recipient->variables = $variables; return $recipient; } ?>
Github
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"strings"
)

func main() {
	txRequest := createTransaction()
	apiKey := "0123456789012345678901263456789012345678901234567890123456789012"
	accountId := "012345678901234567"

	client := &http.Client{}
	url := "https://api.tarvent.com/graphql"
	req, err := http.NewRequest("POST", url, strings.NewReader(txRequest))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(req.URL)

	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("X-API-KEY", apiKey)
	req.Header.Set("Account", accountId)

	resp, err := client.Do(req)

	fmt.Println(resp, err)
	if err != nil {
		fmt.Println(err)
		return
	}

	defer resp.Body.Close()

	responseBody := new(bytes.Buffer)
	_, err = responseBody.ReadFrom(resp.Body)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(responseBody.String())
}

func createTransaction() string {
	tarventTxSettings := map[string]interface{}{
		"tracking": map[string]interface{}{
			"opens":  true,
			"clicks": true,
		},
		"ignoreSuppressCheck": false,
	}

	tarventTxHeader := map[string]interface{}{
		"from": map[string]interface{}{
			"name":         "Tarvent Team",
			"emailAddress": "hello@yoursendingdomain.com",
		},
		"subject":       "This is a test",
	}

	tarventTxContents := map[string]interface{}{
		"templateId": "null",
		"contentBodies": []map[string]interface{}{
			{
				"clickTracking": true,
				"mimeType":      "HTML",
				"charset":       "UTF8",
				"bodyContent":   "<html><body><p>Hello {{Tx.VariableData.FirstName}},</p><p>OMG, it's working!</p></body></html>",
			}},
	}

	recipientList := []map[string]interface{}{
		addRecipient("Developer", "developer@tarvent.com", "", "TO", []map[string]interface{}{}, []map[string]interface{}{
			{"name": "FirstName", "value": "Developer"}}),
	}

	transactionRequest := map[string]interface{}{
		"settings":   tarventTxSettings,
		"header":     tarventTxHeader,
		"content":    tarventTxContents,
		"recipients": recipientList,
	}

	jsonBytes, err := json.Marshal(map[string]interface{}{
		"query":     "mutation createTransaction($input: CreateTransactionInput!) { createTransaction(input: $input) { emailAddress errorCode errorMsg requestId transactionId }}",
		"variables": map[string]interface{}{"input": transactionRequest},
	})
	if err != nil {
		fmt.Println("Error:", err)
		return ""
	}

	return string(jsonBytes)
}

func addRecipient(name, email, contactId, typ string, metadata, variables []map[string]interface{}) map[string]interface{} {
	recipient := map[string]interface{}{
		"name":         name,
		"emailAddress": email,
		"contactId":    contactId,
		"type":         typ,
		"metadata":     metadata,
		"variables":    variables,
	}
	return recipient
}

Github
package com.example;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;

public class Main {

    public static void main(String[] args) {
        String requestBody = createTransaction();
        String apiKey = "0123456789012345678901263456789012345678901234567890123456789012";
        String accountId = "012345678901234567";

        HttpClient client = HttpClient.newBuilder().build();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.tarvent.com/graphql"))
                .header("Accept", "application/json")
                .header("Content-Type", "application/json")
                .header("X-API-KEY", apiKey)
                .header("Account", accountId)
                .POST(HttpRequest.BodyPublishers.ofString(requestBody, StandardCharsets.UTF_8))
                .build();

        try {
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
            String responseBody = response.body();
            System.out.println(responseBody);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    static String createTransaction() {
        Map<String, Object> tarventTxSettings = new HashMap<>();

        Map<String, Object> tracking = new HashMap<>();
        tracking.put("opens", true);
        tracking.put("clicks", true);
        tarventTxSettings.put("tracking", tracking);
        tarventTxSettings.put("ignoreSuppressCheck", false);

        Map<String, Object> tarventTxHeader = new HashMap<>();
        Map<String, Object> from = new HashMap<>();
        from.put("name", "Tarvent Team");
        from.put("emailAddress", "hello@yoursendingdomain.com");
        tarventTxHeader.put("from", from);
        tarventTxHeader.put("subject", "This is a test");

        Map<String, Object> tarventTxContents = new HashMap<>();
        tarventTxContents.put("templateId", "null");

        List<Map<String, Object>> contentBodies = new ArrayList<>();
        Map<String, Object> contentBody0 = new HashMap<>();
        contentBody0.put("clickTracking", true);
        contentBody0.put("mimeType", "HTML");
        contentBody0.put("charset", "UTF8");
        contentBody0.put("bodyContent", "<html><body><p>Hello {{Tx.VariableData.FirstName}},</p><p>OMG, it's working!</p></body></html>");
        contentBodies.add(contentBody0);
        tarventTxContents.put("contentBodies", contentBodies);

        List<Map<String, Object>> recipientList = new ArrayList<>();
        recipientList
                .add(addRecipient("Developer", "developer@tarvent.com", null, "TO", new ArrayList<Map<String, String>>(), List.of(Map.of("name", "FirstName", "value", "Developer"))));

        Map<String, Object> transactionRequest = new HashMap<>();
        transactionRequest.put("groupName", "Notification Email");
        transactionRequest.put("settings", tarventTxSettings);
        transactionRequest.put("header", tarventTxHeader);
        transactionRequest.put("content", tarventTxContents);
        transactionRequest.put("recipients", recipientList);

        String requestJsonString = "";
        try {
            requestJsonString = new com.fasterxml.jackson.databind.ObjectMapper()
                    .writeValueAsString(transactionRequest);
        } catch (JsonProcessingException e) { }

        // Create JSON
        String jsonString = "{\"query\": \"mutation createTransaction($input: CreateTransactionInput!) { createTransaction(input: $input) { emailAddress errorCode errorMsg requestId transactionId }}\", "
                +
                "\"variables\": {\"input\": " + requestJsonString + "}}";
        System.out.println(jsonString);
        return jsonString;
    }

    static Map<String, Object> addRecipient(String name, String email, String contactId, String type,
            List<Map<String, String>> metadata, List<Map<String, String>> variables) {
        Map<String, Object> recipient = new HashMap<>();
        recipient.put("name", name);
        recipient.put("emailAddress", email);
        recipient.put("contactId", contactId);
        recipient.put("type", type);
        recipient.put("metadata", metadata);
        recipient.put("variables", variables);

        return recipient;
    }
}

Github
const axios = require('axios');
(async () => {
  console.log(await createTransaction());
}
)();
async function createTransaction() {
  const tarventTxSettings = {
    tracking: {
      opens: true,
      clicks: true
    },
    ignoreSuppressCheck: false
  };
  const tarventTxHeader = {
    from: {
      name: 'Tarvent team',
      emailAddress: 'hello@yoursendingdomain.com'
    },
    subject: 'This is a test',
  };
  const tarventTxContents = {
    templateId: null,
    contentBodies: [{
      clickTracking: true,
      mimeType: "HTML",
      charset: "UTF8",
      bodyContent: "<html><body><p>Hello {{Tx.VariableData.FirstName}},</p><p>OMG, it's working!</p></body></html>"
    }]
  };
  const recipientList = [
    addRecipient('Developer', 'developer@tarvent.com', null, 'TO', [], [
      { name: "FirstName", value: "Developer" }
    ])
  ];
  const transactionRequest = {
    groupName: '',
    settings: tarventTxSettings,
    header: tarventTxHeader,
    content: tarventTxContents,
    recipients: recipientList,
  };
  const graphqlCall = {
    query: 'mutation createTransaction($input: CreateTransactionInput!) { createTransaction(input: $input) { emailAddress errorCode errorMsg requestId transactionId }}',
    variables: {
      input: transactionRequest,
    }
  };
  const response = await axios.post('https://api.tarvent.com/graphql', graphqlCall, {
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'X-API-KEY': '0123456789012345678901263456789012345678901234567890123456789012',
      'Account': '012345678901234567',
    }
  });
  console.log(JSON.stringify(response.data));
}
function addRecipient(name, email, contactId, type, metadata, variables) {
  const recipient = {
    name: name,
    emailAddress: email,
    contactId: contactId,
    type: type,
    metadata: metadata,
    variables: variables
  };
  return recipient;
}

Github

Stop reading help docs and get coding

Our form-based code generator is the best thing since sliced bread. We show you have to configure 100% of our functionality in a single page with every detailed laid out, if you need it.

You only need 1 entry point, not hundreds

GraphQL-based APIs have only 1 entry point. Even better, we have an entire tool dedicated to you, allowing you to discover everything our graph offers without having to read the documentation.
GraphQL documentation