Create an email campaign

Code Examples

You can use as reference the code below to implement this call in your preferred language.
Check all our official API clients here

const SibApiV3Sdk = require('sib-api-v3-sdk');
let defaultClient = SibApiV3Sdk.ApiClient.instance;

let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'YOUR API KEY';

let apiInstance = new SibApiV3Sdk.EmailCampaignsApi();
let emailCampaigns = new SibApiV3Sdk.CreateEmailCampaign(); 
emailCampaigns = {
  tag: 'myTag',
  sender: {name: 'senderName', email: 'sender@domain.com'}, name: 'My First Campaign',
  templateId: 10,
  scheduledAt: new Date("2019-03-25T15:10:00+05:30"),
  subject: ' My {{params.subject}}',
  replyTo: 'replyto@domain.com',
  toField: '{{contact.FIRSTNAME}} {{contact.LASTNAME}}',
  recipients: {listIds: [1, 3], exclusionListIds: [2]},
  attachmentUrl: 'https://attachment.domain.com/myAttachmentFromUrl.jpg',
  inlineImageActivation: false,
  mirrorActive: false,
  recurring: false,
  type: 'classic',
  header: 'If you are not able to see this mail, click {here}',
  footer: 'If you wish to unsubscribe from our newsletter, click {here}',
  utmCampaign: 'My utm campaign value',
  params: {'PARAMETER': 'My param value' , 'ADDRESS': 'Seattle, WA', 'SUBJECT': 'New Subject'} 
}
apiInstance.createEmailCampaign(emailCampaigns).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
  console.error(error);
});
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API KEY');

$apiInstance = new SendinBlue\Client\Api\EmailCampaignsApi(
    new GuzzleHttp\Client(),
    $config
);
$emailCampaigns = new \SendinBlue\Client\Model\CreateEmailCampaign();
$emailCampaigns['tag'] = 'myTag';
$emailCampaigns['sender'] =  array('name' => 'senderName', 'email' => 'sender@domain.com');
$emailCampaigns['name'] = 'My First Campaign';
$emailCampaigns['templateId'] = 1;
$emailCampaigns['scheduledAt'] = new \DateTime('2021-01-01T00:00:00+00:00');
$emailCampaigns['subject'] = 'My {{params.subject}}';
$emailCampaigns['replyTo'] = 'replyto@domain.com';
$emailCampaigns['toField'] = '{{contact.FIRSTNAME}} {{contact.LASTNAME}}';
$emailCampaigns['recipients'] =  array(
	'listIds' => array(1, 3), 'exclusionListIds' => array(2)
);
$emailCampaigns['attachmentUrl'] = 'https://attachment.domain.com/myAttachmentFromUrl.jpg';
$emailCampaigns['inlineImageActivation'] = false;
$emailCampaigns['mirrorActive'] = false;
$emailCampaigns['recurring'] = false;
$emailCampaigns['type'] = 'classic';
$emailCampaigns['header'] = 'If you are not able to see this mail, click {here}';
$emailCampaigns['footer'] = 'If you wish to unsubscribe from our newsletter, click {here}';
$emailCampaigns['utmCampaign'] = 'My utm campaign value';
$emailCampaigns['params'] = array('PARAMETER' => 'My param value', 'ADDRESS' => 'Seattle, WA', 'SUBJECT' => 'New Subject');

try {
    $result = $apiInstance->createEmailCampaign($emailCampaigns);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling EmailCampaignsApi->createEmailCampaign: ', $e->getMessage(), PHP_EOL;
}
?>
from __future__ import print_function
import time
import datetime
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint

configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR API KEY'

api_instance = sib_api_v3_sdk.EmailCampaignsApi(sib_api_v3_sdk.ApiClient(configuration))
tag = 'myTag'
sender = {"name": 'senderName', "email": 'sender@domain.com'}
name = 'My First Campaign'
template_id= 10
scheduled_at = "2021-03-25T15:10:00+05:30"
subject = ' My Subject'
reply_to = 'replyto@domain.com'
to_field = 'John Doe'
recipients = {"listIds": [1, 3], "exclusionListIds": [2]}
attachment_url = 'https://attachment.domain.com/myAttachmentFromUrl.jpg'
inline_image_activation = False
mirror_active = False
header = 'If you are not able to see this mail, click {here}'
footer = 'If you wish to unsubscribe from our newsletter, click {here}'
utm_campaign = 'My utm campaign value'
email_campaigns = sib_api_v3_sdk.CreateEmailCampaign(tag=tag, sender=sender, name=name, template_id=template_id, scheduled_at=scheduled_at, subject=subject, reply_to=reply_to, to_field=to_field, recipients=recipients, attachment_url=attachment_url, inline_image_activation=inline_image_activation,mirror_active=mirror_active, header=header, footer=footer, utm_campaign=utm_campaign) # CreateEmailCampaign | Values to create a campaign

try:
    api_response = api_instance.create_email_campaign(email_campaigns)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling EmailCampaignsApi->create_email_campaign: %s\n" % e)
const SibApiV3Sdk = require('sib-api-v3-typescript');

let apiInstance = new SibApiV3Sdk.EmailCampaignsApi();

let apiKey = apiInstance.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';

let emailCampaigns = new SibApiV3Sdk.CreateEmailCampaign();
emailCampaigns = {
  tag: 'myTag',
  sender: {name: 'senderName', email: 'sender@domain.com'}, name: 'My First Campaign',
  templateId: 10,
  scheduledAt: new Date("2019-03-25T15:10:00+05:30"),
  subject: ' My {{params.subject}}',
  replyTo: 'replyto@domain.com',
  toField: '{{contact.FIRSTNAME}} {{contact.LASTNAME}}',
  recipients: {listIds: [1, 3], exclusionListIds: [2]},
  attachmentUrl: 'https://attachment.domain.com/myAttachmentFromUrl.jpg',
  inlineImageActivation: false,
  mirrorActive: false,
  recurring: false,
  type: 'classic',
  header: 'If you are not able to see this mail, click {here}',
  footer: 'If you wish to unsubscribe from our newsletter, click {here}',
  utmCampaign: 'My utm campaign value',
  params: {'PARAMETER': 'My param value' , 'ADDRESS': 'Seattle, WA', 'SUBJECT': 'New Subject'}
}

apiInstance.createEmailCampaign(emailCampaigns).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
  console.error(error);
});
package sibApi;

import sendinblue.ApiClient;
import sendinblue.Configuration;
import sendinblue.auth.ApiKeyAuth;
import sibModel.*;
import org.threeten.bp.OffsetDateTime;
import java.util.*;
import java.util.List;

public class Program {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        // Configure API key authorization: api-key
        ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("api-key");
        apiKey.setApiKey("YOUR API KEY");

        try {
            EmailCampaignsApi api = new EmailCampaignsApi();
            CreateEmailCampaignSender sender = new CreateEmailCampaignSender();
            sender.setEmail("example@example.com");
            sender.setName("John Doe");
            String scheduledAt = ("2021-08-22T09:43:51.970+05:30";
            List<Long> listIds = new ArrayList<Long>();
            listIds.add(2l);
            List<Long> exclusionListIds = new ArrayList<Long>();
            exclusionListIds.add(4l);
            CreateEmailCampaignRecipients recipients = new CreateEmailCampaignRecipients();
            recipients.setListIds(listIds);
            recipients.setExclusionListIds(exclusionListIds);
            CreateEmailCampaign emailCampaigns = new CreateEmailCampaign();
            emailCampaigns.setTag("myTag");
            emailCampaigns.setSender(sender);
            emailCampaigns.setName("My First Campaign");
            emailCampaigns.setTemplateId(1l);
            emailCampaigns.setScheduledAt(scheduledAt);
            emailCampaigns.setSubject("My {{params.subject}}");
            emailCampaigns.setReplyTo("replyto@domain.com");
            emailCampaigns.setToField("{{contact.FIRSTNAME}} {{contact.LASTNAME}}");
            emailCampaigns.setRecipients(recipients);
            emailCampaigns.setAttachmentUrl("https://attachment.domain.com/myAttachmentFromUrl.jpg");
            emailCampaigns.setInlineImageActivation(false);
            emailCampaigns.setMirrorActive(false);
            emailCampaigns.setHeader("If you are not able to see this mail, click {here}");
            emailCampaigns.setFooter("If you wish to unsubscribe from our newsletter, click {here}");
            emailCampaigns.setUtmCampaign("My utm campaign value");
            Properties params = new Properties();
            params.setProperty("PARAMETER","My param value");
            params.setProperty("ADDRESS","Seattle, WA");
            params.setProperty("SUBJECT","New Subject");
            emailCampaigns.setParams(params);
            CreateModel response = api.createEmailCampaign(emailCampaigns);
            System.out.println(response.toString());
        } catch (Exception e) {
            System.out.println("Exception occurred:- " + e.getMessage());
        }
    }
}
using sib_api_v3_sdk.Api;
using sib_api_v3_sdk.Client;
using sib_api_v3_sdk.Model;
using System;
using System.Diagnostics;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace Sendinblue
{
    class Program
    {
        static void Main(string[] args)
        {
            Configuration.Default.ApiKey.Add("api-key", "YOUR API KEY");

            var apiInstance = new EmailCampaignsApi();
            string tag = "myTag";
            string sender_Name = "John Doe";
            string sender_Email = "example@example.com";
            CreateEmailCampaignSender sender = new CreateEmailCampaignSender(sender_Name, sender_Email);
            string name = "My First Campaign";
            string htmlContent = null;
            string htmlUrl = null;
            long? templateId = 1;
            string scheduledAt = "2021-12-24T16:03:51.000+05:30";
            string subject = "My {{params.subject}}";
            string replyTo = "replyto@domain.com";
            string toField = "{{contact.FIRSTNAME}} {{contact.LASTNAME}}";
            List<long?> exclusionListIds = new List<long?>();
            exclusionListIds.Add(4);
            List<long?> listIds = new List<long?>();
            listIds.Add(2);
            CreateEmailCampaignRecipients recipients = new CreateEmailCampaignRecipients(exclusionListIds, listIds);
            string attachmentUrl = "https://attachment.domain.com/myAttachmentFromUrl.jpg";
            bool? inlineImageActivation = false;
            bool? mirrorActive = false;
            string footer = "If you wish to unsubscribe from our newsletter, click {here}";
            string header = "If you are not able to see this mail, click {here}";
            string utmCampaign = "My utm campaign value";
            JObject _params = new JObject();
            _params.Add("PARAMETER", "My param value");
            _params.Add("ADDRESS", "Seattle, WA");
            _params.Add("SUBJECT", "New Subject");
            try
            {
                var emailCampaigns = new CreateEmailCampaign(tag, sender, name, htmlContent, htmlUrl, templateId, scheduledAt, subject, replyTo, toField, recipients, attachmentUrl, inlineImageActivation, mirrorActive, footer, header, utmCampaign, _params);
                CreateModel result = apiInstance.CreateEmailCampaign(emailCampaigns);
                Debug.WriteLine(result.ToJson());
                Console.WriteLine(result.ToJson());
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
    }
}
package main
import (
	"fmt"
	"context"
    sib_api_v3_sdk "./lib"
)

func main() {
	var ctx context.Context
	var cli = sib_api_v3_sdk.APIClient{
		cfg: sib_api_v3_sdk.NewConfiguration(),
	}
	//Configure API key authorization: api-key
	cli.cfg.AddDefaultHeader("api-key", "YOUR_API_KEY")

	sib := sib_api_v3_sdk.NewAPIClient(cli.cfg)
	s := &CreateEmailCampaignSender{
		Name:  "MyName",
		Email: "example@example.com",
	}
	params := CreateEmailCampaign{
		Sender:                s,
		Name:                  "TestCampaign",
		HtmlContent:           "Hi There! welcome to SIB",
		Subject:               "Welcome!",
		AttachmentUrl:         "https://attachment.domain.com/myAttachmentFromUrl.jpg",
		InlineImageActivation: false,
		ReplyTo:               "replyto@domain.com",
		TemplateId:            int64(10),
		ToField:               "John Doe",
		Recipients: &CreateEmailCampaignRecipients{
			ListIds:          []int64{2},
			ExclusionListIds: []int64{1, 3},
		},
    Tag: "myTag",
    ScheduledAt:"2021-03-25T15:10:00+05:30",
    Header: 'If you are not able to see this mail, click {here}',
    Footer: 'If you wish to unsubscribe from our newsletter, click {here}',
    UtmCampaign: 'My utm campaign value',
	}
	obj, resp, err := sib.EmailCampaignsApi.CreateEmailCampaign(ctx, params)
    if err!=nil{
        fmt.Println("Error in EmailCampaignsApi->CreateEmailCampaign ",err.Error())
        return
    }
	fmt.Println( "CreateEmailCampaign, response:",resp,"CreateEmailCampaign object",obj)
	return 
}
# load the gem
require 'sib-api-v3-sdk'
# setup authorization
SibApiV3Sdk.configure do |config|
  # Configure API key authorization: api-key
  config.api_key['api-key'] = 'YOUR API KEY'
end

api_instance = SibApiV3Sdk::EmailCampaignsApi.new

email_campaigns = SibApiV3Sdk::CreateEmailCampaign.new # CreateEmailCampaign | Values to create a campaign

email_campaigns = {
  'name'=> 'my new campaign',
  'subject'=> 'My {{params.subject}}',
  'sender'=> {
      'name'=> 'senderName',
      'email'=> 'sender@domain.com'
  },
  'templateId'=> 10,
  'scheduledAt'=> DateTime.iso8601('2021-02-03T04:05:06+07:00'),
  'replyTo'=> 'replyto@domain.com',
  'toField'=> '{{contact.FIRSTNAME}} {{contact.LASTNAME}}',
  'recipients'=> {
    'listIds'=> [1,3],
    'exclusionListIds'=> [2]
  },
  'attachmentUrl'=> 'https://attachment.domain.com/myAttachmentFromUrl.jpg',
  'inlineImageActivation'=> false,
  'mirrorActive'=> false,
  'recurring'=> false,
  'type'=> 'classic',
  'tag'=> 'myTag',
  'header'=> 'If you are not able to see this mail, click {here}',
  'footer'=> 'If you wish to unsubscribe from our newsletter, click {here}',
  'utmCampaign'=> 'My utm campaign value',
  'params'=> {
    'PARAMETER'=> 'My param value',
    'ADDRESS'=> 'Seattle, WA',
    'SUBJECT'=> 'New Subject'
  }
};

begin
  #Create an email campaign
  result = api_instance.create_email_campaign(email_campaigns)
  p result
rescue SibApiV3Sdk::ApiError => e
  puts "Exception when calling EmailCampaignsApi->create_email_campaign: #{e}"
end
Language
Credentials
Header
Click Try It! to start a request and see the response here!