Injection API

The injection API lets you send email. Each endpoint can send an email to a single recipient or thousands. SocketLabs generates and sends the messages using the options you’ve defined in the emailMessage object.

Create an Injection API Key

API calls to the Injection API are authenticated using the API key that you generated. Authenticate your calls to the Injection API using the Authorization header with the Bearer authentication scheme.

Endpoint

https://api.socketlabs.com/v2/subaccount/:subaccountId/credentials/injection-api

Path Variables

  • subaccountId (number, required)

Example Request

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.socketlabs.com/v2/subaccount/12345/credentials/injection-api");
request.Headers.Add("Authorization", "Bearer <token>");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

Example Response

{
    "data": {
        "serverId": 12345,
        "apiKey": "abcdefghijklmnop1234567890",
        "gateway": "https://inject-cx.socketlabs.com/api/v1/email"
    }
}

Injection API

If you do not want to use one of our prebuilt libraries, the easiest process for sending mail with the injection API is to:

  1. Create a new Injection API Key
  2. Create Email Message Object
  3. Build and Add the Recipient Array to the Message Object
  4. (Optional) Build and Add Custom Headers
  5. (Optional) Build and Add Merge Data
  6. Send with the Injection API

Create Email Message Object

The email message object includes options for different email body types, CC and BCC, merge data, custom headers, and more to give you the most flexibility around your email sending needs.

For example code, please refer to our library code examples

Email Message Required Attributes

Property Name Data Type Details
To (array[Recipient])  An array of recipient EmailAddress/ FriendlyName value pairs representing the recipients of an email message.
From Recipient The EmailAddress/FriendlyName value pair for the sender of the message.
Subject String The subject line of the email message. 200 character limit.

Email Message Optional Attributes

Property Name Data Type Details
ReplyTo Recipient The EmailAddress/FriendlyName value pair for the sender of the message
TextBody string Body of text that would be the content of the mesage--this or HtmlBody are required
Htmlbody string Body of text that would be the content of the message- this or TextBody are required
AmpBody string body portion
MergeData string Data storage for the inline merge feature
MessageId string SocketLabs header used to tag individual messages
MailingId string SocketLabs header used to track batches of messages
Charset string The charset name to be used when creating the message. Default is UTF8.
CustomHeaders array[CustomHeader] An array of header feld data stored in Name/ Value pairs.
CC array[Recipient] An array of recipient EmailAddress/ FriendlyName value pairs representing the CC’d recipients of an email message.
BCC array[Recipient] An array of recipient EmailAddress/ FriendlyName value pairs representing the BCC’d recipients of an email message.
Attachments array[Attachment] An array of attached content blobs, such as images, documents, and other binary fles. This is not recommended for bulk sending, as many receivers will either not accept the mail or will mark it as spam.

Injection API

If you do not want to use one of our prebuilt libraries, the easiest process for sending mail with the injection API is to:

  1. Create a new Injection API Key
  2. Create Email Message Object
  3. Build and Add the Recipient Array to the Message Object
  4. (Optional) Build and Add Custom Headers
  5. (Optional) Build and Add Merge Data
  6. Send with the Injection API

Create Email Message Object

The email message object includes options for different email body types, CC and BCC, merge data, custom headers, and more to give you the most flexibility around your email sending needs. 

For example code, please refer to our library code examples.

Email Message Required Attributes

Property Name Data Type Details
To (array[Recipient])  An array of recipient EmailAddress/ FriendlyName value pairs representing the recipients of an email message.
From Recipient The EmailAddress/FriendlyName value pair for the sender of the message.
Subject String The subject line of the email message. 200 character limit.

Recipient Array Attributes

Property Name Data Type Details
emailAddress string An email address string such as foo@bar.com. This is required.
friendlyName string An alias for an email address. This is optional.

(Optional) Build and Add Custom Headers

Property Name Data Type Details
PerMessage array[array[MergeValueData]] A two dimensional (2D) array of Field/Value pairs, used to defne merge feld data for each message. Variables can be freely named, with the exception of a single reserved word, ‘DeliveryAddress‘, which defnes the recipient of the current message.
Global array[MergeValueData] A array of Field:Value pairs that will be applied globally to all recipients.

MergeValueData

Property Name Data Type Details
Field string Optional
Value string Optional

Send with the Injection API Example Request

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://inject-cx.socketlabs.com/api/v1/email");
var content = new StringContent("{\r\n    \"serverId\": YOUR-SERVER-ID,\r\n    \"APIKey\": \"YOUR-API-KEY\",\r\n    \"Messages\": [\r\n        {\r\n            \"To\": [\r\n                {\r\n                    \"emailAddress\": \"recipient1@example.com\"\r\n                }\r\n            ],\r\n            \"From\": {\r\n                \"emailAddress\": \"from@example.com\"\r\n            },\r\n            \"Subject\": \"Sending a Basic Message\",\r\n            \"TextBody\": \"This is the Plain Text Body of my message.\",\r\n            \"HtmlBody\": \"<html>This is the Html Body of my message.</html>\"\r\n        }\r\n    ]\r\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

Example Success Response

{
  "ErrorCode": "Success",
  "MessageResults": [],
  "TransactionReceipt": "null"
}

Example Failure Response

{
    "data": {
        "error": [{
            "errorType": "string",
            "message": "string"
        }]
    }
}

Failure Codes

Please see the API documentation for more details regarding failure codes.

Want to set up SMTP? Our next section will assist. 

Other Resources