Request
POST https://{hostname}/v3/campaigns/create.{Format}?apikey=
Request body:
{
"Name": "Test campaign",
"Subject": "Some subject",
"SenderEmail": "something@email.com",
"ReplyToEmail": "something@email.com",
"ConfirmationToEmail": "something@email.com",
"HTMLContent": "Some HTML body",
"MailingLists": [
{
"MailingListID": "adaf2fe1-55db-42dc-aaf8-56d8f502138d",
"SegmentID": "10166"
},
{
"MailingListID": "dce99b7a-2619-4805-aaeb-7fecdcb3c71b"
}
],
"IsAB": "true",
"ABCampaignType": "Content",
"WebLocationB": "http://www.mysite.gr/newsletter/index",
"HoursToTest": "2",
"ListPercentage": "20",
"ABWinnerSelectionType": "OpenRate"
}
Request
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data-binary "{
\"Name\":\"Test campaign\",
\"Subject\":\"Some subject\",
\"SenderEmail\":\"something@email.com\",
\"ReplyToEmail\":\"something@email.com\",
\"ConfirmationToEmail\":\"something@email.com\",
\"HTMLContent\":\"Some HTML body\",
\"MailingLists\": [
{
\"MailingListID\":\"adaf2fe1-55db-42dc-aaf8-56d8f502138d\",
\"SegmentID\":\"10166\"
},
{
\"MailingListID\":\"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\"
}
],
\"IsAB\":\"true\",
\"ABCampaignType\":\"Content\",
\"WebLocationB\":\"http://www.mysite.gr/newsletter/index\",
\"HoursToTest\":\"2\",
\"ListPercentage\":\"20\",
\"ABWinnerSelectionType\":\"OpenRate\"
}" \
'https://{hostname}/v3/campaigns/create.{Format}?apikey='
Request
// Maven : Add these dependencies to your pom.xml (java6+)
// <dependency>
// <groupId>org.glassfish.jersey.core</groupId>
// <artifactId>jersey-client</artifactId>
// <version>2.8</version>
// </dependency>
// <dependency>
// <groupId>org.glassfish.jersey.media</groupId>
// <artifactId>jersey-media-json-jackson</artifactId>
// <version>2.8</version>
// </dependency>
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
Client client = ClientBuilder.newClient();
Entity payload = Entity.json("{ \"Name\": \"Test campaign\", \"Subject\": \"Some subject\", \"SenderEmail\": \"something@email.com\", \"ReplyToEmail\": \"something@email.com\", \"ConfirmationToEmail\": \"something@email.com\", \"HTMLContent\": \"Some HTML body\", \"MailingLists\": [ { \"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\", \"SegmentID\": \"10166\" }, { \"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\" } ], \"IsAB\": \"true\", \"ABCampaignType\": \"Content\", \"WebLocationB\": \"http://www.mysite.gr/newsletter/index\", \"HoursToTest\": \"2\", \"ListPercentage\": \"20\", \"ABWinnerSelectionType\": \"OpenRate\"}");
Response response = client.target("https://{hostname}/v3/campaigns/create.{Format}?apikey=")
.request(MediaType.APPLICATION_JSON_TYPE)
.header("Accept", "application/json")
.post(payload);
System.out.println("status: " + response.getStatus());
System.out.println("headers: " + response.getHeaders());
System.out.println("body:" + response.readEntity(String.class));
Request
var request = new XMLHttpRequest();
request.open('POST', 'https://{hostname}/v3/campaigns/create.{Format}?apikey=');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', 'application/json');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = {
'Name': 'Test campaign',
'Subject': 'Some subject',
'SenderEmail': 'something@email.com',
'ReplyToEmail': 'something@email.com',
'ConfirmationToEmail': 'something@email.com',
'HTMLContent': 'Some HTML body',
'MailingLists': [
{
'MailingListID': 'adaf2fe1-55db-42dc-aaf8-56d8f502138d',
'SegmentID': '10166'
},
{
'MailingListID': 'dce99b7a-2619-4805-aaeb-7fecdcb3c71b'
}
],
'IsAB': 'true',
'ABCampaignType': 'Content',
'WebLocationB': 'http://www.mysite.gr/newsletter/index',
'HoursToTest': '2',
'ListPercentage': '20',
'ABWinnerSelectionType': 'OpenRate'
};
request.send(JSON.stringify(body));
Request
var request = require('request');
request({
method: 'POST',
url: 'https://{hostname}/v3/campaigns/create.{Format}?apikey=',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: "{ \"Name\": \"Test campaign\", \"Subject\": \"Some subject\", \"SenderEmail\": \"something@email.com\", \"ReplyToEmail\": \"something@email.com\", \"ConfirmationToEmail\": \"something@email.com\", \"HTMLContent\": \"Some HTML body\", \"MailingLists\": [ { \"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\", \"SegmentID\": \"10166\" }, { \"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\" } ], \"IsAB\": \"true\", \"ABCampaignType\": \"Content\", \"WebLocationB\": \"http://www.mysite.gr/newsletter/index\", \"HoursToTest\": \"2\", \"ListPercentage\": \"20\", \"ABWinnerSelectionType\": \"OpenRate\"}"
}, function (error, response, body) {
console.log('Status:', response.statusCode);
console.log('Headers:', JSON.stringify(response.headers));
console.log('Response:', body);
});
Request
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
use LWP::UserAgent;
use strict;
use warnings;
use 5.010;
use Cpanel::JSON::XS qw(encode_json decode_json);
my $ua = LWP::UserAgent->new;
my $data = '{ "Name": "Test campaign", "Subject": "Some subject", "SenderEmail": "something@email.com", "ReplyToEmail": "something@email.com", "ConfirmationToEmail": "something@email.com", "HTMLContent": "Some HTML body", "MailingLists": [ { "MailingListID": "adaf2fe1-55db-42dc-aaf8-56d8f502138d", "SegmentID": "10166" }, { "MailingListID": "dce99b7a-2619-4805-aaeb-7fecdcb3c71b" } ], "IsAB": "true", "ABCampaignType": "Content", "WebLocationB": "http://www.mysite.gr/newsletter/index", "HoursToTest": "2", "ListPercentage": "20", "ABWinnerSelectionType": "OpenRate"}';
$ua->default_header("Content-Type" => "application/json");
$ua->default_header("Accept" => "application/json");
my $response = $ua->post("https://{hostname}/v3/campaigns/create.{Format}?apikey=", Content => $data);
print $response->as_string;
Request
from urllib2 import Request, urlopen
values = """
{
"Name": "Test campaign",
"Subject": "Some subject",
"SenderEmail": "something@email.com",
"ReplyToEmail": "something@email.com",
"ConfirmationToEmail": "something@email.com",
"HTMLContent": "Some HTML body",
"MailingLists": [
{
"MailingListID": "adaf2fe1-55db-42dc-aaf8-56d8f502138d",
"SegmentID": "10166"
},
{
"MailingListID": "dce99b7a-2619-4805-aaeb-7fecdcb3c71b"
}
],
"IsAB": "true",
"ABCampaignType": "Content",
"WebLocationB": "http://www.mysite.gr/newsletter/index",
"HoursToTest": "2",
"ListPercentage": "20",
"ABWinnerSelectionType": "OpenRate"
}
"""
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
request = Request('https://{hostname}/v3/campaigns/create.{Format}?apikey=', data=values, headers=headers)
response_body = urlopen(request).read()
print response_body
Request
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://{hostname}/v3/campaigns/create.{Format}?apikey=");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"Name\": \"Test campaign\",
\"Subject\": \"Some subject\",
\"SenderEmail\": \"something@email.com\",
\"ReplyToEmail\": \"something@email.com\",
\"ConfirmationToEmail\": \"something@email.com\",
\"HTMLContent\": \"Some HTML body\",
\"MailingLists\": [
{
\"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\",
\"SegmentID\": \"10166\"
},
{
\"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\"
}
],
\"IsAB\": \"true\",
\"ABCampaignType\": \"Content\",
\"WebLocationB\": \"http://www.mysite.gr/newsletter/index\",
\"HoursToTest\": \"2\",
\"ListPercentage\": \"20\",
\"ABWinnerSelectionType\": \"OpenRate\"
}");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Accept: application/json"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
Request
require 'rubygems' if RUBY_VERSION < '1.9'
require 'rest_client'
values = '{
"Name": "Test campaign",
"Subject": "Some subject",
"SenderEmail": "something@email.com",
"ReplyToEmail": "something@email.com",
"ConfirmationToEmail": "something@email.com",
"HTMLContent": "Some HTML body",
"MailingLists": [
{
"MailingListID": "adaf2fe1-55db-42dc-aaf8-56d8f502138d",
"SegmentID": "10166"
},
{
"MailingListID": "dce99b7a-2619-4805-aaeb-7fecdcb3c71b"
}
],
"IsAB": "true",
"ABCampaignType": "Content",
"WebLocationB": "http://www.mysite.gr/newsletter/index",
"HoursToTest": "2",
"ListPercentage": "20",
"ABWinnerSelectionType": "OpenRate"
}'
headers = {
:content_type => 'application/json',
:accept => 'application/json'
}
response = RestClient.post 'https://{hostname}/v3/campaigns/create.{Format}?apikey=', values, headers
puts response
Request
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
client := &http.Client{}
body := []byte("{\n \"Name\": \"Test campaign\",\n \"Subject\": \"Some subject\",\n \"SenderEmail\": \"something@email.com\",\n \"ReplyToEmail\": \"something@email.com\",\n \"ConfirmationToEmail\": \"something@email.com\",\n \"HTMLContent\": \"Some HTML body\",\n \"MailingLists\": [\n {\n \"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\",\n \"SegmentID\": \"10166\"\n },\n {\n \"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\"\n }\n ],\n \"IsAB\": \"true\",\n \"ABCampaignType\": \"Content\",\n \"WebLocationB\": \"http://www.mysite.gr/newsletter/index\",\n \"HoursToTest\": \"2\",\n \"ListPercentage\": \"20\",\n \"ABWinnerSelectionType\": \"OpenRate\"\n}")
req, _ := http.NewRequest("POST", "https://{hostname}/v3/campaigns/create.{Format}?apikey=", bytes.NewBuffer(body))
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Errored when sending request to the server")
return
}
defer resp.Body.Close()
resp_body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(resp.Status)
fmt.Println(string(resp_body))
}
Request
//Common testing requirement. If you are consuming an API in a sandbox/test region, uncomment this line of code ONLY for non production uses.
//System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
//Be sure to run "Install-Package Microsoft.Net.Http" from your nuget command line.
using System;
using System.Net.Http;
var baseAddress = new Uri("https://{hostname}/v3/");
using (var httpClient = new HttpClient{ BaseAddress = baseAddress })
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
using (var content = new StringContent("{ \"Name\": \"Test campaign\", \"Subject\": \"Some subject\", \"SenderEmail\": \"something@email.com\", \"ReplyToEmail\": \"something@email.com\", \"ConfirmationToEmail\": \"something@email.com\", \"HTMLContent\": \"Some HTML body\", \"MailingLists\": [ { \"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\", \"SegmentID\": \"10166\" }, { \"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\" } ], \"IsAB\": \"true\", \"ABCampaignType\": \"Content\", \"WebLocationB\": \"http://www.mysite.gr/newsletter/index\", \"HoursToTest\": \"2\", \"ListPercentage\": \"20\", \"ABWinnerSelectionType\": \"OpenRate\"}", System.Text.Encoding.Default, "application/json"))
{
using (var response = await httpClient.PostAsync("campaigns/{CampaignID}/clone.{Format}{?apikey}", content))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
}
Request
Dim request = TryCast(System.Net.WebRequest.Create("https://{hostname}/v3/campaigns/create.{Format}?apikey="), System.Net.HttpWebRequest)
request.Method = "POST"
request.ContentType = "application/json"
request.Accept = "application/json"
Using writer = New System.IO.StreamWriter(request.GetRequestStream())
Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes("{
\""Name\"": \""Test campaign\"",
\""Subject\"": \""Some subject\"",
\""SenderEmail\"": \""something@email.com\"",
\""ReplyToEmail\"": \""something@email.com\"",
\""ConfirmationToEmail\"": \""something@email.com\"",
\""HTMLContent\"": \""Some HTML body\"",
\""MailingLists\"": [
{
\""MailingListID\"": \""adaf2fe1-55db-42dc-aaf8-56d8f502138d\"",
\""SegmentID\"": \""10166\""
},
{
\""MailingListID\"": \""dce99b7a-2619-4805-aaeb-7fecdcb3c71b\""
}
],
\""IsAB\"": \""true\"",
\""ABCampaignType\"": \""Content\"",
\""WebLocationB\"": \""http://www.mysite.gr/newsletter/index\"",
\""HoursToTest\"": \""2\"",
\""ListPercentage\"": \""20\"",
\""ABWinnerSelectionType\"": \""OpenRate\""
}")
request.ContentLength = byteArray.Length
writer.Write(byteArray)
writer.Close()
End Using
Dim responseContent As String
Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
Using reader = New System.IO.StreamReader(response.GetResponseStream())
responseContent = reader.ReadToEnd()
End Using
End Using
Request
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
@Grab (group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.5.0')
def client = new RESTClient("https://{hostname}/v3")
def emptyHeaders = [:]
emptyHeaders."Content-Type" = "application/json"
emptyHeaders."Accept" = "application/json"
def jsonObj = new JsonSlurper().parseText('{
"Name": "Test campaign",
"Subject": "Some subject",
"SenderEmail": "something@email.com",
"ReplyToEmail": "something@email.com",
"ConfirmationToEmail": "something@email.com",
"HTMLContent": "Some HTML body",
"MailingLists": [
{
"MailingListID": "adaf2fe1-55db-42dc-aaf8-56d8f502138d",
"SegmentID": "10166"
},
{
"MailingListID": "dce99b7a-2619-4805-aaeb-7fecdcb3c71b"
}
],
"IsAB": "true",
"ABCampaignType": "Content",
"WebLocationB": "http://www.mysite.gr/newsletter/index",
"HoursToTest": "2",
"ListPercentage": "20",
"ABWinnerSelectionType": "OpenRate"
}')
response = client.post( path : "/campaigns/{CampaignID}/clone.{Format}{?apikey}",
body : jsonObj,
headers: emptyHeaders,
contentType : JSON )
println("Status:" + response.status)
if (response.data) {
println("Content Type: " + response.contentType)
println("Body:\n" + JsonOutput.prettyPrint(JsonOutput.toJson(response.data)))
}
Request
NSURL *URL = [NSURL URLWithString:@"https://{hostname}/v3/campaigns/create.{Format}?apikey="];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPBody:[@"{\n \"Name\": \"Test campaign\",\n \"Subject\": \"Some subject\",\n \"SenderEmail\": \"something@email.com\",\n \"ReplyToEmail\": \"something@email.com\",\n \"ConfirmationToEmail\": \"something@email.com\",\n \"HTMLContent\": \"Some HTML body\",\n \"MailingLists\": [\n {\n \"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\",\n \"SegmentID\": \"10166\"\n },\n {\n \"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\"\n }\n ],\n \"IsAB\": \"true\",\n \"ABCampaignType\": \"Content\",\n \"WebLocationB\": \"http://www.mysite.gr/newsletter/index\",\n \"HoursToTest\": \"2\",\n \"ListPercentage\": \"20\",\n \"ABWinnerSelectionType\": \"OpenRate\"\n}" dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
// Handle error...
return;
}
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSLog(@"Response HTTP Status code: %ld\n", (long)[(NSHTTPURLResponse *)response statusCode]);
NSLog(@"Response HTTP Headers:\n%@\n", [(NSHTTPURLResponse *)response allHeaderFields]);
}
NSString* body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response Body:\n%@\n", body);
}];
[task resume];
Request
import Foundation
// NOTE: Uncommment following two lines for use in a Playground
// import PlaygroundSupport
// PlaygroundPage.current.needsIndefiniteExecution = true
let url = URL(string: "https://{hostname}/v3/campaigns/create.{Format}?apikey=")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.httpBody = """
"{\n \"Name\": \"Test campaign\",\n \"Subject\": \"Some subject\",\n \"SenderEmail\": \"something@email.com\",\n \"ReplyToEmail\": \"something@email.com\",\n \"ConfirmationToEmail\": \"something@email.com\",\n \"HTMLContent\": \"Some HTML body\",\n \"MailingLists\": [\n {\n \"MailingListID\": \"adaf2fe1-55db-42dc-aaf8-56d8f502138d\",\n \"SegmentID\": \"10166\"\n },\n {\n \"MailingListID\": \"dce99b7a-2619-4805-aaeb-7fecdcb3c71b\"\n }\n ],\n \"IsAB\": \"true\",\n \"ABCampaignType\": \"Content\",\n \"WebLocationB\": \"http://www.mysite.gr/newsletter/index\",\n \"HoursToTest\": \"2\",\n \"ListPercentage\": \"20\",\n \"ABWinnerSelectionType\": \"OpenRate\"\n}"
""".data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let response = response {
print(response)
if let data = data, let body = String(data: data, encoding: .utf8) {
print(body)
}
} else {
print(error ?? "Unknown error")
}
}
task.resume()