Skip to content

Latest commit

 

History

History
2634 lines (2476 loc) · 74.8 KB

_contacts_bulk.md

File metadata and controls

2634 lines (2476 loc) · 74.8 KB

Manage Contacts in bulk

Choose a resource

Manage list subscriptions for a single contact ( /contact/$ID/managecontactslists )

This resource allows you to add a single contact in several lists at once. More information

### Manage and upload multiple contacts ( /contact/managemanycontacts )

This resource allows you to add contacts in bulk in a JSON format. Optionally, these contacts can be added to existing lists. More information

### Manage multiple Contacts subscriptions to a list ( /contactslist/$ID/managemanycontacts )

This resource allows you to add contacts directly to a list. It will create new contacts if they are not already in the Mailjet system. More information

Manage Contacts through CSV upload

This process allows you to upload CSV files containing large quantities of contacts. More information

Subscriptions for a contact

<?php
/*
Create : Manage a contact subscription to a list
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'ContactsLists' => [
        [
            'ListID' => "$ListID_1",
            'Action' => "addnoforce"
        ],
        [
            'ListID' => "$ListID_2",
            'Action' => "addforce"
        ]
    ]
];
$response = $mj->post(Resources::$ContactManagecontactslists, ['id' => $id, 'body' => $body]);
$response->success() && var_dump($response->getData());
?>
# Create : Manage a contact subscription to a list
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contact/$ID/managecontactslists \
	-H 'Content-Type: application/json' \
	-d '{
		"ContactsLists":[
				{
						"ListID": "$ListID_1",
						"Action": "addnoforce"
				},
				{
						"ListID": "$ListID_2",
						"Action": "addforce"
				}
		]
	}'
/**
 *
 * Create : Manage a contact subscription to a list
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("contact")
	.id($ID)
	.action("managecontactslists")
	.request({
		"ContactsLists":[
				{
						"ListID": "$ListID_1",
						"Action": "addnoforce"
				},
				{
						"ListID": "$ListID_2",
						"Action": "addforce"
				}
		]
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# Create : Manage a contact subscription to a list
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Contact_managecontactslists.create(id: $ID, contacts_lists: [{
    'ListID'=> '$ListID_1',
    'Action'=> 'addnoforce'
}, {
    'ListID'=> '$ListID_2',
    'Action'=> 'addforce'
}]
)
p variable.attributes['Data']
"""
Create : Manage a contact subscription to a list
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
id = '$ID'
data = {
  'ContactsLists': [
				{
						"ListID": "$ListID_1",
						"Action": "addnoforce"
				},
				{
						"ListID": "$ListID_2",
						"Action": "addforce"
				}
		]
}
result = mailjet.contact_managecontactslists.create(id=id, data=data)
print result.status_code
print result.json()
/*
Create : Manage a contact subscription to a list
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.ContactManagecontactslists
	mr := &Request{
	  Resource: "contact",
	  ID: RESOURCE_ID,
	  Action: "managecontactslists",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.ContactManagecontactslists {
      ContactsLists: []MailjetContactsList {
        MailjetContactsList {
          ListID: "$ListID_1",
          Action: "addnoforce",
        },
        MailjetContactsList {
          ListID: "$ListID_2",
          Action: "addforce",
        },
      },
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.ContactManagecontactslists;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * Create : Manage a contact subscription to a list
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(ContactManagecontactslists.resource, ID)
			.property(ContactManagecontactslists.CONTACTSLISTS, new JSONArray()
                .put(new JSONObject()
                    .put("ListID", "$ListID_1")
                    .put("Action", "addnoforce"))
                .put(new JSONObject()
                    .put("ListID", "$ListID_2")
                    .put("Action", "addforce")));
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// Create : Manage a contact subscription to a list
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = ContactManagecontactslists.Resource,
            ResourceId = ResourceId.Numeric(ID)
         }
            .Property(ContactManagecontactslists.ContactsLists, new JArray {
                new JObject {
                 {"ListID", "$ListID_1"},
                 {"Action", "addnoforce"}
                 },
                new JObject {
                 {"ListID", "$ListID_2"},
                 {"Action", "addforce"}
                 }
                });
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response:

{
	"Count": 1,
	"Data": [
		{ 
			"ContactsLists" : [
				{ 
					"Action" : "addnoforce", 
					"ListID" : "$ListID_1" 
				}, 
				{ 
					"Action" : "addforce", 
					"ListID" : "$ListID_2"
				}
			] 
		}
	],
	"Total": 1
}

To manage a Contact subscription for one or multiple Lists, we can do a POST on /contact/$ID/managecontactslists, specifying the contact ID in the URL and adding JSON to the body of the request with the list subscriptions to be modified.

'Action' is mandatory and can be one of the following values:

Actions
addforce string
adds the contact and resets the unsub status to false
addnoforce string
adds the contact and does not change the subscription status of the contact
remove string
removes the contact from the list
unsub string
unsubscribes a contact from the list
```json { "ErrorInfo": "", "ErrorMessage": { "ContactsLists": [ { "ListID": "original_list_id", "Action": "original_string_action", "Error": "errorstring" } ] }, "StatusCode": 400 }

For this API call, there is one specific <code>HTTP 400 status</code> error condition that is worth noting:
<ul>
	<li><code>400 Object properties invalid</code>: The ID of the Contact List is missing / invalid.
</ul>

<p>
	A detailed description of the error will be sent in a standard API error payload: <br />

	The <code>errorpayload</code> will contain the following JSON detailing each property error in the original JSON payload. Only the properties having an error will be listed. <br /><br />
	<br>
	The possible <code>errorstring</code> are:
	</p>
	<ul>
		<li>listID missing or not valid</li>
		<li>action missing or not valid</li>
	</ul>

### Retrieve the lists a contact is part of

```shell
# View : Lists a contact belong to
curl -s \
	-X GET \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contact/$ID/getcontactslists 
<?php
/*
View : Lists a contact belong to
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$ContactGetcontactslists, ['id' => $id]);
$response->success() && var_dump($response->getData());
?>
/**
 *
 * View : Lists a contact belong to
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.get("contact")
	.id($ID)
	.action("getcontactslists")
	.request()
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# View : Lists a contact belong to
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Contact_getcontactslists.find($ID)
p variable.attributes['Data']
"""
View : Lists a contact belong to
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
id = '$ID'
result = mailjet.contact_getcontactslists.get(id=id)
print result.status_code
print result.json()
/*
View : Lists a contact belong to
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.ContactGetcontactslists
	mr := &Request{
	  Resource: "contact",
	  ID: RESOURCE_ID,
	  Action: "getcontactslists",
	}
	err := mailjetClient.Get(mr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.ContactGetcontactslists;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * View : Lists a contact belong to
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(ContactGetcontactslists.resource, ID);
      response = client.get(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// View : Lists a contact belong to
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = ContactGetcontactslists.Resource,
            ResourceId = ResourceId.Numeric(ID)
         }
         MailjetResponse response = await client.GetAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

To get information on all lists a specific contact belongs to, do a GET on /contact/{contact_ID}/getcontactslists. You can use either the ContactID or the email address.

API Response

{
	"Count": 1,
	"Data": [
		{
			"IsActive": "true",
			"IsUnsub": "false",
			"ListID": "1",
			"SubscribedAt": "2019-01-01T00:00:00Z"
		}
	],
	"Total": 1
}

The response will include the List ID, the contact's subscription status, as well as the time when this contact was subscribed to this list.

Manage multiple contacts

<?php
/*
Create : Manage the details of a Contact.
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'ContactsLists' => [
        [
            'ListID' => 1,
            'action' => "addnoforce"
        ],
        [
            'ListID' => 2,
            'action' => "addforce"
        ]
    ],
    'Contacts' => [
        [
            'Email' => "jimsmith@example.com",
            'Name' => "Jim",
            'Properties' => [
                'Property1' => "value",
                'Property2' => "value2"
            ]
        ],
        [
            'Email' => "janetdoe@example.com",
            'Name' => "Janet",
            'Properties' => [
                'Property1' => "value",
                'Property2' => "value2"
            ]
        ]
    ]
];
$response = $mj->post(Resources::$ContactManagemanycontacts, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
# Create : Manage the details of a Contact.
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contact/managemanycontacts \
	-H 'Content-Type: application/json' \
	-d '{
		"ContactsLists":[
				{
						"ListID": 1,
						"action": "addnoforce"
				},
				{
						"ListID": 2,
						"action": "addforce"
				}
		],
		"Contacts":[
				{
						"Email": "jimsmith@example.com",
						"Name": "Jim",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				},
				{
						"Email": "janetdoe@example.com",
						"Name": "Janet",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				}
		]
	}'
/**
 *
 * Create : Manage the details of a Contact.
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("contact")
	.action("managemanycontacts")
	.request({
		"ContactsLists":[
				{
						"ListID": 1,
						"action": "addnoforce"
				},
				{
						"ListID": 2,
						"action": "addforce"
				}
		],
		"Contacts":[
				{
						"Email": "jimsmith@example.com",
						"Name": "Jim",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				},
				{
						"Email": "janetdoe@example.com",
						"Name": "Janet",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				}
		]
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# Create : Manage the details of a Contact.
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Contact_managemanycontacts.create(contacts_lists: [{
    'ListID'=> 1,
    'action'=> 'addnoforce'
}, {
    'ListID'=> 2,
    'action'=> 'addforce'
}],
contacts: [{
    'Email'=> 'jimsmith@example.com',
    'Name'=> 'Jim',
    'Properties'=> {
        'Property1'=> 'value',
        'Property2'=> 'value2'
    }
}, {
    'Email'=> 'janetdoe@example.com',
    'Name'=> 'Janet',
    'Properties'=> {
        'Property1'=> 'value',
        'Property2'=> 'value2'
    }
}]
)
p variable.attributes['Data']
"""
Create : Manage the details of a Contact.
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
data = {
  'ContactsLists': [
				{
						"ListID": 1,
						"action": "addnoforce"
				},
				{
						"ListID": 2,
						"action": "addforce"
				}
		],
  'Contacts': [
				{
						"Email": "jimsmith@example.com",
						"Name": "Jim",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				},
				{
						"Email": "janetdoe@example.com",
						"Name": "Janet",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				}
		]
}
result = mailjet.contact_managemanycontacts.create(data=data)
print result.status_code
print result.json()
/*
Create : Manage the details of a Contact.
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.ContactManagemanycontacts
	mr := &Request{
	  Resource: "contact",
	  Action: "managemanycontacts",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.ContactManagemanycontacts {
      ContactsLists: []MailjetContactsList {
        MailjetContactsList {
          ListID: 1,
          Action: "addnoforce",
        },
        MailjetContactsList {
          ListID: 2,
          Action: "addforce",
        },
      },
      Contacts: []MailjetContact {
        MailjetContact {
          Email: "jimsmith@example.com",
          Name: "Jim",
          Properties: MyPropertiesStruct {
            Property1: "value",
            Property2: "value2",
          },
        },
        MailjetContact {
          Email: "janetdoe@example.com",
          Name: "Janet",
          Properties: MyPropertiesStruct {
            Property1: "value",
            Property2: "value2",
          },
        },
      },
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.ContactManagemanycontacts;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * Create : Manage the details of a Contact.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(ContactManagemanycontacts.resource)
			.property(ContactManagemanycontacts.CONTACTSLISTS, new JSONArray()
                .put(new JSONObject()
                    .put("ListID", "1")
                    .put("action", "addnoforce"))
                .put(new JSONObject()
                    .put("ListID", "2")
                    .put("action", "addforce")))
			.property(ContactManagemanycontacts.CONTACTS, new JSONArray()
                .put(new JSONObject()
                    .put("Email", "jimsmith@example.com")
                    .put("Name", "Jim")
                    .put("Properties", new JSONObject()
                        .put("Property1", "value")
                        .put("Property2", "value2")))
                .put(new JSONObject()
                    .put("Email", "janetdoe@example.com")
                    .put("Name", "Janet")
                    .put("Properties", new JSONObject()
                        .put("Property1", "value")
                        .put("Property2", "value2"))));
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// Create : Manage the details of a Contact.
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = ContactManagemanycontacts.Resource,
         }
            .Property(ContactManagemanycontacts.ContactsLists, new JArray {
                new JObject {
                 {"ListID", 1},
                 {"action", "addnoforce"}
                 },
                new JObject {
                 {"ListID", 2},
                 {"action", "addforce"}
                 }
                })
            .Property(ContactManagemanycontacts.Contacts, new JArray {
                new JObject {
                 {"Email", "jimsmith@example.com"},
                 {"Name", "Jim"},
                 {"Properties", new JObject {
                  {"Property1", "value"},
                  {"Property2", "value2"}
                  }}
                 },
                new JObject {
                 {"Email", "janetdoe@example.com"},
                 {"Name", "Janet"},
                 {"Properties", new JObject {
                  {"Property1", "value"},
                  {"Property2", "value2"}
                  }}
                 }
                });
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

Uploading multiple contacts, with the option to manage their subscriptions to a Contact List or multiple lists, if required, can be done with a POST on the /contact/managemanycontacts resource. This resource is asynchronous and will return a JobID allowing you to monitor the process.

Email is the only mandatory property in Contacts.

If you are specifying Properties for a contact, please note that these properties must already be defined with the /contactmetadata resource. The properties specified can only be static in this resource.

If a contact (uniquely identified by the email) has already been added, multiple entries or subsequent uploads will not add duplicate entries in neither the contacts and list subscription. The Properties and Name of the contact will be updated with any modified values.

To unassign custom contact data for a specific contact, set the value of the contact property to null.

ContactsLists in this POST is not mandatory. You can upload multiple contacts without adding them to a list. The field Action in ContactsLists can have the following values:

Actions
addforce string
adds the contact and re-subscribes the contact to the list
addnoforce string
adds the contact and does not change the subscription status of the contact
remove string
removes the contact from the list
unsub string
unsubscribes the contact from the list

API response:

{
   "Count": 1,
   "Data": [
      {
         "JobID": 35800
      }
   ],
   "Total": 1
}

A successful call will return JSON in the following format, containing the JobID allowing to monitor the processing :

### Monitor the upload of multiple contacts
<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$ContactManagemanycontacts, ['actionID' => $id]);
$response->success() && var_dump($response->getData());
?>
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.ContactManagemanycontacts;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * View : Manage the details of a Contact.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(ContactManagemanycontacts.resource, 'actionid')
      response = client.get(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
result = mailjet.contact_managemanycontacts.get(action_id='$JOBID')
# View : Job information
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']
end
variable = Mailjet::Contact_managemanycontacts.find($JOBID)
# View: Job information
curl -s \
	-X GET \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contact/managemanycontacts/$JOBID
/**
 *
 * View: Job information
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.get("contact")
	.action('managemanycontacts')
	.id($JOBID)
	.request()
request
  .then(result => {
    console.log(result.body)
  })
  .catch(error => {
    console.log(error.statusCode)
  })
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// View: Job information.
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = ContactManagemanycontacts.Resource,
            ActionId = $JOBID
         };
         MailjetResponse response = await client.GetAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response:

{
   "Count": 1,
   "Data": [
      {
         "Status": "string",
         "JobStart": "timestamp",
         "JobEnd": "timestamp",
         "Count": "integer",
         "Error": "string",
         "ErrorFile": "string"
      }
   ],
   "Total": 1
}

After the POST on /contact/managemanycontacts, we can follow with a GET, this time including the JobID

This provides the following information:

  • Status: This can be one of the following:
  • Allocated: the job is in the queue
  • Upload: The data is in the upload phase
  • Prepare: The data is being formatted to be added to the list
  • Importing: Data is being added to the Contact List
  • Completed: Addition to the Contact List complete
  • Error: Declares an error
  • Abort: For cancelled jobs.
  • JobStart: Time of job start
  • JobEnd: Time of job end
  • Count: Represents the number of contacts already processed by the background job
  • Error: If the status equals 'error', contains error information from the batch job
  • ErrorFile: Contains the URL to the Error information file

Recovering error file

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$BatchjobJsonerror, ['id' => $JobID]);
$response->success() && var_dump($response->getBody());
?>
/**
* Not available in Java , please refer to Curl
*/
"""
Not available in Python, please refer to Curl
"""
# Not available in Ruby, please refer to Curl
curl -s \
	-X GET \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/DATA/batchjob/$JOBID/JSONError/application:json/LAST
/**
 *
 * Not available in Node, please refer to Curl
 *
 */
/*
Not available in Go, please refer to Curl
*/

Manage contacts in a list

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'Action' => "addnoforce",
    'Contacts' => [
        [
            'Email' => "jimsmith@example.com",
            'Name' => "Jim",
            'Properties' => [
                'Property1' => "value",
                'Property2' => "value2"
            ]
        ],
        [
            'Email' => "janetdoe@example.com",
            'Name' => "Janet",
            'Properties' => [
                'Property1' => "value",
                'Property2' => "value2"
            ]
        ]
    ]
];
$response = $mj->post(Resources::$ContactslistManagemanycontacts, ['id' => $id, 'body' => $body]);
$response->success() && var_dump($response->getData());
?>
# Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contactslist/$ID/ManageManyContacts \
	-H 'Content-Type: application/json' \
	-d '{
		"Action":"addnoforce",
		"Contacts":[
				{
						"Email": "jimsmith@example.com",
						"Name": "Jim",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				},
				{
						"Email": "janetdoe@example.com",
						"Name": "Janet",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				}
		]
	}'
/**
 *
 * Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("contactslist")
	.id($ID)
	.action("ManageManyContacts")
	.request({
		"Action":"addnoforce",
		"Contacts":[
				{
						"Email": "jimsmith@example.com",
						"Name": "Jim",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				},
				{
						"Email": "janetdoe@example.com",
						"Name": "Janet",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				}
		]
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']
  config.default_from = 'your default sending address'
end
variable = Mailjet::Contactslist_managemanycontacts.create(id: $ID, , action: "addnoforce",contacts: [{ 'Email'=> 'jimsmith@example.com', 'Name'=> 'Jim', 'Properties'=> { 'Property1'=> 'value', 'Property2'=> 'value2' }}, { 'Email'=> 'janetdoe@example.com', 'Name'=> 'Janet', 'Properties'=> { 'Property1'=> 'value', 'Property2'=> 'value2' }}])
"""
Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
id = '$ID'
data = {
  'Action': 'addnoforce',
  'Contacts': [
				{
						"Email": "jimsmith@example.com",
						"Name": "Jim",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				},
				{
						"Email": "janetdoe@example.com",
						"Name": "Janet",
						"Properties": {
								"Property1": "value",
								"Property2": "value2"
						}
				}
		]
}
result = mailjet.contactslist_ManageManyContacts.create(id=id, data=data)
print result.status_code
print result.json()
/*
Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
*/
package main
import (
	"fmt"
	. "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
	"os"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.ContactslistManageManyContacts
	mr := &Request{
	  Resource: "contactslist",
	  ID: RESOURCE_ID,
	  Action: "ManageManyContacts",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.ContactslistManageManyContacts {
      Action: "addnoforce",
      Contacts: []MailjetContact {
        MailjetContact {
          Email: "jimsmith@example.com",
          Name: "Jim",
          Properties: MyPropertiesStruct {
            Property1: "value",
            Property2: "value2",
          },
        },
        MailjetContact {
          Email: "janetdoe@example.com",
          Name: "Janet",
          Properties: MyPropertiesStruct {
            Property1: "value",
            Property2: "value2",
          },
        },
      },
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.ContactslistManagemanycontacts;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(ContactslistManagemanycontacts.resource, ID)
						.property(ContactslistManagemanycontacts.ACTION, "addnoforce")
						.property(ContactslistManagemanycontacts.CONTACTS, new JSONArray()
                                                                .put(new JSONObject()
                                                                    .put("Email", "jimsmith@example.com")
                                                                    .put("Name", "Jim")
                                                                    .put("Properties", new JSONObject()
                                                                        .put("Property1", "value")
                                                                        .put("Property2", "value2")))
                                                                .put(new JSONObject()
                                                                    .put("Email", "janetdoe@example.com")
                                                                    .put("Name", "Janet")
                                                                    .put("Properties", new JSONObject()
                                                                        .put("Property1", "value")
                                                                        .put("Property2", "value2"))));
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// Create : Manage your contact lists. One Contact might be associated to one or more ContactsList.
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = ContactslistManagemanycontacts.Resource,
            ResourceId = ResourceId.Numeric(ID)
         }
            .Property(ContactslistManagemanycontacts.Action, "addnoforce")
            .Property(ContactslistManagemanycontacts.Contacts, new JArray {
	       new JObject {
	          {"Email", "jimsmith@example.com"},
	          {"Name", "Jim"},
	          {"Properties", new JObject {
	             {"Property1", "value"},
	             {"Property2", "value2"}
	             }
                  }
	       },
	       new JObject {
	          {"Email", "janetdoe@example.com"},
	          {"Name", "Janet"},
	          {"Properties", new JObject {
	             {"Property1", "value"},
	             {"Property2", "value2"}
	             }
                  }
	       }
            });
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response:

{
   "Count": 1,
   "Data": [
      {
         "JobID": 35800
      }
   ],
   "Total": 1
}

Multiple contacts, in JSON format, can be uploaded with a POST using the /contactslist/$ID/managemanycontacts action. This resource is asynchronous and will return a JobID allowing you to monitor the process. This is the perfect method to easily add a large quantity of contacts to a list.

The field Email in Contacts is the key for the contact and is mandatory, as is Action. Action can have one of the following values:

Actions
addforce string
adds the contact and re-subscribes the contact to the list
addnoforce string
adds the contact and does not change the subscription status of the contact
remove string
removes the contact from the List
unsub string
unsubscribes the contact from the List

If you are specifying Properties for a contact, please note that these properties must already be defined with the /contactmetadata resource. The properties specified can only be static in this resource. To unassign custom contact data for a specific contact, set the value of the contact property to null.

If a contact (uniquely identified by the email) has already been added to your contacts or a list, multiple entries or subsequent uploads will not add duplicate entries in either the contacts or list subscription. The Properties and Name of the contact will be updated with any modified values.

Monitor the upload of multiple contacts

<?php
// View: Job information
require 'vendor/autoload.php';
$mj = new Mailjet($MJ_APIKEY_PUBLIC,$MJ_APIKEY_PRIVATE);
$result = $mj->get(Resources::$ContactslistManagemanycontacts, ['id' => $id, 'actionid' => $actionId]);
var_dump($result->getData());
?>
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.Contactslist;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * Create : only need a Name
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(ContactslistManagemanycontacts.resource, 'id', 'jobid');
      response = client.get(request);
      System.out.println(response.getData());
    }
}
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
result = mailjet.contactslist_managemanycontacts.get(id='$ID', actionid='$JOBID')
# View: Job information
curl -s \
	-X GET \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/contactslist/$ID/ManageManyContacts/$JOBID
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']
end
variable = Mailjet::Contactslist_managemanycontacts.find($ID, $JOBID)
/**
 *
 * View: Job information
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.get("contact")
	.id($ID)
	.action('managemanycontacts')
	.id($JOBID)
	.request()
request
  .then(result => {
    console.log(result.body)
  })
  .catch(error => {
    console.log(error.statusCode)
  })
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
   /// <summary>
   /// View: Job information.
   /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = ContactslistManagemanycontacts.Resource,
            ResourceId = $ID,
            ActionId = $JOBID
         };
         MailjetResponse response = await client.GetAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response:

{
   "Count": 1,
   "Data": [
      {
         "Status": "string",
         "JobStart": "timestamp",
         "JobEnd": "timestamp",
         "Count": "integer",
         "Error": "string",
         "ErrorFile": "string"
      }
   ],
   "Total": 1
}

After the POST on /contactslist/$ID/managemanycontacts, we can follow with a GET, this time including the JobID

This provides the following information:

  • Status: This can be one of the following:
  • Allocated: the job is in the queue
  • Upload: The data is in the upload phase
  • Prepare: The data is being formatted to be added to the list
  • Importing: Data is being added to the Contact List
  • Completed: Addition to the Contact List complete
  • Error: Declares an error
  • Abort: For cancelled jobs.
  • JobStart: Time of job start
  • JobEnd: Time of job end
  • Count: Represents the number of contacts already processed by the background job
  • Error: If the status equals 'error', contains error information from the batch job
  • ErrorFile: Contains the URL to the Error information file

Recovering error file

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$BatchjobJsonerror, ['id' => $JobID]);
$response->success() && var_dump($response->getBody());
?>
/**
* Not available in Java , please refer to Curl
*/
"""
Not available in Python, please refer to Curl
"""
# Not available in Ruby, please refer to Curl
curl -s \
	-X GET \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/DATA/batchjob/$JOBID/JSONError/application:json/LAST
/**
 *
 * Not available in Node, please refer to Curl
 *
 */
/*
Not available in Go, please refer to Curl
*/

Contacts CSV upload

In some cases you might need to manage large quantities of contacts stored into a CSV record in relation to a contactslist.

With the following process, you will be able to fully manage your contacts and their relationship with a contact list (ie: adding, removing or unsubscribing)

Please note that these steps represent a single process. Don't execute each step independently but rather as a whole.

CSV file structure

"email","age"
"foo@example.org",42
"bar@example.com",13
"sam@ple.co.uk",37

The structure for the CSV file should be as follows:

You can define Custom Contact Data in the CSV. Visit our Contact Personalization Guide for more information about defining Custom Contact Data. If you are using undefined contact properties, Mailjet will automatically create /contactmetadata in the next step of the process.

With this process it is not possible to populate the Contact Name property. If you specify a "name" it will create a new /contactmetadata and /contactdata as explained above. The email should be unique in the file and will be the key to reconcile this list with your existing contact in Mailjet system.

CSV file structure with contact data of type datetime

"foo@example.org",2018/10/12
"bar@example.com",2016/10/12
"sam@ple.co.uk",2017/10/12

When creating a CSV file, which contains contact properties with type datetime, you have to omit the first row of the csv, which defines the names of the contact properties in the CSV file. These contact properties are added in dedicated field - ImportOptions. See here for details.

Data Upload

from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
f = open('./data.csv')
result = mailjet.contactslist_csvdata.create(id='$ID_CONTACTLIST', data=f.read())
print result.status_code
print result.json()
package com.my.project;

import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.resource.Contactslist;

import java.io.File;

public class MyClass {
	/**
	 * A wrapper for the CSV upload
	 */
	public static void main(String[] args) throws MailjetException {
		ClientOptions clientOptions;
		MailjetClient client;
		MailjetRequest request;
		MailjetResponse response;

		clientOptions = ClientOptions
				.builder()
				.apiKey(System.getenv("MJ_APIKEY_PUBLIC"))
				.apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE"))
				.build();
		client = new MailjetClient(clientOptions);
		request = new MailjetRequest(Contactslist.csvDataResource, CONTACT_LIST_ID)
				.attachFile(new File("/test.csv"));
		response = client.post(request);

		System.out.println(response.getStatus());
		System.out.println(response.getData());
	}
}
<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
// View: CSV upload
$CSVContent = file_get_contents('./test.csv');
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->post(Resources::$ContactslistCsvdata, ['body' => $CSVContent, 'id' => $ID_CONTACTLIST]);
$response->success() && var_dump($response->getData());
?>
# Upload the CSV file through the DATA API
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3/DATA/contactslist/$ID_CONTACTLIST/CSVData/text:plain \
-H "Content-Type: text/plain" \
--data-binary "@./test.csv"
# unsupported at the moment, please refer to cURL
const fs = require ('fs')
const mailjet = require ('node-mailjet')
    .connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
fs.readFile('./data.csv', (err, data) => {
  if (err) { return console.error(err) }
  const request = mailjet.post('contactslist')
      .id("$ID_CONTACTLIST")
      .action('csvdata')
      .request(data);
  request
  .then(result => {
    console.log(result.body)
  })
  .catch(error => {
    console.log(error.statusCode)
  })
})
package main
import (
    "fmt"
    "io/ioutil"
    . "github.com/mailjet/mailjet-apiv3-go/v4"
    "os"
)
func check(e error) {
    if e != nil {
        panic(e)
    }
}
func main () {
    dat, err := ioutil.ReadFile("./data.csv")
    check(err)
    mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
    type MyStruct struct {
	   ID int
    }
    var data = new(MyStruct)
    mr := &DataRequest{
      SourceType: "contactslist",
      SourceTypeID: "$ID_CONTACTLIST",
      DataType: "CSVData",
      MimeType: "text:plain",
    }
    fmr := &FullDataRequest{
      Info: mr,
      Payload: string(dat),
    }
    err1 := mailjetClient.PostData(fmr, &data)
    if err1 != nil {
      fmt.Println(err1)
    }
    fmt.Printf("Data array: %+v\n", data)
}
# unsupported at the moment, please refer to cURL

API response:

{
   "ID": 57
}

The first step is to upload the CSV data to the server. You need to specify the wanted contactslist ID and, of course, the csv_content.

Add the contacts and subscriptions to the contact list

<?php
/*
Create: A wrapper for the CSV importer
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'ContactsListID' => "$ID_CONTACTLIST",
    'DataID' => "$ID_DATA",
    'Method' => "addnoforce"
];
$response = $mj->post(Resources::$Csvimport, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
# Create: A wrapper for the CSV importer
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/csvimport \
	-H 'Content-Type: application/json' \
	-d '{
		"ContactsListID":"$ID_CONTACTLIST",
		"DataID":"$ID_DATA",
		"Method":"addnoforce"
	}'
/**
 *
 * Create: A wrapper for the CSV importer
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("csvimport")
	.request({
		"ContactsListID":"$ID_CONTACTLIST",
		"DataID":"$ID_DATA",
		"Method":"addnoforce"
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# Create: A wrapper for the CSV importer
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Csvimport.create(contacts_list_id: "$ID_CONTACTLIST",
data_id: "$ID_DATA",
method: "addnoforce"
)
p variable.attributes['Data']
"""
Create: A wrapper for the CSV importer
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
data = {
  'ContactsListID': '$ID_CONTACTLIST',
  'DataID': '$ID_DATA',
  'Method': 'addnoforce'
}
result = mailjet.csvimport.create(data=data)
print result.status_code
print result.json()
/*
Create: A wrapper for the CSV importer
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Csvimport
	mr := &Request{
	  Resource: "csvimport",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.Csvimport {
      ContactsListID: "$ID_CONTACTLIST",
      DataID: "$ID_DATA",
      Method: "addnoforce",
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;

import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.resource.Csvimport;

public class MyClass {
	/**
	 * Create: A wrapper for the CSV importer
	 */
	public static void main(String[] args) throws MailjetException {
		ClientOptions clientOptions;
		MailjetClient client;
		MailjetRequest request;
		MailjetResponse response;

		clientOptions = ClientOptions
				.builder()
				.apiKey(System.getenv("MJ_APIKEY_PUBLIC"))
				.apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE"))
				.build();
		client = new MailjetClient(clientOptions);
		request = new MailjetRequest(Csvimport.resource)
				.property(Csvimport.CONTACTSLISTID, CONTACT_LIST_ID)
				.property(Csvimport.DATAID, DATA_ID)
				.property(Csvimport.METHOD, "addnoforce");
		response = client.post(request);
		System.out.println(response.getStatus());
		System.out.println(response.getData());
	}
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// Create: A wrapper for the CSV importer
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = Csvimport.Resource,
         }
            .Property(Csvimport.ContactsListID, "$ID_CONTACTLIST")
            .Property(Csvimport.DataID, "$ID_DATA")
            .Property(Csvimport.Method, "addnoforce");
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response:

{
	"Count": 1,
	"Data": [
		{
			"AliveAt": "",
			"ContactsListID": "",
			"Count": "1",
			"Current": "",
			"DataID": "",
			"Errcount": "0",
			"ErrTreshold": "",
			"ID": "",
			"ImportOptions": "",
			"JobEnd": "",
			"JobStart": "",
			"Method": "",
			"RequestAt": "",
			"Status": "Upload"
		}
	],
	"Total": 1
}

Now, the uploaded data needs to be assigned to the given contactslist resource.

Method's possible values are:

Actions
addforce string
adds the contact and resets the unsub status to false
addnoforce string
adds the contact and does not change the subscription status of the contact
remove string
removes the contact from the List
unsub string
unsubscribes a contact from the List

Add contacts with contact data of type datetime

<?php
/*
Create: A wrapper for the CSV importer
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$body = [
    'ContactsListID' => "$ID_CONTACTLIST",
    'DataID' => "$ID_DATA",
    'Method' => "addnoforce",
    'ImportOptions' => "{\\"DateTimeFormat\\": \\"yyyy/mm/dd\\",\\"TimezoneOffset\\": 2,\\"FieldNames\\": [\\"email\\",\\"birthday\\"]}"
];
$response = $mj->post(Resources::$Csvimport, ['body' => $body]);
$response->success() && var_dump($response->getData());
?>
# Create: A wrapper for the CSV importer
curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/csvimport \
	-H 'Content-Type: application/json' \
	-d '{
		"ContactsListID":"$ID_CONTACTLIST",
		"DataID":"$ID_DATA",
		"Method":"addnoforce",
		"ImportOptions":"{\"DateTimeFormat\": \"yyyy/mm/dd\",\"TimezoneOffset\": 2,\"FieldNames\": [\"email\",\"birthday\"]}"
	}'
/**
 *
 * Create: A wrapper for the CSV importer
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.post("csvimport")
	.request({
		"ContactsListID":"$ID_CONTACTLIST",
		"DataID":"$ID_DATA",
		"Method":"addnoforce",
		"ImportOptions":"{\"DateTimeFormat\": \"yyyy/mm/dd\",\"TimezoneOffset\": 2,\"FieldNames\": [\"email\",\"birthday\"]}"
	})
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# Create: A wrapper for the CSV importer
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Csvimport.create(contacts_list_id: "$ID_CONTACTLIST",
data_id: "$ID_DATA",
method: "addnoforce",
import_options: "{\"DateTimeFormat\": \"yyyy/mm/dd\",\"TimezoneOffset\": 2,\"FieldNames\": [\"email\",\"birthday\"]}"
)
p variable.attributes['Data']
"""
Create: A wrapper for the CSV importer
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
data = {
  'ContactsListID': '$ID_CONTACTLIST',
  'DataID': '$ID_DATA',
  'Method': 'addnoforce',
  'ImportOptions': '{\"DateTimeFormat\": \"yyyy/mm/dd\",\"TimezoneOffset\": 2,\"FieldNames\": [\"email\",\"birthday\"]}'
}
result = mailjet.csvimport.create(data=data)
print result.status_code
print result.json()
/*
Create: A wrapper for the CSV importer
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Csvimport
	mr := &Request{
	  Resource: "csvimport",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.Csvimport {
      ContactsListID: "$ID_CONTACTLIST",
      DataID: "$ID_DATA",
      Method: "addnoforce",
    ImportOptions: "{\"DateTimeFormat\": \"yyyy/mm/dd\",\"TimezoneOffset\": 2,\"FieldNames\": [\"email\",\"birthday\"]}",
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.Csvimport;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * Create: A wrapper for the CSV importer
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(Csvimport.resource)
			.property(Csvimport.CONTACTSLISTID, "$ID_CONTACTLIST")
			.property(Csvimport.DATAID, "$ID_DATA")
			.property(Csvimport.METHOD, "addnoforce")
			.property(Csvimport.IMPORTOPTIONS, "{\\"DateTimeFormat\\": \\"yyyy/mm/dd\\",\\"TimezoneOffset\\": 2,\\"FieldNames\\": [\\"email\\",\\"birthday\\"]}");
      response = client.post(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// Create: A wrapper for the CSV importer
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = Csvimport.Resource,
         }
            .Property(Csvimport.ContactsListID, "$ID_CONTACTLIST")
            .Property(Csvimport.DataID, "$ID_DATA")
            .Property(Csvimport.Method, "addnoforce")
            .Property(Csvimport.ImportOptions, "{\\"DateTimeFormat\\": \\"yyyy/mm/dd\\",\\"TimezoneOffset\\": 2,\\"FieldNames\\": [\\"email\\",\\"birthday\\"]}");
         MailjetResponse response = await client.PostAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response

{
	"Count": 1,
	"Data": [
		{
			"AliveAt": "",
			"ContactsList": "",
			"Count": "",
			"Current": "",
			"DataID": "",
			"Errcount": "",
			"ErrTreshold": "",
			"ID": "",
			"ImportOptions": "",
			"JobEnd": "",
			"JobStart": "",
			"Method": "",
			"RequestAt": "",
			"Status": ""
		}
	],
	"Total": 1
}

When using contact data with type datetime, you should define an additional property - ImportOptions. Its value should be passed as a string, containing the following options:

  • DateTimeFormat - it shows the format of the datetime in the CSV file. It can be represented as any combination of the acronyms for year (yy), month (mm), day (dd), hour (hh), minute (nn), second (ss). The date is separated from the time with an empty space. The separators for the dates could be a dash(-), slash (>/) or dot (.). The separator for the time is a colon (:). The RFC3339 format is also supported (e.g. 'yyyy-mm-ddThh:nn:ss+01:00').
  • TimezoneOffset - used to select timezone offset. The value is integer in the range from -12 to 12.
  • FieldNames - specifies the names of the fields that are going to be imported. This corresponds to the first row of the CSV, when you import contacts without datetime contact data. All properties that will be modified should be added to the import options, following the exact same order as the columns in the CSV.

Monitor the process

<?php
/*
View: CSV upload Batch job running on the Mailjet infrastructure.
*/
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$Csvimport, ['id' => $id]);
$response->success() && var_dump($response->getData());
?>
# View: CSV upload Batch job running on the Mailjet infrastructure.
curl -s \
	-X GET \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3/REST/csvimport/$ID_JOB 
/**
 *
 * View: CSV upload Batch job running on the Mailjet infrastructure.
 *
 */
const mailjet = require ('node-mailjet')
	.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
const request = mailjet
	.get("csvimport")
	.id($ID_JOB)
	.request()
request
	.then((result) => {
		console.log(result.body)
	})
	.catch((err) => {
		console.log(err.statusCode)
	})
# View: CSV upload Batch job running on the Mailjet infrastructure.
require 'mailjet'
Mailjet.configure do |config|
  config.api_key = ENV['MJ_APIKEY_PUBLIC']
  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  
end
variable = Mailjet::Csvimport.find($ID_JOB)
p variable.attributes['Data']
"""
View: CSV upload Batch job running on the Mailjet infrastructure.
"""
from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
id = '$ID_JOB'
result = mailjet.csvimport.get(id=id)
print result.status_code
print result.json()
/*
View: CSV upload Batch job running on the Mailjet infrastructure.
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go/v4"
	"github.com/mailjet/mailjet-apiv3-go/v4/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Csvimport
	mr := &Request{
	  Resource: "csvimport",
	  ID: RESOURCE_ID,
	}
	err := mailjetClient.Get(mr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
package com.my.project;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.resource.Csvimport;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
    /**
     * View: CSV upload Batch job running on the Mailjet infrastructure.
     */
    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {
      MailjetClient client;
      MailjetRequest request;
      MailjetResponse response;
      client = new MailjetClient(System.getenv("MJ_APIKEY_PUBLIC"), System.getenv("MJ_APIKEY_PRIVATE"));
      request = new MailjetRequest(Csvimport.resource, ID);
      response = client.get(request);
      System.out.println(response.getStatus());
      System.out.println(response.getData());
    }
}
using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication
{
   class Program
   {
      /// <summary>
      /// View: CSV upload Batch job running on the Mailjet infrastructure.
      /// </summary>
      static void Main(string[] args)
      {
         RunAsync().Wait();
      }
      static async Task RunAsync()
      {
         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("MJ_APIKEY_PUBLIC"), Environment.GetEnvironmentVariable("MJ_APIKEY_PRIVATE"));
         MailjetRequest request = new MailjetRequest
         {
            Resource = Csvimport.Resource,
            ResourceId = ResourceId.Numeric(ID)
         }
         MailjetResponse response = await client.GetAsync(request);
         if (response.IsSuccessStatusCode)
         {
            Console.WriteLine(string.Format("Total: {0}, Count: {1}\n", response.GetTotal(), response.GetCount()));
            Console.WriteLine(response.GetData());
         }
         else
         {
            Console.WriteLine(string.Format("StatusCode: {0}\n", response.StatusCode));
            Console.WriteLine(string.Format("ErrorInfo: {0}\n", response.GetErrorInfo()));
            Console.WriteLine(response.GetData());
            Console.WriteLine(string.Format("ErrorMessage: {0}\n", response.GetErrorMessage()));
         }
      }
   }
}

API response:

{
	"Count": 1,
	"Data": [
		{
			"AliveAt": "",
			"ContactsList": "",
			"Count": "1",
			"Current": "",
			"DataID": "",
			"Errcount": "0",
			"ErrTreshold": "",
			"ID": "",
			"ImportOptions": "",
			"JobEnd": "",
			"JobStart": "",
			"Method": "",
			"RequestAt": "",
			"Status": "Completed"
		}
	],
	"Total": 1
}

You can now make sure the task completed successfully. You might need multiple checks as a huge amount of data may take some time to be processed (several hours are not uncommon). Using the job ID returned in the previous step, you can retrieve the job status

This provides the following information:
<ul>
	<li>Status: This can be one of the following:
		<ul>
		    <li>Prepare: The data is being formatted to be added to the list</li>
		    <li>Importing: Data is being added to the Contact List</li>
		    <li>Completed: Addition to the Contact List complete</li>
		    <li>Error: Declares an error</li>
		</ul>
	</li>
	<li>JobStart: Time of job start</li>
	<li>JobEnd: Time of job end</li>
	<li>Count: Represents the number of contacts already processed by the background job</li>
	<li>Errcount: contains the number of errors detected during the process, the Status can be "Completed" and have errors</li>
</ul>

Error handling

<?php
require 'vendor/autoload.php';
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));
$response = $mj->get(Resources::$BatchjobCsverror, ['id' => $job_id]);
$response->success() && var_dump($response->getBody());
?>
/**
* Not available in Java , please refer to Curl
*/
"""
Not available in Python, please refer to Curl
"""
# Not available in Ruby, please refer to Curl
curl --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3/DATA/BatchJob/$job_id/CSVError/text:csv
/**
 *
 * Not available in Node, please refer to Curl
 *
 */
/*
Not available in Go, please refer to Curl
*/

Using the job ID, you can retrieve the error file (if any, see Errcount number in the response of the monitoring of the job), through the DATA API. This error file will give you a textual reason for errors.

The returned file will be a copy of your original file with an added column describing the error for each line in error.

File uploaded with error :

"email","age"
"foo@example.org",42
"bar@example.com"
"sam@ple.co.uk",37

Error file content

email,age,error
"bar@example.com", ###Too few columns at line