From d3f49a5c5f91af08fd23cadf84f30386acbb5571 Mon Sep 17 00:00:00 2001 From: Marcin Klocek Date: Thu, 6 Aug 2026 16:32:27 +0200 Subject: [PATCH 1/6] Add SDK code samples to inbound email endpoints Document all 19 inbound operations (folders, inboxes, messages, threads) with Node.js, PHP, Python, Ruby, .NET, and Java examples alongside the existing cURL, matching the x-codeSamples convention used across the other specs. Resource IDs use named variables (env vars for PHP) rather than inline literals. --- specs/inbound.openapi.yml | 1434 +++++++++++++++++++++++++++++++++++++ 1 file changed, 1434 insertions(+) diff --git a/specs/inbound.openapi.yml b/specs/inbound.openapi.yml index 8dcdd60..30cd3b5 100644 --- a/specs/inbound.openapi.yml +++ b/specs/inbound.openapi.yml @@ -76,6 +76,67 @@ paths: source: | curl -X GET https://mailtrap.io/api/inbound/folders \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folders = await client.inbound.folders.getList(); + console.log(folders); + - lang: php + label: PHP + source: | + folders(); + + $response = $folders->getList(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folders = client.inbound_api.folders.get_list() + print(folders) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + folders = Mailtrap::InboundFoldersAPI.new(client) + + puts folders.list + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folders = await client.Inbound().Folders().GetAll(); + Console.WriteLine(folders.Count); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + var folders = client.inboundApi().folders().getList(); + System.out.println(folders); responses: "200": description: List of folders @@ -109,6 +170,75 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "Support" }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folder = await client.inbound.folders.create({ name: "Support" }); + console.log(folder); + - lang: php + label: PHP + source: | + folders(); + + $response = $folders->create(new CreateInboundFolder('Support')); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder = client.inbound_api.folders.create( + mt.CreateInboundFolderParams(name="Support") + ) + print(folder) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + folders = Mailtrap::InboundFoldersAPI.new(client) + + folder = folders.create(name: 'Support') + puts folder + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folder = await client.Inbound().Folders() + .Create(new CreateInboundFolderRequest { Name = "Support" }); + Console.WriteLine(folder.Id); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.inbound.CreateInboundFolderRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + var folder = client.inboundApi().folders() + .create(CreateInboundFolderRequest.builder().name("Support").build()); + System.out.println(folder); requestBody: required: true content: @@ -147,6 +277,73 @@ paths: source: | curl -X GET https://mailtrap.io/api/inbound/folders/{folder_id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + const folder = await client.inbound.folders.get(folderId); + console.log(folder); + - lang: php + label: PHP + source: | + folders(); + + $folderId = $_ENV['MAILTRAP_INBOUND_FOLDER_ID']; + $response = $folders->getById($folderId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + folder = client.inbound_api.folders.get_by_id(folder_id) + print(folder) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + folders = Mailtrap::InboundFoldersAPI.new(client) + + folder_id = 1 + puts folders.get(folder_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + var folder = await client.Inbound().Folder(folderId).GetDetails(); + Console.WriteLine(folder.Name); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + var folder = client.inboundApi().folders().getById(folderId); + System.out.println(folder); responses: "200": description: Folder details @@ -177,6 +374,80 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "Customer Success" }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + const folder = await client.inbound.folders.update(folderId, { name: "Customer Success" }); + console.log(folder); + - lang: php + label: PHP + source: | + folders(); + + $folderId = $_ENV['MAILTRAP_INBOUND_FOLDER_ID']; + $response = $folders->update($folderId, new UpdateInboundFolder('Customer Success')); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + folder = client.inbound_api.folders.update( + folder_id, mt.UpdateInboundFolderParams(name="Customer Success") + ) + print(folder) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + folders = Mailtrap::InboundFoldersAPI.new(client) + + folder_id = 1 + puts folders.update(folder_id, name: 'Customer Success') + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + var folder = await client.Inbound().Folder(folderId) + .Update(new UpdateInboundFolderRequest { Name = "Customer Success" }); + Console.WriteLine(folder.Name); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.inbound.UpdateInboundFolderRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + var folder = client.inboundApi().folders() + .update(folderId, UpdateInboundFolderRequest.builder().name("Customer Success").build()); + System.out.println(folder); requestBody: required: true content: @@ -214,6 +485,68 @@ paths: source: | curl -X DELETE https://mailtrap.io/api/inbound/folders/{folder_id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + await client.inbound.folders.delete(folderId); + - lang: php + label: PHP + source: | + folders(); + + $folderId = $_ENV['MAILTRAP_INBOUND_FOLDER_ID']; + $response = $folders->delete($folderId); + echo $response->getStatusCode(); // 204 + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + client.inbound_api.folders.delete(folder_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + folders = Mailtrap::InboundFoldersAPI.new(client) + + folder_id = 1 + folders.delete(folder_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + await client.Inbound().Folder(folderId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + client.inboundApi().folders().delete(folderId); responses: "204": description: Folder deleted @@ -239,6 +572,73 @@ paths: source: | curl -X GET https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + const inboxes = await client.inbound.inboxes.getList(folderId); + console.log(inboxes); + - lang: php + label: PHP + source: | + inboxes($folderId); + + $response = $inboxes->getList(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + inboxes = client.inbound_api.inboxes.get_list(folder_id) + print(inboxes) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + inboxes = Mailtrap::InboundInboxesAPI.new(client) + + folder_id = 1 + puts inboxes.list(folder_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + var inboxes = await client.Inbound().Folder(folderId).Inboxes().GetAll(); + Console.WriteLine(inboxes.Count); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + var inboxes = client.inboundApi().inboxes().getList(folderId); + System.out.println(inboxes); responses: "200": description: List of inboxes @@ -287,6 +687,87 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "Support tickets" }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + // Omit domain_id for a Mailtrap-hosted inbox; pass it for a custom-domain inbox. + const folderId = 1; + const inbox = await client.inbound.inboxes.create(folderId, { name: "Support tickets" }); + console.log(inbox); + - lang: php + label: PHP + source: | + inboxes($folderId); + + // Omit the domain id for a Mailtrap-hosted inbox; pass it for a custom-domain inbox. + $response = $inboxes->create(new CreateInboundInbox('Support tickets')); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + # Omit domain_id for a Mailtrap-hosted inbox; pass it for a custom-domain inbox. + folder_id = 1 + inbox = client.inbound_api.inboxes.create( + folder_id, mt.CreateInboundInboxParams(name="Support tickets") + ) + print(inbox) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + inboxes = Mailtrap::InboundInboxesAPI.new(client) + + # Omit domain_id for a Mailtrap-hosted inbox; pass it for a custom-domain inbox. + folder_id = 1 + inbox = inboxes.create(folder_id, name: 'Support tickets') + puts inbox + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + // Omit DomainId for a Mailtrap-hosted inbox; set it for a custom-domain inbox. + var folderId = 1; + var inbox = await client.Inbound().Folder(folderId).Inboxes() + .Create(new CreateInboundInboxRequest { Name = "Support tickets" }); + Console.WriteLine(inbox.Id); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.inbound.CreateInboundInboxRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + // Omit domainId for a Mailtrap-hosted inbox; set it for a custom-domain inbox. + long folderId = 1L; + var inbox = client.inboundApi().inboxes() + .create(folderId, CreateInboundInboxRequest.builder().name("Support tickets").build()); + System.out.println(inbox); requestBody: required: true content: @@ -340,6 +821,79 @@ paths: source: | curl -X GET https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes/{inbox_id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + const inboxId = 42; + const inbox = await client.inbound.inboxes.get(folderId, inboxId); + console.log(inbox); + - lang: php + label: PHP + source: | + inboxes($folderId); + + $inboxId = $_ENV['MAILTRAP_INBOUND_INBOX_ID']; + $response = $inboxes->getById($inboxId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + inbox_id = 42 + inbox = client.inbound_api.inboxes.get_by_id(folder_id, inbox_id) + print(inbox) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + inboxes = Mailtrap::InboundInboxesAPI.new(client) + + folder_id = 1 + inbox_id = 42 + puts inboxes.get(folder_id, inbox_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + var inboxId = 42; + var inbox = await client.Inbound().Folder(folderId).Inbox(inboxId).GetDetails(); + Console.WriteLine(inbox.Address); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + long inboxId = 42L; + var inbox = client.inboundApi().inboxes().getById(folderId, inboxId); + System.out.println(inbox); responses: "200": description: Inbox details @@ -372,6 +926,86 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "Support tickets v2" }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + const inboxId = 42; + const inbox = await client.inbound.inboxes.update(folderId, inboxId, { name: "Support tickets v2" }); + console.log(inbox); + - lang: php + label: PHP + source: | + inboxes($folderId); + + $inboxId = $_ENV['MAILTRAP_INBOUND_INBOX_ID']; + $response = $inboxes->update($inboxId, new UpdateInboundInbox('Support tickets v2')); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + inbox_id = 42 + inbox = client.inbound_api.inboxes.update( + folder_id, inbox_id, mt.UpdateInboundInboxParams(name="Support tickets v2") + ) + print(inbox) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + inboxes = Mailtrap::InboundInboxesAPI.new(client) + + folder_id = 1 + inbox_id = 42 + puts inboxes.update(folder_id, inbox_id, name: 'Support tickets v2') + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + var inboxId = 42; + var inbox = await client.Inbound().Folder(folderId).Inbox(inboxId) + .Update(new UpdateInboundInboxRequest { Name = "Support tickets v2" }); + Console.WriteLine(inbox.Name); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.inbound.UpdateInboundInboxRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + long inboxId = 42L; + var inbox = client.inboundApi().inboxes() + .update(folderId, inboxId, UpdateInboundInboxRequest.builder().name("Support tickets v2").build()); + System.out.println(inbox); requestBody: required: true content: @@ -410,6 +1044,74 @@ paths: source: | curl -X DELETE https://mailtrap.io/api/inbound/folders/{folder_id}/inboxes/{inbox_id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const folderId = 1; + const inboxId = 42; + await client.inbound.inboxes.delete(folderId, inboxId); + - lang: php + label: PHP + source: | + inboxes($folderId); + + $inboxId = $_ENV['MAILTRAP_INBOUND_INBOX_ID']; + $response = $inboxes->delete($inboxId); + echo $response->getStatusCode(); // 204 + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + folder_id = 1 + inbox_id = 42 + client.inbound_api.inboxes.delete(folder_id, inbox_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + inboxes = Mailtrap::InboundInboxesAPI.new(client) + + folder_id = 1 + inbox_id = 42 + inboxes.delete(folder_id, inbox_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var folderId = 1; + var inboxId = 42; + await client.Inbound().Folder(folderId).Inbox(inboxId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long folderId = 1L; + long inboxId = 42L; + client.inboundApi().inboxes().delete(folderId, inboxId); responses: "204": description: Inbox deleted @@ -452,6 +1154,79 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/inbound/inboxes/{inbox_id}/messages' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + // Pass { last_id: page.last_id } to fetch the next page. + const inboxId = 42; + const page = await client.inbound.messages.getList(inboxId); + console.log(page.data, page.total_count, page.last_id); + - lang: php + label: PHP + source: | + messages($inboxId); + + // Pass a last_id string to fetch the next page. + $response = $messages->getList(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + # Pass last_id=page.last_id to fetch the next page. + inbox_id = 42 + page = client.inbound_api.messages.get_list(inbox_id) + print(page.data, page.total_count, page.last_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + messages = Mailtrap::InboundMessagesAPI.new(client) + + # Pass last_id: page.last_id to fetch the next page. + inbox_id = 42 + page = messages.list(inbox_id) + puts page.total_count + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var page = await client.Inbound().Inbox(inboxId).Messages().List(); + Console.WriteLine(page.TotalCount); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + // Pass the previous page's last id to paginate (null for the first page). + long inboxId = 42L; + var page = client.inboundApi().messages().list(inboxId, null); + System.out.println(page.getTotalCount()); responses: "200": description: List of messages @@ -515,6 +1290,79 @@ paths: source: | curl -X GET https://mailtrap.io/api/inbound/inboxes/{inbox_id}/messages/{id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const messageId = "1700000000000123"; + const message = await client.inbound.messages.get(inboxId, messageId); + console.log(message.subject); + - lang: php + label: PHP + source: | + messages($inboxId); + + $messageId = $_ENV['MAILTRAP_INBOUND_MESSAGE_ID']; + $response = $messages->getById($messageId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + message_id = "1700000000000123" + message = client.inbound_api.messages.get_by_id(inbox_id, message_id) + print(message.subject) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + messages = Mailtrap::InboundMessagesAPI.new(client) + + inbox_id = 42 + message_id = '1700000000000123' + puts messages.get(inbox_id, message_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var messageId = "1700000000000123"; + var message = await client.Inbound().Inbox(inboxId).Message(messageId).GetDetails(); + Console.WriteLine(message.Subject); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String messageId = "1700000000000123"; + var message = client.inboundApi().messages().get(inboxId, messageId); + System.out.println(message.getSubject()); responses: "200": description: Message details @@ -546,6 +1394,74 @@ paths: source: | curl -X DELETE https://mailtrap.io/api/inbound/inboxes/{inbox_id}/messages/{id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const messageId = "1700000000000123"; + await client.inbound.messages.delete(inboxId, messageId); + - lang: php + label: PHP + source: | + messages($inboxId); + + $messageId = $_ENV['MAILTRAP_INBOUND_MESSAGE_ID']; + $response = $messages->delete($messageId); + echo $response->getStatusCode(); // 204 + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + message_id = "1700000000000123" + client.inbound_api.messages.delete(inbox_id, message_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + messages = Mailtrap::InboundMessagesAPI.new(client) + + inbox_id = 42 + message_id = '1700000000000123' + messages.delete(inbox_id, message_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var messageId = "1700000000000123"; + await client.Inbound().Inbox(inboxId).Message(messageId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String messageId = "1700000000000123"; + client.inboundApi().messages().delete(inboxId, messageId); responses: "204": description: Message deleted @@ -598,6 +1514,110 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "text": "Thanks for reaching out. We are looking into it." }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const messageId = "1700000000000123"; + const result = await client.inbound.messages.reply(inboxId, messageId, { + text: "Thanks for reaching out. We are looking into it.", + html: "

Thanks for reaching out. We are looking into it.

", + }); + console.log(result.message_ids); + - lang: php + label: PHP + source: | + messages($inboxId); + + $email = (new Email()) + ->text('Thanks for reaching out. We are looking into it.') + ->html('

Thanks for reaching out. We are looking into it.

'); + + $messageId = $_ENV['MAILTRAP_INBOUND_MESSAGE_ID']; + $response = $messages->reply($messageId, $email); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + message_id = "1700000000000123" + result = client.inbound_api.messages.reply( + inbox_id, + message_id, + mt.ReplyInboundMessageParams( + text="Thanks for reaching out. We are looking into it.", + html="

Thanks for reaching out. We are looking into it.

", + ), + ) + print(result.message_ids) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + messages = Mailtrap::InboundMessagesAPI.new(client) + + inbox_id = 42 + message_id = '1700000000000123' + result = messages.reply( + inbox_id, message_id, + text: 'Thanks for reaching out. We are looking into it.', + html: '

Thanks for reaching out. We are looking into it.

' + ) + puts result.message_ids + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var messageId = "1700000000000123"; + var result = await client.Inbound().Inbox(inboxId).Message(messageId) + .Reply(new ReplyInboundMessageRequest + { + Text = "Thanks for reaching out. We are looking into it.", + Html = "

Thanks for reaching out. We are looking into it.

", + }); + Console.WriteLine(string.Join(",", result.MessageIds)); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.inbound.InboundReplyRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String messageId = "1700000000000123"; + var result = client.inboundApi().messages().reply(inboxId, messageId, + InboundReplyRequest.builder() + .text("Thanks for reaching out. We are looking into it.") + .html("

Thanks for reaching out. We are looking into it.

") + .build()); + System.out.println(result); responses: "201": $ref: "#/components/responses/SendMessageAccepted" @@ -647,6 +1667,98 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "text": "Thanks all. Adding my colleague to the thread." }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const messageId = "1700000000000123"; + const result = await client.inbound.messages.replyAll(inboxId, messageId, { + text: "Thanks all. Adding my colleague to the thread.", + }); + console.log(result.message_ids); + - lang: php + label: PHP + source: | + messages($inboxId); + + $email = (new Email())->text('Thanks all. Adding my colleague to the thread.'); + + $messageId = $_ENV['MAILTRAP_INBOUND_MESSAGE_ID']; + $response = $messages->replyAll($messageId, $email); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + message_id = "1700000000000123" + result = client.inbound_api.messages.reply_all( + inbox_id, + message_id, + mt.ReplyInboundMessageParams(text="Thanks all. Adding my colleague to the thread."), + ) + print(result.message_ids) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + messages = Mailtrap::InboundMessagesAPI.new(client) + + inbox_id = 42 + message_id = '1700000000000123' + result = messages.reply_all(inbox_id, message_id, text: 'Thanks all. Adding my colleague to the thread.') + puts result.message_ids + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var messageId = "1700000000000123"; + var result = await client.Inbound().Inbox(inboxId).Message(messageId) + .ReplyAll(new ReplyInboundMessageRequest + { + Text = "Thanks all. Adding my colleague to the thread.", + }); + Console.WriteLine(string.Join(",", result.MessageIds)); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.inbound.InboundReplyRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String messageId = "1700000000000123"; + var result = client.inboundApi().messages().replyAll(inboxId, messageId, + InboundReplyRequest.builder() + .text("Thanks all. Adding my colleague to the thread.") + .build()); + System.out.println(result); responses: "201": $ref: "#/components/responses/SendMessageAccepted" @@ -702,6 +1814,114 @@ paths: -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "to": [{ "email": "colleague@example.com" }], "text": "Please take a look at the message below." }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const messageId = "1700000000000123"; + const result = await client.inbound.messages.forward(inboxId, messageId, { + to: [{ email: "colleague@example.com" }], + text: "Please take a look at the message below.", + }); + console.log(result.message_ids); + - lang: php + label: PHP + source: | + messages($inboxId); + + $email = (new Email()) + ->to(new Address('colleague@example.com')) + ->text('Please take a look at the message below.'); + + $messageId = $_ENV['MAILTRAP_INBOUND_MESSAGE_ID']; + $response = $messages->forward($messageId, $email); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + message_id = "1700000000000123" + result = client.inbound_api.messages.forward( + inbox_id, + message_id, + mt.ForwardInboundMessageParams( + to=[mt.Address(email="colleague@example.com")], + text="Please take a look at the message below.", + ), + ) + print(result.message_ids) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + messages = Mailtrap::InboundMessagesAPI.new(client) + + inbox_id = 42 + message_id = '1700000000000123' + result = messages.forward( + inbox_id, message_id, + to: [{ email: 'colleague@example.com' }], + text: 'Please take a look at the message below.' + ) + puts result.message_ids + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Emails.Models; + using Mailtrap.Inbound.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var messageId = "1700000000000123"; + var result = await client.Inbound().Inbox(inboxId).Message(messageId) + .Forward(new ForwardInboundMessageRequest + { + To = [new EmailAddress("colleague@example.com")], + Text = "Please take a look at the message below.", + }); + Console.WriteLine(string.Join(",", result.MessageIds)); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.emails.Address; + import io.mailtrap.model.request.inbound.InboundForwardRequest; + import java.util.List; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String messageId = "1700000000000123"; + var result = client.inboundApi().messages().forward(inboxId, messageId, + InboundForwardRequest.builder() + .to(List.of(new Address("colleague@example.com"))) + .text("Please take a look at the message below.") + .build()); + System.out.println(result); responses: "201": $ref: "#/components/responses/SendMessageAccepted" @@ -753,6 +1973,79 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/inbound/inboxes/{inbox_id}/threads' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + // Pass { last_id: page.last_id } to fetch the next page. + const inboxId = 42; + const page = await client.inbound.threads.getList(inboxId); + console.log(page.data, page.total_count, page.last_id); + - lang: php + label: PHP + source: | + threads($inboxId); + + // Pass a last_id string to fetch the next page. + $response = $threads->getList(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + # Pass last_id=page.last_id to fetch the next page. + inbox_id = 42 + page = client.inbound_api.threads.get_list(inbox_id) + print(page.data, page.total_count, page.last_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + threads = Mailtrap::InboundThreadsAPI.new(client) + + # Pass last_id: page.last_id to fetch the next page. + inbox_id = 42 + page = threads.list(inbox_id) + puts page.total_count + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var page = await client.Inbound().Inbox(inboxId).Threads().List(); + Console.WriteLine(page.TotalCount); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + // Pass the previous page's last id to paginate (null for the first page). + long inboxId = 42L; + var page = client.inboundApi().threads().list(inboxId, null); + System.out.println(page.getTotalCount()); responses: "200": description: List of threads @@ -823,6 +2116,79 @@ paths: source: | curl -X GET https://mailtrap.io/api/inbound/inboxes/{inbox_id}/threads/{id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const threadId = "1700000000000124"; + const thread = await client.inbound.threads.get(inboxId, threadId); + console.log(thread); + - lang: php + label: PHP + source: | + threads($inboxId); + + $threadId = $_ENV['MAILTRAP_INBOUND_THREAD_ID']; + $response = $threads->getById($threadId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + thread_id = "1700000000000124" + thread = client.inbound_api.threads.get_by_id(inbox_id, thread_id) + print(thread) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + threads = Mailtrap::InboundThreadsAPI.new(client) + + inbox_id = 42 + thread_id = '1700000000000124' + puts threads.get(inbox_id, thread_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var threadId = "1700000000000124"; + var thread = await client.Inbound().Inbox(inboxId).Thread(threadId).GetDetails(); + Console.WriteLine(thread.Messages.Count); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String threadId = "1700000000000124"; + var thread = client.inboundApi().threads().get(inboxId, threadId); + System.out.println(thread); responses: "200": description: Thread details @@ -922,6 +2288,74 @@ paths: source: | curl -X DELETE https://mailtrap.io/api/inbound/inboxes/{inbox_id}/threads/{id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const inboxId = 42; + const threadId = "1700000000000124"; + await client.inbound.threads.delete(inboxId, threadId); + - lang: php + label: PHP + source: | + threads($inboxId); + + $threadId = $_ENV['MAILTRAP_INBOUND_THREAD_ID']; + $response = $threads->delete($threadId); + echo $response->getStatusCode(); // 204 + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + inbox_id = 42 + thread_id = "1700000000000124" + client.inbound_api.threads.delete(inbox_id, thread_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + threads = Mailtrap::InboundThreadsAPI.new(client) + + inbox_id = 42 + thread_id = '1700000000000124' + threads.delete(inbox_id, thread_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var inboxId = 42; + var threadId = "1700000000000124"; + await client.Inbound().Inbox(inboxId).Thread(threadId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long inboxId = 42L; + String threadId = "1700000000000124"; + client.inboundApi().threads().delete(inboxId, threadId); responses: "204": description: Thread deleted From 6dd51db4a7e875b6d434c0537919670d1518c509 Mon Sep 17 00:00:00 2001 From: Marcin Klocek Date: Thu, 6 Aug 2026 16:38:40 +0200 Subject: [PATCH 2/6] Unify API key placeholder to YOUR_API_KEY in code samples Replace the remaining YOUR_API_TOKEN placeholders with YOUR_API_KEY across the specs so all code samples use one consistent placeholder. --- specs/account-management.openapi.yml | 32 ++++++++-------- specs/contacts.openapi.yml | 56 ++++++++++++++-------------- specs/email-campaigns.openapi.yml | 22 +++++------ specs/sandbox-sending.openapi.yml | 8 ++-- specs/sandbox.openapi.yml | 24 ++++++------ specs/templates.openapi.yml | 14 +++---- 6 files changed, 78 insertions(+), 78 deletions(-) diff --git a/specs/account-management.openapi.yml b/specs/account-management.openapi.yml index 0c8e296..d7673db 100644 --- a/specs/account-management.openapi.yml +++ b/specs/account-management.openapi.yml @@ -48,14 +48,14 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/accounts \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ - token: "YOUR_API_TOKEN" + token: "YOUR_API_KEY" }); async function listAccounts() { @@ -81,7 +81,7 @@ paths: source: | import mailtrap as mt - client = mt.MailtrapClient(token="YOUR_API_TOKEN") + client = mt.MailtrapClient(token="YOUR_API_KEY") accounts = client.general_api.accounts.get_list() @@ -123,7 +123,7 @@ paths: import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory.createMailtrapClient(config); @@ -181,7 +181,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/account_accesses \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -310,7 +310,7 @@ paths: label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/account_accesses/{account_access_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -415,7 +415,7 @@ paths: label: 'cURL' source: | curl -X PUT https://mailtrap.io/api/account_accesses/{account_access_id}/permissions/bulk \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "permissions": [ @@ -599,7 +599,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/permissions/resources \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -701,7 +701,7 @@ paths: label: cURL source: | curl -X GET https://mailtrap.io/api/api_tokens \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' responses: '200': description: List of API tokens @@ -724,7 +724,7 @@ paths: label: cURL source: | curl -X POST https://mailtrap.io/api/api_tokens \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "My API Token", @@ -763,7 +763,7 @@ paths: label: cURL source: | curl -X GET https://mailtrap.io/api/api_tokens/{id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' parameters: - $ref: '#/components/parameters/api_token_id' responses: @@ -788,7 +788,7 @@ paths: label: cURL source: | curl -X DELETE https://mailtrap.io/api/api_tokens/{id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' parameters: - $ref: '#/components/parameters/api_token_id' responses: @@ -816,7 +816,7 @@ paths: label: cURL source: | curl -X POST https://mailtrap.io/api/api_tokens/{id}/reset \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' parameters: - $ref: '#/components/parameters/api_token_id' responses: @@ -846,7 +846,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/billing/usage \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -1030,7 +1030,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/organizations/{organization_id}/sub_accounts \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' responses: '200': description: Returns the list of sub accounts belonging to the organization. @@ -1066,7 +1066,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/organizations/{organization_id}/sub_accounts \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "account": { diff --git a/specs/contacts.openapi.yml b/specs/contacts.openapi.yml index 00ece4b..cb63195 100644 --- a/specs/contacts.openapi.yml +++ b/specs/contacts.openapi.yml @@ -69,7 +69,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/contacts \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "contact": { @@ -84,7 +84,7 @@ paths: import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ - token: "YOUR_API_TOKEN" + token: "YOUR_API_KEY" }); const contact = await client.contacts.create({ @@ -126,7 +126,7 @@ paths: import mailtrap as mt client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) @@ -148,7 +148,7 @@ paths: source: | require 'mailtrap' - client = Mailtrap::Client.new(api_key: 'YOUR_API_TOKEN') + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') contacts = Mailtrap::ContactsAPI.new(account_id, client) contact = contacts.create( @@ -197,7 +197,7 @@ paths: import java.util.HashMap; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory @@ -273,14 +273,14 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/{contact_identifier} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ - token: "YOUR_API_TOKEN" + token: "YOUR_API_KEY" }); // Get by contact ID @@ -318,7 +318,7 @@ paths: import mailtrap as mt client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) @@ -337,7 +337,7 @@ paths: source: | require 'mailtrap' - client = Mailtrap::Client.new(api_key: 'YOUR_API_TOKEN') + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') contacts = Mailtrap::ContactsAPI.new(account_id, client) # Get by contact ID @@ -380,7 +380,7 @@ paths: import java.net.URLEncoder; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory @@ -426,7 +426,7 @@ paths: label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/contacts/{contact_identifier} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"contact": { "email": "new@example.com", "fields": {"first_name": "John"}}}' - lang: javascript @@ -558,7 +558,7 @@ paths: label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/contacts/{contact_identifier} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -651,7 +651,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/contacts/{contact_identifier}/events \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"name": "UserLogin", "params": {"user_id": 101, "is_active": true}}' - lang: javascript @@ -776,7 +776,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/contacts/exports \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"filters": [{"name": "list_id", "operator": "equal", "value": [1, 2]}]}' - lang: javascript @@ -895,7 +895,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/exports/{export_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -992,7 +992,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/contacts/imports \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"contacts": [{"email": "user1@example.com", "fields": {"first_name": "John"}, "list_ids_included": [1, 2]}]}' - lang: javascript @@ -1136,7 +1136,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/imports/{import_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -1243,11 +1243,11 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/lists \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' # Filter lists by name (case-insensitive prefix match) curl -X GET 'https://mailtrap.io/api/contacts/lists?search=news' \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -1339,7 +1339,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/contacts/lists \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"name": "Customers"}' - lang: javascript @@ -1440,7 +1440,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/lists/{list_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -1525,7 +1525,7 @@ paths: label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/contacts/lists/{list_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"name": "Former Customers"}' - lang: javascript @@ -1629,7 +1629,7 @@ paths: label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/contacts/lists/{list_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -1711,7 +1711,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/fields \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -1808,7 +1808,7 @@ paths: label: 'cURL' source: | curl -X POST https://mailtrap.io/api/contacts/fields \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"name": "Company", "data_type": "text", "merge_tag": "company"}' - lang: javascript @@ -1943,7 +1943,7 @@ paths: label: 'cURL' source: | curl -X GET https://mailtrap.io/api/contacts/fields/{field_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | @@ -2032,7 +2032,7 @@ paths: label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/contacts/fields/{field_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' \ + -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"name": "Updated Name", "merge_tag": "updated_name"}' - lang: javascript @@ -2158,7 +2158,7 @@ paths: label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/contacts/fields/{field_id} \ - -H 'Authorization: Bearer YOUR_API_TOKEN' + -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | diff --git a/specs/email-campaigns.openapi.yml b/specs/email-campaigns.openapi.yml index 1c17d40..54d784e 100644 --- a/specs/email-campaigns.openapi.yml +++ b/specs/email-campaigns.openapi.yml @@ -57,7 +57,7 @@ paths: label: "cURL" source: | curl -X GET "https://mailtrap.io/api/email_campaigns?per_page=50&token=1" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' post: operationId: createEmailCampaign summary: Create an email campaign @@ -93,7 +93,7 @@ paths: label: "cURL — create a draft" source: | curl -X POST "https://mailtrap.io/api/email_campaigns" \ - -H 'Api-Token: YOUR_API_TOKEN' \ + -H 'Api-Token: YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "Spring Sale", @@ -132,7 +132,7 @@ paths: label: "cURL" source: | curl -X GET "https://mailtrap.io/api/email_campaigns/4567" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' patch: operationId: updateEmailCampaign summary: Update an email campaign @@ -177,7 +177,7 @@ paths: label: "cURL — edit a draft (subject + design)" source: | curl -X PATCH "https://mailtrap.io/api/email_campaigns/4567" \ - -H 'Api-Token: YOUR_API_TOKEN' \ + -H 'Api-Token: YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "name": "Spring Sale (updated)", @@ -214,7 +214,7 @@ paths: label: "cURL" source: | curl -X DELETE "https://mailtrap.io/api/email_campaigns/4567" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' "/api/email_campaigns/{email_campaign_id}/start": post: operationId: startEmailCampaign @@ -247,7 +247,7 @@ paths: label: "cURL" source: | curl -X POST "https://mailtrap.io/api/email_campaigns/4567/start" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' "/api/email_campaigns/{email_campaign_id}/schedule": post: operationId: scheduleEmailCampaign @@ -287,7 +287,7 @@ paths: label: "cURL" source: | curl -X POST "https://mailtrap.io/api/email_campaigns/4567/schedule" \ - -H 'Api-Token: YOUR_API_TOKEN' \ + -H 'Api-Token: YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "datetime": "2026-06-01T09:00:00.000Z" }' "/api/email_campaigns/{email_campaign_id}/cancel": @@ -320,7 +320,7 @@ paths: label: "cURL" source: | curl -X POST "https://mailtrap.io/api/email_campaigns/4567/cancel" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' "/api/email_campaigns/{email_campaign_id}/terminate": post: operationId: terminateEmailCampaign @@ -351,7 +351,7 @@ paths: label: "cURL" source: | curl -X POST "https://mailtrap.io/api/email_campaigns/4567/terminate" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' "/api/email_campaigns/{email_campaign_id}/reset": post: operationId: resetEmailCampaign @@ -381,7 +381,7 @@ paths: label: "cURL" source: | curl -X POST "https://mailtrap.io/api/email_campaigns/4567/reset" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' "/api/email_campaigns/{email_campaign_id}/stats": get: operationId: getEmailCampaignStats @@ -419,7 +419,7 @@ paths: label: "cURL" source: | curl -X GET "https://mailtrap.io/api/email_campaigns/4567/stats?start_date=2026-05-01&end_date=2026-05-31" \ - -H 'Api-Token: YOUR_API_TOKEN' + -H 'Api-Token: YOUR_API_KEY' components: securitySchemes: HeaderAuth: diff --git a/specs/sandbox-sending.openapi.yml b/specs/sandbox-sending.openapi.yml index 378fa3b..c6bc9b5 100644 --- a/specs/sandbox-sending.openapi.yml +++ b/specs/sandbox-sending.openapi.yml @@ -51,7 +51,7 @@ paths: import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ - token: "YOUR_API_TOKEN", + token: "YOUR_API_KEY", testInboxId: TEST_INBOX_ID, sandbox: true }); @@ -100,7 +100,7 @@ paths: inbox_id = 123456 client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", sandbox=True, inbox_id=inbox_id ) @@ -119,7 +119,7 @@ paths: source: | require 'mailtrap' - client = Mailtrap::Client.new(api_key: 'YOUR_API_TOKEN', sandbox: true, inbox_id: TEST_INBOX_ID) + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY', sandbox: true, inbox_id: TEST_INBOX_ID) mail = Mailtrap::Mail.new( from: { email: 'test@example.com', name: 'Test Sender' }, @@ -170,7 +170,7 @@ paths: import java.util.List; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .inboxId(TEST_INBOX_ID) .build(); diff --git a/specs/sandbox.openapi.yml b/specs/sandbox.openapi.yml index 3073ab0..5342ad6 100644 --- a/specs/sandbox.openapi.yml +++ b/specs/sandbox.openapi.yml @@ -241,7 +241,7 @@ paths: import mailtrap as mt client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) @@ -255,7 +255,7 @@ paths: source: | require 'mailtrap' - client = Mailtrap::Client.new(api_key: 'YOUR_API_TOKEN') + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client @@ -289,7 +289,7 @@ paths: import io.mailtrap.model.request.projects.ProjectRequest; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory @@ -328,7 +328,7 @@ paths: import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ - token: "YOUR_API_TOKEN", + token: "YOUR_API_KEY", accountId: ACCOUNT_ID }); @@ -359,7 +359,7 @@ paths: import mailtrap as mt client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) @@ -372,7 +372,7 @@ paths: source: | require 'mailtrap' - client = Mailtrap::Client.new(api_key: 'YOUR_API_TOKEN') + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client @@ -407,7 +407,7 @@ paths: import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory @@ -871,7 +871,7 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const TOKEN = "YOUR_API_TOKEN"; + const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ @@ -914,7 +914,7 @@ paths: import mailtrap as mt client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) project_id = 12345 @@ -961,7 +961,7 @@ paths: import io.mailtrap.model.request.inbox.CreateInboxRequest; var config = new MailtrapConfig.Builder() - .token("YOUR_API_TOKEN") + .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory @@ -2630,7 +2630,7 @@ paths: import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ - token: "YOUR_API_TOKEN", + token: "YOUR_API_KEY", accountId: ACCOUNT_ID }); @@ -2665,7 +2665,7 @@ paths: import mailtrap as mt client = mt.MailtrapClient( - token="YOUR_API_TOKEN", + token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) diff --git a/specs/templates.openapi.yml b/specs/templates.openapi.yml index 078a7da..49becbf 100644 --- a/specs/templates.openapi.yml +++ b/specs/templates.openapi.yml @@ -146,7 +146,7 @@ paths: label: Node.js source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_TOKEN" }); + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); async function createTemplate() { const template = await client.templates.create({ @@ -189,7 +189,7 @@ paths: label: Python source: | import mailtrap as mt - client = mt.MailtrapClient(token="YOUR_API_TOKEN", account_id="YOUR_ACCOUNT_ID") + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") template = client.email_templates_api.templates.create( mt.CreateEmailTemplateParams( name="Welcome Email", @@ -203,7 +203,7 @@ paths: label: Ruby source: | require 'mailtrap' - client = Mailtrap::Client.new(api_key: 'YOUR_API_TOKEN') + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') templates = Mailtrap::EmailTemplatesAPI.new(YOUR_ACCOUNT_ID, client) template = templates.create( name: 'Welcome Email', @@ -237,7 +237,7 @@ paths: import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; - var config = new MailtrapConfig.Builder().token("YOUR_API_TOKEN").build(); + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); var request = new CreateEmailTemplateRequest( @@ -314,7 +314,7 @@ paths: source: | import mailtrap as mt - client = mt.MailtrapClient(token="YOUR_API_TOKEN", account_id="YOUR_ACCOUNT_ID") + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") template_id = 12345 template = client.email_templates_api.templates.get_by_id(template_id) @@ -411,7 +411,7 @@ paths: email_template_id = "YOUR_TEMPLATE_ID" - client = mt.MailtrapClient(token="YOUR_API_TOKEN", account_id="YOUR_ACCOUNT_ID") + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") template = client.email_templates_api.templates.update( template_id=email_template_id, template_params=mt.UpdateEmailTemplateParams( @@ -502,7 +502,7 @@ paths: email_template_id = "YOUR_TEMPLATE_ID" - client = mt.MailtrapClient(token="YOUR_API_TOKEN", account_id="YOUR_ACCOUNT_ID") + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") deleted_template = client.email_templates_api.templates.delete( template_id=email_template_id ) From 769133055fc05bce4eb61684332dc0f7b889de23 Mon Sep 17 00:00:00 2001 From: Marcin Klocek Date: Thu, 6 Aug 2026 17:05:23 +0200 Subject: [PATCH 3/6] Add SDK code samples to account-management endpoints Document API tokens (list/create/get/delete/reset) and sub-accounts (list/create) with Node.js, PHP, Python, Ruby, .NET, and Java examples, and add the missing Ruby example to the permissions operations. API-token samples use the account-scoped SDK methods the clients currently ship. --- specs/account-management.openapi.yml | 576 +++++++++++++++++++++++++++ 1 file changed, 576 insertions(+) diff --git a/specs/account-management.openapi.yml b/specs/account-management.openapi.yml index d7673db..baff229 100644 --- a/specs/account-management.openapi.yml +++ b/specs/account-management.openapi.yml @@ -486,6 +486,23 @@ paths: ) ] ) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + permissions = Mailtrap::PermissionsAPI.new(account_id, client) + + account_access_id = 5142 + permissions.bulk_update( + account_access_id, + [ + { resource_id: '3281', resource_type: 'account', access_level: 'viewer' }, + { resource_id: '3809', resource_type: 'sandbox', _destroy: true } + ] + ) - lang: csharp label: C# source: | @@ -635,6 +652,16 @@ paths: client = mt.MailtrapClient(token="YOUR_API_KEY") resources = client.general_api.permissions.get_resources(account_id) print(resources) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + permissions = Mailtrap::PermissionsAPI.new(account_id, client) + + puts permissions.resources - lang: csharp label: C# source: | @@ -702,6 +729,73 @@ paths: source: | curl -X GET https://mailtrap.io/api/api_tokens \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const tokens = await client.general(accountId).apiTokens.getList(); + console.log(tokens); + - lang: php + label: PHP + source: | + apiTokens($accountId); + + $response = $apiTokens->getApiTokens(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + tokens = client.general_api.api_tokens.get_list(account_id) + print(tokens) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + api_tokens = Mailtrap::ApiTokensAPI.new(account_id, client) + + puts api_tokens.list + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var tokens = await client.Account(accountId).ApiTokens().GetAll(); + Console.WriteLine(tokens.Count); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var tokens = client.generalApi().apiTokens().getAllApiTokens(accountId); + System.out.println(tokens); responses: '200': description: List of API tokens @@ -732,6 +826,120 @@ paths: {"resource_type": "account", "resource_id": 3229, "access_level": 100} ] }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + // The full token value is returned only once — store it securely. + const token = await client.general(accountId).apiTokens.create({ + name: "My API Token", + resources: [ + { resource_type: "account", resource_id: accountId, access_level: 100 }, + ], + }); + console.log(token); + - lang: php + label: PHP + source: | + apiTokens($accountId); + + $permissions = new Permissions( + new CreateOrUpdatePermission($accountId, PermissionInterface::TYPE_ACCOUNT, 100) + ); + + $response = $apiTokens->createApiToken('My API Token', $permissions); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + # The full token value is returned only once — store it securely. + token = client.general_api.api_tokens.create( + account_id=account_id, + token_params=mt.CreateApiTokenParams( + name="My API Token", + resources=[ + mt.ApiTokenResource( + resource_type="account", resource_id=account_id, access_level=100 + ) + ], + ), + ) + print(token) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + api_tokens = Mailtrap::ApiTokensAPI.new(account_id, client) + + # The full token value is returned only once — store it securely. + token = api_tokens.create( + name: 'My API Token', + resources: [ + { resource_type: 'account', resource_id: account_id, access_level: 100 } + ] + ) + puts token + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.ApiTokens.Requests; + using Mailtrap.Core.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var request = new CreateApiTokenRequest { Name = "My API Token" }; + request.Resources.Add(new ApiTokenAccessRequest(ResourceType.Account, accountId, AccessLevel.Admin)); + + // The full token value is returned only once — store it securely. + var token = await client.Account(accountId).ApiTokens().Create(request); + Console.WriteLine(token.Token); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.AccessLevel; + import io.mailtrap.model.ResourceType; + import io.mailtrap.model.request.apitokens.ApiTokenResource; + import io.mailtrap.model.request.apitokens.CreateApiTokenRequest; + import java.util.List; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var request = new CreateApiTokenRequest( + "My API Token", + List.of(new ApiTokenResource(ResourceType.ACCOUNT, accountId, AccessLevel.ADMIN))); + + // The full token value is returned only once — store it securely. + var token = client.generalApi().apiTokens().createApiToken(accountId, request); + System.out.println(token); requestBody: required: true content: @@ -764,6 +972,79 @@ paths: source: | curl -X GET https://mailtrap.io/api/api_tokens/{id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const apiTokenId = 123; + const token = await client.general(accountId).apiTokens.get(apiTokenId); + console.log(token); + - lang: php + label: PHP + source: | + apiTokens($accountId); + + $apiTokenId = $_ENV['MAILTRAP_API_TOKEN_ID']; + $response = $apiTokens->getApiToken($apiTokenId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + api_token_id = 123 + token = client.general_api.api_tokens.get_by_id(account_id, api_token_id) + print(token) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + api_token_id = 123 + api_tokens = Mailtrap::ApiTokensAPI.new(account_id, client) + + puts api_tokens.get(api_token_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var apiTokenId = 123; + var token = await client.Account(accountId).ApiToken(apiTokenId).GetDetails(); + Console.WriteLine(token.Name); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long apiTokenId = 123L; + var token = client.generalApi().apiTokens().getApiToken(accountId, apiTokenId); + System.out.println(token); parameters: - $ref: '#/components/parameters/api_token_id' responses: @@ -789,6 +1070,74 @@ paths: source: | curl -X DELETE https://mailtrap.io/api/api_tokens/{id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const apiTokenId = 123; + await client.general(accountId).apiTokens.delete(apiTokenId); + - lang: php + label: PHP + source: | + apiTokens($accountId); + + $apiTokenId = $_ENV['MAILTRAP_API_TOKEN_ID']; + $response = $apiTokens->deleteApiToken($apiTokenId); + echo $response->getStatusCode(); // 204 + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + api_token_id = 123 + client.general_api.api_tokens.delete(account_id, api_token_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + api_token_id = 123 + api_tokens = Mailtrap::ApiTokensAPI.new(account_id, client) + + api_tokens.delete(api_token_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var apiTokenId = 123; + await client.Account(accountId).ApiToken(apiTokenId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long apiTokenId = 123L; + client.generalApi().apiTokens().deleteApiToken(accountId, apiTokenId); parameters: - $ref: '#/components/parameters/api_token_id' responses: @@ -817,6 +1166,84 @@ paths: source: | curl -X POST https://mailtrap.io/api/api_tokens/{id}/reset \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const apiTokenId = 123; + // The new token value is returned only once — store it securely. + const token = await client.general(accountId).apiTokens.reset(apiTokenId); + console.log(token); + - lang: php + label: PHP + source: | + apiTokens($accountId); + + $apiTokenId = $_ENV['MAILTRAP_API_TOKEN_ID']; + $response = $apiTokens->resetApiToken($apiTokenId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + api_token_id = 123 + # The new token value is returned only once — store it securely. + token = client.general_api.api_tokens.reset(account_id, api_token_id) + print(token) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + api_token_id = 123 + api_tokens = Mailtrap::ApiTokensAPI.new(account_id, client) + + # The new token value is returned only once — store it securely. + puts api_tokens.reset(api_token_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var apiTokenId = 123; + // The new token value is returned only once — store it securely. + var token = await client.Account(accountId).ApiToken(apiTokenId).Reset(); + Console.WriteLine(token.Token); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long apiTokenId = 123L; + // The new token value is returned only once — store it securely. + var token = client.generalApi().apiTokens().resetApiToken(accountId, apiTokenId); + System.out.println(token); parameters: - $ref: '#/components/parameters/api_token_id' responses: @@ -1031,6 +1458,74 @@ paths: source: | curl -X GET https://mailtrap.io/api/organizations/{organization_id}/sub_accounts \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const organizationId = 2000002; + const subAccounts = await client.organizations(organizationId).subAccounts.getList(); + console.log(subAccounts); + - lang: php + label: PHP + source: | + organization($organizationId)->subAccounts(); + + $response = $subAccounts->getSubAccounts(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + organization_id = 2000002 + client = mt.MailtrapClient(token="YOUR_API_KEY", organization_id=organization_id) + + sub_accounts = client.organizations_api.sub_accounts.get_list() + print(sub_accounts) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + organization_id = 2000002 + sub_accounts = Mailtrap::SubAccountsAPI.new(organization_id, client) + + puts sub_accounts.list + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + // Sub-accounts live under /organizations/{id}, so use the organization client. + var client = mailtrapFactory.CreateOrganizationClient(); + + var organizationId = 2000002; + var subAccounts = await client.Organization(organizationId).SubAccounts().GetAll(); + Console.WriteLine(subAccounts.Count); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long organizationId = 2000002L; + var subAccounts = client.organizationsApi().subAccounts().getSubAccounts(organizationId); + System.out.println(subAccounts); responses: '200': description: Returns the list of sub accounts belonging to the organization. @@ -1073,6 +1568,87 @@ paths: "name": "New Team Account" } }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const organizationId = 2000002; + const subAccount = await client.organizations(organizationId).subAccounts + .create({ name: "New Team Account" }); + console.log(subAccount); + - lang: php + label: PHP + source: | + organization($organizationId)->subAccounts(); + + $response = $subAccounts->createSubAccount('New Team Account'); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + organization_id = 2000002 + client = mt.MailtrapClient(token="YOUR_API_KEY", organization_id=organization_id) + + sub_account = client.organizations_api.sub_accounts.create( + mt.CreateSubAccountParams(name="New Team Account") + ) + print(sub_account) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + organization_id = 2000002 + sub_accounts = Mailtrap::SubAccountsAPI.new(organization_id, client) + + sub_account = sub_accounts.create(name: 'New Team Account') + puts sub_account + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Organizations.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + // Sub-accounts live under /organizations/{id}, so use the organization client. + var client = mailtrapFactory.CreateOrganizationClient(); + + var organizationId = 2000002; + var request = new CreateSubAccountRequest + { + Account = new SubAccountAttributes { Name = "New Team Account" }, + }; + var subAccount = await client.Organization(organizationId).SubAccounts().Create(request); + Console.WriteLine(subAccount.Id); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.subaccounts.CreateSubAccountRequest; + import io.mailtrap.model.request.subaccounts.SubAccountInput; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long organizationId = 2000002L; + var request = new CreateSubAccountRequest(new SubAccountInput("New Team Account")); + var subAccount = client.organizationsApi().subAccounts() + .createSubAccount(organizationId, request); + System.out.println(subAccount); requestBody: required: true content: From 177100cb95fd888ded3c940a7dc25d1f832ef22d Mon Sep 17 00:00:00 2001 From: Marcin Klocek Date: Thu, 6 Aug 2026 17:11:21 +0200 Subject: [PATCH 4/6] Add missing-language SDK samples to contacts, sandbox, and templates Add the Ruby example to the contact event/export operations and the two sandbox email-address operations, and add .NET and Java examples to the email-template get/update/delete operations, filling the per-language gaps where the SDK implements the endpoint. --- specs/contacts.openapi.yml | 42 ++++++++++++++++++ specs/sandbox.openapi.yml | 22 ++++++++++ specs/templates.openapi.yml | 86 +++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) diff --git a/specs/contacts.openapi.yml b/specs/contacts.openapi.yml index cb63195..20e8d8a 100644 --- a/specs/contacts.openapi.yml +++ b/specs/contacts.openapi.yml @@ -701,6 +701,21 @@ paths: ) ) print(event) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + contact_events = Mailtrap::ContactEventsAPI.new(account_id, client) + + event = contact_events.create( + 'contact_id', + name: 'UserLogin', + params: { user_id: 101, is_active: true } + ) + puts event - lang: csharp label: C# source: | @@ -820,6 +835,21 @@ paths: ] ) print(f"Export started: {export_job.id}") + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + contact_exports = Mailtrap::ContactExportsAPI.new(account_id, client) + + export_job = contact_exports.create( + filters: [ + { name: 'list_id', operator: 'equal', value: [1, 2] } + ] + ) + puts export_job - lang: csharp label: C# source: | @@ -929,6 +959,18 @@ paths: export_status = client.contacts_api.contact_exports.get_by_id(export_id) print(f"Status: {export_status.status}, URL: {export_status.url}") + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + contact_exports = Mailtrap::ContactExportsAPI.new(account_id, client) + + export_id = 12345 + export_status = contact_exports.get(export_id) + puts export_status - lang: csharp label: C# source: | diff --git a/specs/sandbox.openapi.yml b/specs/sandbox.openapi.yml index 5342ad6..dfe05bd 100644 --- a/specs/sandbox.openapi.yml +++ b/specs/sandbox.openapi.yml @@ -1784,6 +1784,17 @@ paths: result = inboxes_api.enable_email_address(inbox_id) print(result) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + inboxes = Mailtrap::InboxesAPI.new(account_id, client) + + inbox_id = 12345 + puts inboxes.toggle_email_username(inbox_id) - lang: csharp label: .NET source: | @@ -1891,6 +1902,17 @@ paths: result = inboxes_api.reset_email_username(inbox_id) print(result) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + inboxes = Mailtrap::InboxesAPI.new(account_id, client) + + inbox_id = 12345 + puts inboxes.reset_email_username(inbox_id) - lang: csharp label: .NET source: | diff --git a/specs/templates.openapi.yml b/specs/templates.openapi.yml index 49becbf..859cd2c 100644 --- a/specs/templates.openapi.yml +++ b/specs/templates.openapi.yml @@ -331,6 +331,32 @@ paths: ) template = templates.get(template_id) puts "Template: #{template}" + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var templateId = 12345; + var template = await client.Account(accountId).EmailTemplate(templateId).GetDetails(); + Console.WriteLine(template.Name); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long templateId = 12345L; + var template = client.emailTemplatesApi().emailTemplates() + .getEmailTemplate(accountId, templateId); + System.out.println(template); responses: '200': description: Returns attributes of the email template. @@ -433,6 +459,43 @@ paths: client ) templates.update(EMAIL_TEMPLATE_ID, name: 'Welcome Updated') + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.EmailTemplates.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var templateId = 12345; + var request = new UpdateEmailTemplateRequest("Updated Welcome Email", "Transactional", "Updated Subject") + { + BodyHtml = "
Updated HTML Body
", + BodyText = "Updated Text Body", + }; + var template = await client.Account(accountId).EmailTemplate(templateId).Update(request); + Console.WriteLine(template.Name); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.emailtemplates.EmailTemplate; + import io.mailtrap.model.request.emailtemplates.UpdateEmailTemplateRequest; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long templateId = 12345L; + var request = new UpdateEmailTemplateRequest( + new EmailTemplate("Updated Welcome Email", "Transactional", "Updated Subject", + "Updated Text Body", "
Updated HTML Body
")); + var template = client.emailTemplatesApi().emailTemplates() + .updateEmailTemplate(accountId, templateId, request); + System.out.println(template); requestBody: content: application/json: @@ -517,6 +580,29 @@ paths: client ) templates.delete(EMAIL_TEMPLATE_ID) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var templateId = 12345; + await client.Account(accountId).EmailTemplate(templateId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long templateId = 12345L; + client.emailTemplatesApi().emailTemplates().deleteEmailTemplate(accountId, templateId); responses: '204': description: No Content From e788c9fe27a900ead4393a45327169b20836d273 Mon Sep 17 00:00:00 2001 From: Marcin Klocek Date: Thu, 6 Aug 2026 17:20:36 +0200 Subject: [PATCH 5/6] Add SDK code samples to email-sending endpoints Document email logs (list/get) and webhooks (create/list/get/update/delete) with Node.js, PHP, Python, Ruby, .NET, and Java examples, add the remaining five SDK examples to the account sending-stats operations, and add the Ruby example to the sending-domain update and company-info operations. Suppression create and tracking opt-outs have no SDK coverage and remain cURL-only. --- specs/email-sending.openapi.yml | 987 ++++++++++++++++++++++++++++++-- 1 file changed, 955 insertions(+), 32 deletions(-) diff --git a/specs/email-sending.openapi.yml b/specs/email-sending.openapi.yml index 39a2ab4..ae25980 100644 --- a/specs/email-sending.openapi.yml +++ b/specs/email-sending.openapi.yml @@ -583,6 +583,22 @@ paths: "inbound_enabled": true } }' + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + sending_domains = Mailtrap::SendingDomainsAPI.new(account_id, client) + + domain_id = 12345 + puts sending_domains.update( + domain_id, + open_tracking_enabled: true, + click_tracking_enabled: true, + auto_unsubscribe_link_enabled: false + ) parameters: - $ref: '#/components/parameters/domain_id' requestBody: @@ -786,6 +802,17 @@ paths: source: | curl -X GET https://mailtrap.io/api/domains/{domain_id}/company_info \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + company_info = Mailtrap::CompanyInfoAPI.new(account_id, client) + + domain_id = 12345 + puts company_info.get(domain_id) parameters: - $ref: '#/components/parameters/domain_id' responses: @@ -827,6 +854,26 @@ paths: "info_level": "business" } }' + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + company_info = Mailtrap::CompanyInfoAPI.new(account_id, client) + + domain_id = 12345 + puts company_info.create( + domain_id, + name: 'Mailtrap', + address: '123 Main St', + city: 'San Francisco', + country: 'US', + zip_code: '94105', + website_url: 'https://mailtrap.io', + info_level: 'business' + ) parameters: - $ref: '#/components/parameters/domain_id' requestBody: @@ -885,6 +932,17 @@ paths: "zip_code": "10001" } }' + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + company_info = Mailtrap::CompanyInfoAPI.new(account_id, client) + + domain_id = 12345 + puts company_info.update(domain_id, city: 'New York', zip_code: '10001') parameters: - $ref: '#/components/parameters/domain_id' requestBody: @@ -1463,6 +1521,41 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/stats?start_date=2025-01-01&end_date=2025-12-31' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const stats = await client.stats(accountId).get({ start_date: "2026-01-01", end_date: "2026-01-31" }); + console.log(stats); + - lang: php + label: PHP + source: | + stats($accountId); + + $response = $stats->get('2026-01-01', '2026-01-31'); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + params = mt.StatsFilterParams(start_date="2026-01-01", end_date="2026-01-31") + stats = client.stats_api.get(account_id=account_id, params=params) + print(stats) - lang: ruby label: Ruby source: | @@ -1472,6 +1565,33 @@ paths: stats = Mailtrap::StatsAPI.new(YOUR_ACCOUNT_ID, client) puts "Stats: #{stats.get(start_date: '2026-01-01', end_date: '2026-01-31')}" + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Stats.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var filter = new StatsFilter { StartDate = "2026-01-01", EndDate = "2026-01-31" }; + var stats = await client.Account(accountId).Stats().GetStats(filter); + Console.WriteLine(stats); + - lang: java + label: Java + source: | + import io.mailtrap.api.stats.StatsFilter; + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var filter = StatsFilter.builder().startDate("2026-01-01").endDate("2026-01-31").build(); + var stats = client.sendingApi().stats().getStats(accountId, filter); + System.out.println(stats); parameters: - $ref: '#/components/parameters/StartDateQueryFilter' - $ref: '#/components/parameters/EndDateQueryFilter' @@ -1507,6 +1627,41 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/stats/domains?start_date=2025-01-01&end_date=2025-12-31' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const stats = await client.stats(accountId).byDomain({ start_date: "2026-01-01", end_date: "2026-01-31" }); + console.log(stats); + - lang: php + label: PHP + source: | + stats($accountId); + + $response = $stats->byDomain('2026-01-01', '2026-01-31'); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + params = mt.StatsFilterParams(start_date="2026-01-01", end_date="2026-01-31") + stats = client.stats_api.by_domain(account_id=account_id, params=params) + print(stats) - lang: ruby label: Ruby source: | @@ -1516,6 +1671,33 @@ paths: stats = Mailtrap::StatsAPI.new(YOUR_ACCOUNT_ID, client) puts "Stats: #{stats.by_domain(start_date: '2026-01-01', end_date: '2026-01-31')}" + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Stats.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var filter = new StatsFilter { StartDate = "2026-01-01", EndDate = "2026-01-31" }; + var stats = await client.Account(accountId).Stats().ByDomain(filter); + Console.WriteLine(stats.Count); + - lang: java + label: Java + source: | + import io.mailtrap.api.stats.StatsFilter; + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var filter = StatsFilter.builder().startDate("2026-01-01").endDate("2026-01-31").build(); + var stats = client.sendingApi().stats().byDomain(accountId, filter); + System.out.println(stats); parameters: - $ref: '#/components/parameters/StartDateQueryFilter' - $ref: '#/components/parameters/EndDateQueryFilter' @@ -1566,6 +1748,41 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/stats/categories?start_date=2025-01-01&end_date=2025-12-31' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const stats = await client.stats(accountId).byCategory({ start_date: "2026-01-01", end_date: "2026-01-31" }); + console.log(stats); + - lang: php + label: PHP + source: | + stats($accountId); + + $response = $stats->byCategory('2026-01-01', '2026-01-31'); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + params = mt.StatsFilterParams(start_date="2026-01-01", end_date="2026-01-31") + stats = client.stats_api.by_category(account_id=account_id, params=params) + print(stats) - lang: ruby label: Ruby source: | @@ -1575,6 +1792,33 @@ paths: stats = Mailtrap::StatsAPI.new(YOUR_ACCOUNT_ID, client) puts "Stats: #{stats.by_category(start_date: '2026-01-01', end_date: '2026-01-31')}" + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Stats.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var filter = new StatsFilter { StartDate = "2026-01-01", EndDate = "2026-01-31" }; + var stats = await client.Account(accountId).Stats().ByCategory(filter); + Console.WriteLine(stats.Count); + - lang: java + label: Java + source: | + import io.mailtrap.api.stats.StatsFilter; + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var filter = StatsFilter.builder().startDate("2026-01-01").endDate("2026-01-31").build(); + var stats = client.sendingApi().stats().byCategory(accountId, filter); + System.out.println(stats); parameters: - $ref: '#/components/parameters/StartDateQueryFilter' - $ref: '#/components/parameters/EndDateQueryFilter' @@ -1618,6 +1862,41 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/stats/email_service_providers?start_date=2025-01-01&end_date=2025-12-31' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const stats = await client.stats(accountId).byEmailServiceProvider({ start_date: "2026-01-01", end_date: "2026-01-31" }); + console.log(stats); + - lang: php + label: PHP + source: | + stats($accountId); + + $response = $stats->byEmailServiceProvider('2026-01-01', '2026-01-31'); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + params = mt.StatsFilterParams(start_date="2026-01-01", end_date="2026-01-31") + stats = client.stats_api.by_email_service_provider(account_id=account_id, params=params) + print(stats) - lang: ruby label: Ruby source: | @@ -1627,6 +1906,33 @@ paths: stats = Mailtrap::StatsAPI.new(YOUR_ACCOUNT_ID, client) puts "Stats: #{stats.by_email_service_provider(start_date: '2026-01-01', end_date: '2026-01-31')}" + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Stats.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var filter = new StatsFilter { StartDate = "2026-01-01", EndDate = "2026-01-31" }; + var stats = await client.Account(accountId).Stats().ByEmailServiceProvider(filter); + Console.WriteLine(stats.Count); + - lang: java + label: Java + source: | + import io.mailtrap.api.stats.StatsFilter; + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var filter = StatsFilter.builder().startDate("2026-01-01").endDate("2026-01-31").build(); + var stats = client.sendingApi().stats().byEmailServiceProvider(accountId, filter); + System.out.println(stats); parameters: - $ref: '#/components/parameters/StartDateQueryFilter' - $ref: '#/components/parameters/EndDateQueryFilter' @@ -1670,6 +1976,41 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/stats/date?start_date=2025-01-01&end_date=2025-12-31' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const stats = await client.stats(accountId).byDate({ start_date: "2026-01-01", end_date: "2026-01-31" }); + console.log(stats); + - lang: php + label: PHP + source: | + stats($accountId); + + $response = $stats->byDate('2026-01-01', '2026-01-31'); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY") + + account_id = 1000001 + params = mt.StatsFilterParams(start_date="2026-01-01", end_date="2026-01-31") + stats = client.stats_api.by_date(account_id=account_id, params=params) + print(stats) - lang: ruby label: Ruby source: | @@ -1679,6 +2020,33 @@ paths: stats = Mailtrap::StatsAPI.new(YOUR_ACCOUNT_ID, client) puts "Stats: #{stats.by_date(start_date: '2026-01-01', end_date: '2026-01-31')}" + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Stats.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var filter = new StatsFilter { StartDate = "2026-01-01", EndDate = "2026-01-31" }; + var stats = await client.Account(accountId).Stats().ByDate(filter); + Console.WriteLine(stats.Count); + - lang: java + label: Java + source: | + import io.mailtrap.api.stats.StatsFilter; + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var filter = StatsFilter.builder().startDate("2026-01-01").endDate("2026-01-31").build(); + var stats = client.sendingApi().stats().byDate(accountId, filter); + System.out.println(stats); parameters: - $ref: '#/components/parameters/StartDateQueryFilter' - $ref: '#/components/parameters/EndDateQueryFilter' @@ -1727,38 +2095,106 @@ paths: source: | curl -X GET -g 'https://mailtrap.io/api/email_logs?filters[sent_after]=2025-01-01T00:00:00Z&filters[sent_before]=2025-01-31T23:59:59Z&filters[to][operator]=ci_equal&filters[to][value]=recipient@example.com&filters[domain_id][operator]=equal&filters[domain_id][value][]=3938&filters[domain_id][value][]=3939' \ -H 'Authorization: Bearer YOUR_API_KEY' - parameters: - - name: search_after - in: query - description: Cursor for the next page (message_id UUID from previous response next_page_cursor). - schema: - type: string - format: uuid - - name: filters - in: query - description: | - Filter criteria (deep object). Pass as `filters[field][operator]` and `filters[field][value]`. - When a filter accepts an array value, use bracket notation: `filters[field][value][]=item1&filters[field][value][]=item2`. - Date range: use `filters[sent_after]` and `filters[sent_before]` (ISO 8601 strings). - Unknown filters are ignored. - style: deepObject - explode: true - schema: - $ref: '#/components/schemas/EmailLogsListFilters' - responses: - '200': - description: Success - content: - application/json: - schema: - $ref: '#/components/schemas/EmailLogsListResponse' - '400': - $ref: '#/components/responses/BAD_REQUEST' - '401': - $ref: '#/components/responses/Unauthorized' - '404': - $ref: '#/components/responses/NotFound' - '429': + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const page = await client.emailLogs(accountId).getList(); + console.log(page); + - lang: php + label: PHP + source: | + emailLogs($accountId); + + $response = $emailLogs->getList(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + response = client.email_logs_api.email_logs.get_list() + print(response.total_count) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + email_logs = Mailtrap::EmailLogsAPI.new(account_id, client) + + response = email_logs.list + puts response.total_count + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.EmailLogs.Models; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var response = await client.Account(accountId).EmailLogs().List(new EmailLogsListFilter()); + Console.WriteLine(response.TotalCount); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var response = client.sendingApi().emailLogs().list(accountId, null, null); + System.out.println(response.getTotalCount()); + parameters: + - name: search_after + in: query + description: Cursor for the next page (message_id UUID from previous response next_page_cursor). + schema: + type: string + format: uuid + - name: filters + in: query + description: | + Filter criteria (deep object). Pass as `filters[field][operator]` and `filters[field][value]`. + When a filter accepts an array value, use bracket notation: `filters[field][value][]=item1&filters[field][value][]=item2`. + Date range: use `filters[sent_after]` and `filters[sent_before]` (ISO 8601 strings). + Unknown filters are ignored. + style: deepObject + explode: true + schema: + $ref: '#/components/schemas/EmailLogsListFilters' + responses: + '200': + description: Success + content: + application/json: + schema: + $ref: '#/components/schemas/EmailLogsListResponse' + '400': + $ref: '#/components/responses/BAD_REQUEST' + '401': + $ref: '#/components/responses/Unauthorized' + '404': + $ref: '#/components/responses/NotFound' + '429': $ref: '#/components/responses/LIMIT_EXCEEDED' /api/email_logs/{sending_message_id}: get: @@ -1773,6 +2209,78 @@ paths: source: | curl -X GET 'https://mailtrap.io/api/email_logs/{sending_message_id}' \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const messageId = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d"; + const message = await client.emailLogs(accountId).get(messageId); + console.log(message.subject); + - lang: php + label: PHP + source: | + emailLogs($accountId); + + $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; + $response = $emailLogs->getMessage($messageId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + message_id = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d" + message = client.email_logs_api.email_logs.get_by_id(message_id) + print(message.subject) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + email_logs = Mailtrap::EmailLogsAPI.new(account_id, client) + + message_id = 'a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d' + puts email_logs.get(message_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var messageId = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d"; + var message = await client.Account(accountId).EmailLog(messageId).GetDetails(); + Console.WriteLine(message.Subject); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + String messageId = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d"; + var message = client.sendingApi().emailLogs().get(accountId, messageId); + System.out.println(message.getSubject()); parameters: - $ref: '#/components/parameters/sending_message_id' responses: @@ -1815,6 +2323,135 @@ paths: "domain_id": 435 } }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + // The signing secret is returned only on creation — store it securely. + const webhook = await client.webhooks(accountId).create({ + url: "https://example.com/mailtrap/webhooks", + webhook_type: "email_sending", + payload_format: "json", + sending_stream: "transactional", + event_types: ["delivery", "bounce"], + }); + console.log(webhook); + - lang: php + label: PHP + source: | + webhooks($accountId); + + $response = $webhooks->createWebhook(new CreateWebhook( + url: 'https://example.com/mailtrap/webhooks', + webhookType: Webhook::TYPE_EMAIL_SENDING, + eventTypes: [Webhook::EVENT_DELIVERY, Webhook::EVENT_BOUNCE], + payloadFormat: Webhook::PAYLOAD_FORMAT_JSON, + sendingStream: Webhook::SENDING_STREAM_TRANSACTIONAL, + )); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + # The signing_secret is returned only on creation — store it securely. + webhook = client.webhooks_api.webhooks.create( + mt.CreateWebhookParams( + url="https://example.com/mailtrap/webhooks", + webhook_type="email_sending", + sending_stream="transactional", + event_types=["delivery", "bounce"], + ) + ) + print(webhook) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + webhooks = Mailtrap::WebhooksAPI.new(account_id, client) + + # The signing_secret is returned only on creation — store it securely. + webhook = webhooks.create( + url: 'https://example.com/mailtrap/webhooks', + webhook_type: 'email_sending', + payload_format: 'json', + sending_stream: 'transactional', + event_types: %w[delivery bounce] + ) + puts webhook + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Core.Models; + using Mailtrap.Webhooks.Models; + using Mailtrap.Webhooks.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var request = new CreateWebhookRequest + { + Url = new Uri("https://example.com/mailtrap/webhooks"), + WebhookType = WebhookType.EmailSending, + Active = true, + PayloadFormat = WebhookPayloadFormat.Json, + SendingStream = SendingStream.Transactional, + }; + request.EventTypes.Add(WebhookEventType.Delivery); + request.EventTypes.Add(WebhookEventType.Bounce); + + // The signing secret is returned only on creation — store it securely. + var webhook = await client.Account(accountId).Webhooks().Create(request); + Console.WriteLine(webhook.SigningSecret); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.SendingStream; + import io.mailtrap.model.WebhookEventType; + import io.mailtrap.model.WebhookPayloadFormat; + import io.mailtrap.model.WebhookType; + import io.mailtrap.model.request.webhooks.CreateWebhookRequest; + import io.mailtrap.model.request.webhooks.WebhookInput; + import java.util.List; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var request = new CreateWebhookRequest( + WebhookInput.builder() + .url("https://example.com/mailtrap/webhooks") + .webhookType(WebhookType.EMAIL_SENDING) + .payloadFormat(WebhookPayloadFormat.JSON) + .sendingStream(SendingStream.TRANSACTIONAL) + .eventTypes(List.of(WebhookEventType.DELIVERY, WebhookEventType.BOUNCE)) + .build()); + + // signing_secret is returned only on creation — store it securely. + var webhook = client.generalApi().webhooks().createWebhook(accountId, request); + System.out.println(webhook); requestBody: required: true content: @@ -1939,6 +2576,72 @@ paths: source: | curl -X GET https://mailtrap.io/api/webhooks \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const webhooks = await client.webhooks(accountId).getList(); + console.log(webhooks); + - lang: php + label: PHP + source: | + webhooks($accountId); + + $response = $webhooks->getWebhooks(); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + webhooks = client.webhooks_api.webhooks.get_list() + print(webhooks) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + webhooks = Mailtrap::WebhooksAPI.new(account_id, client) + + puts webhooks.list + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var webhooks = await client.Account(accountId).Webhooks().GetAll(); + Console.WriteLine(webhooks.Count); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + var webhooks = client.generalApi().webhooks().getAllWebhooks(accountId); + System.out.println(webhooks); responses: '200': description: List of webhooks @@ -1986,6 +2689,78 @@ paths: source: | curl -X GET https://mailtrap.io/api/webhooks/{webhook_id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const webhookId = 123; + const webhook = await client.webhooks(accountId).get(webhookId); + console.log(webhook); + - lang: php + label: PHP + source: | + webhooks($accountId); + + $webhookId = $_ENV['MAILTRAP_WEBHOOK_ID']; + $response = $webhooks->getWebhook($webhookId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + webhook_id = 123 + webhook = client.webhooks_api.webhooks.get_by_id(webhook_id) + print(webhook) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + webhooks = Mailtrap::WebhooksAPI.new(account_id, client) + + webhook_id = 123 + puts webhooks.get(webhook_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var webhookId = 123; + var webhook = await client.Account(accountId).Webhook(webhookId).GetDetails(); + Console.WriteLine(webhook.Url); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long webhookId = 123L; + var webhook = client.generalApi().webhooks().getWebhook(accountId, webhookId); + System.out.println(webhook); parameters: - $ref: '#/components/parameters/webhook_id' responses: @@ -2036,6 +2811,86 @@ paths: "active": false } }' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const webhookId = 123; + const webhook = await client.webhooks(accountId).update(webhookId, { active: false }); + console.log(webhook); + - lang: php + label: PHP + source: | + webhooks($accountId); + + $webhookId = $_ENV['MAILTRAP_WEBHOOK_ID']; + $response = $webhooks->updateWebhook($webhookId, new UpdateWebhook(active: false)); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + webhook_id = 123 + webhook = client.webhooks_api.webhooks.update( + webhook_id, mt.UpdateWebhookParams(active=False) + ) + print(webhook) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + webhooks = Mailtrap::WebhooksAPI.new(account_id, client) + + webhook_id = 123 + puts webhooks.update(webhook_id, active: false) + - lang: csharp + label: .NET + source: | + using Mailtrap; + using Mailtrap.Webhooks.Requests; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var webhookId = 123; + var request = new UpdateWebhookRequest { Active = false }; + var webhook = await client.Account(accountId).Webhook(webhookId).Update(request); + Console.WriteLine(webhook.Active); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + import io.mailtrap.model.request.webhooks.UpdateWebhookRequest; + import io.mailtrap.model.request.webhooks.WebhookInput; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long webhookId = 123L; + var request = new UpdateWebhookRequest(WebhookInput.builder().active(false).build()); + var webhook = client.generalApi().webhooks().updateWebhook(accountId, webhookId, request); + System.out.println(webhook); parameters: - $ref: '#/components/parameters/webhook_id' requestBody: @@ -2135,6 +2990,74 @@ paths: source: | curl -X DELETE https://mailtrap.io/api/webhooks/{webhook_id} \ -H 'Authorization: Bearer YOUR_API_KEY' + - lang: javascript + label: Node.js + source: | + import { MailtrapClient } from "mailtrap"; + + const client = new MailtrapClient({ token: "YOUR_API_KEY" }); + + const accountId = 1000001; + const webhookId = 123; + await client.webhooks(accountId).delete(webhookId); + - lang: php + label: PHP + source: | + webhooks($accountId); + + $webhookId = $_ENV['MAILTRAP_WEBHOOK_ID']; + $response = $webhooks->deleteWebhook($webhookId); + var_dump(ResponseHelper::toArray($response)); + - lang: python + label: Python + source: | + import mailtrap as mt + + client = mt.MailtrapClient(token="YOUR_API_KEY", account_id=1000001) + + webhook_id = 123 + client.webhooks_api.webhooks.delete(webhook_id) + - lang: ruby + label: Ruby + source: | + require 'mailtrap' + + client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') + account_id = 1000001 + webhooks = Mailtrap::WebhooksAPI.new(account_id, client) + + webhook_id = 123 + webhooks.delete(webhook_id) + - lang: csharp + label: .NET + source: | + using Mailtrap; + + using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); + var client = mailtrapFactory.CreateClient(); + + var accountId = 1000001; + var webhookId = 123; + await client.Account(accountId).Webhook(webhookId).Delete(); + - lang: java + label: Java + source: | + import io.mailtrap.config.MailtrapConfig; + import io.mailtrap.factory.MailtrapClientFactory; + + var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); + var client = MailtrapClientFactory.createMailtrapClient(config); + + long accountId = 1000001L; + long webhookId = 123L; + client.generalApi().webhooks().deleteWebhook(accountId, webhookId); parameters: - $ref: '#/components/parameters/webhook_id' responses: From c9811d687dd9b331a789ee203c60227cfc0f7fc3 Mon Sep 17 00:00:00 2001 From: Marcin Klocek Date: Thu, 6 Aug 2026 17:48:06 +0200 Subject: [PATCH 6/6] Fix Node.js samples to use configured account/organization client The account-scoped resource accessors (general, organizations, stats, emailLogs, webhooks) are property getters that read accountId/organizationId from the client config, not functions. Pass the id via the MailtrapClient constructor and access the namespace as a property. --- specs/account-management.openapi.yml | 42 ++++++++-------- specs/email-sending.openapi.yml | 72 ++++++++++++++-------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/specs/account-management.openapi.yml b/specs/account-management.openapi.yml index baff229..72b805c 100644 --- a/specs/account-management.openapi.yml +++ b/specs/account-management.openapi.yml @@ -734,10 +734,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const tokens = await client.general(accountId).apiTokens.getList(); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const tokens = await client.general.apiTokens.getList(); console.log(tokens); - lang: php label: PHP @@ -831,11 +831,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + // The full token value is returned only once — store it securely. - const token = await client.general(accountId).apiTokens.create({ + const token = await client.general.apiTokens.create({ name: "My API Token", resources: [ { resource_type: "account", resource_id: accountId, access_level: 100 }, @@ -977,11 +977,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const apiTokenId = 123; - const token = await client.general(accountId).apiTokens.get(apiTokenId); + const token = await client.general.apiTokens.get(apiTokenId); console.log(token); - lang: php label: PHP @@ -1075,11 +1075,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const apiTokenId = 123; - await client.general(accountId).apiTokens.delete(apiTokenId); + await client.general.apiTokens.delete(apiTokenId); - lang: php label: PHP source: | @@ -1171,12 +1171,12 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const apiTokenId = 123; // The new token value is returned only once — store it securely. - const token = await client.general(accountId).apiTokens.reset(apiTokenId); + const token = await client.general.apiTokens.reset(apiTokenId); console.log(token); - lang: php label: PHP @@ -1463,10 +1463,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const organizationId = 2000002; - const subAccounts = await client.organizations(organizationId).subAccounts.getList(); + const client = new MailtrapClient({ token: "YOUR_API_KEY", organizationId }); + + const subAccounts = await client.organizations.subAccounts.getList(); console.log(subAccounts); - lang: php label: PHP @@ -1573,10 +1573,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const organizationId = 2000002; - const subAccount = await client.organizations(organizationId).subAccounts + const client = new MailtrapClient({ token: "YOUR_API_KEY", organizationId }); + + const subAccount = await client.organizations.subAccounts .create({ name: "New Team Account" }); console.log(subAccount); - lang: php diff --git a/specs/email-sending.openapi.yml b/specs/email-sending.openapi.yml index ae25980..4fffb5b 100644 --- a/specs/email-sending.openapi.yml +++ b/specs/email-sending.openapi.yml @@ -1526,10 +1526,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const stats = await client.stats(accountId).get({ start_date: "2026-01-01", end_date: "2026-01-31" }); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const stats = await client.stats.get({ start_date: "2026-01-01", end_date: "2026-01-31" }); console.log(stats); - lang: php label: PHP @@ -1632,10 +1632,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const stats = await client.stats(accountId).byDomain({ start_date: "2026-01-01", end_date: "2026-01-31" }); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const stats = await client.stats.byDomain({ start_date: "2026-01-01", end_date: "2026-01-31" }); console.log(stats); - lang: php label: PHP @@ -1753,10 +1753,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const stats = await client.stats(accountId).byCategory({ start_date: "2026-01-01", end_date: "2026-01-31" }); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const stats = await client.stats.byCategory({ start_date: "2026-01-01", end_date: "2026-01-31" }); console.log(stats); - lang: php label: PHP @@ -1867,10 +1867,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const stats = await client.stats(accountId).byEmailServiceProvider({ start_date: "2026-01-01", end_date: "2026-01-31" }); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const stats = await client.stats.byEmailServiceProvider({ start_date: "2026-01-01", end_date: "2026-01-31" }); console.log(stats); - lang: php label: PHP @@ -1981,10 +1981,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const stats = await client.stats(accountId).byDate({ start_date: "2026-01-01", end_date: "2026-01-31" }); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const stats = await client.stats.byDate({ start_date: "2026-01-01", end_date: "2026-01-31" }); console.log(stats); - lang: php label: PHP @@ -2100,10 +2100,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const page = await client.emailLogs(accountId).getList(); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const page = await client.emailLogs.getList(); console.log(page); - lang: php label: PHP @@ -2214,11 +2214,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const messageId = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d"; - const message = await client.emailLogs(accountId).get(messageId); + const message = await client.emailLogs.get(messageId); console.log(message.subject); - lang: php label: PHP @@ -2328,11 +2328,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + // The signing secret is returned only on creation — store it securely. - const webhook = await client.webhooks(accountId).create({ + const webhook = await client.webhooks.create({ url: "https://example.com/mailtrap/webhooks", webhook_type: "email_sending", payload_format: "json", @@ -2581,10 +2581,10 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; - const webhooks = await client.webhooks(accountId).getList(); + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + + const webhooks = await client.webhooks.getList(); console.log(webhooks); - lang: php label: PHP @@ -2694,11 +2694,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const webhookId = 123; - const webhook = await client.webhooks(accountId).get(webhookId); + const webhook = await client.webhooks.get(webhookId); console.log(webhook); - lang: php label: PHP @@ -2816,11 +2816,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const webhookId = 123; - const webhook = await client.webhooks(accountId).update(webhookId, { active: false }); + const webhook = await client.webhooks.update(webhookId, { active: false }); console.log(webhook); - lang: php label: PHP @@ -2995,11 +2995,11 @@ paths: source: | import { MailtrapClient } from "mailtrap"; - const client = new MailtrapClient({ token: "YOUR_API_KEY" }); - const accountId = 1000001; + const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId }); + const webhookId = 123; - await client.webhooks(accountId).delete(webhookId); + await client.webhooks.delete(webhookId); - lang: php label: PHP source: |