{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/email-api/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition","tabs","tab"]},"type":"markdown"},"seo":{"title":"Manage contacts via CSV Upload","siteUrl":"https://dev.mailjet.com/","projectTitle":"Mailjet Developer Documentation","description":"Upload contacts in bulk to Mailjet using a CSV file: format the data, post it to the DATA API, then trigger an async import via /csvimport.","image":"https://dev.mailjet.com/og-image.png","lang":"en-US","keywords":["Mailjet API","Email API","Content API","SMTP Relay","transactional email","email delivery","Send API","email templates","developer documentation"],"meta":[{"name":"og:type","content":"website"},{"name":"og:site_name","content":"Mailjet Developer Documentation"},{"name":"twitter:card","content":"summary_large_image"},{"name":"robots","content":"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"},{"name":"googlebot","content":"index, follow, max-snippet:-1, max-image-preview:large"}],"jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://dev.mailjet.com/#organization","name":"Mailjet","alternateName":"Sinch Mailjet","url":"https://www.mailjet.com","logo":"https://assets.mailjet.com/lib/images/mailjetLogo/mj_logo_with_text_color.png","parentOrganization":{"@type":"Organization","name":"Sinch","url":"https://www.sinch.com"}},{"@type":"WebSite","@id":"https://dev.mailjet.com/#website","name":"Mailjet Developer Documentation","description":"Official developer documentation for the Mailjet Email API, Content API and SMTP Relay.","url":"https://dev.mailjet.com/","inLanguage":"en-US","publisher":{"@id":"https://dev.mailjet.com/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://dev.mailjet.com/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]},"llmstxt":{"hide":false,"title":"Mailjet Developer Documentation","description":"Developer documentation for the Mailjet Email API, Content API and SMTP Relay - guides, API references and code samples for sending, templating and tracking email at scale.","details":{"content":"Mailjet (part of Sinch) provides APIs for sending and managing email.\n\nThis documentation covers four main areas:\n\n- **Email API** - the Send API (v3 and v3.1) for transactional and marketing email,\n  plus contact management, segmentation, campaigns, statistics, webhooks, the Parse API\n  and the Mailjet Templating Language.\n- **Content API** - programmatic management of email templates, template contents,\n  images, labels and authentication tokens (v1).\n- **SMTP Relay** - sending through Mailjet's SMTP servers, including custom headers.\n- **API Reference** - the complete, generated reference for every endpoint, built directly\n  from the OpenAPI specifications.\n\nBase URL for all REST APIs: `https://api.mailjet.com`.\nAuthentication uses HTTP Basic auth with an API key and secret key.\n\n## Machine-readable entry points\n\nPrefer these when you need the API surface in as few requests as possible:\n\n- `/openapi/openapi-mailjet.md` - the **complete** Email API reference (every endpoint,\n  grouped by resource) as a single Markdown document.\n- `/openapi/openapi-passport.md` - the **complete** Content API reference as a single\n  Markdown document.\n- `/_bundle/openapi/openapi-mailjet.yaml` - the raw, fully bundled OpenAPI 3 description\n  of the Email API.\n- `/_bundle/openapi/openapi-passport.yaml` - the raw, fully bundled OpenAPI 3 description\n  of the Content API.\n- `/sitemap.xml` - every indexable URL on this site.\n\nEvery page on this site is also available as clean Markdown by appending `.md` to its URL."},"sections":[{"title":"Email API","description":"Sending, contacts, campaigns, statistics, webhooks and templating.","includeFiles":["docs/email-api/**/*.md"],"excludeFiles":[]},{"title":"Content API","description":"Manage templates, template contents, images, labels and tokens.","includeFiles":["docs/content-api/**/*.md","docs/content-api.md"],"excludeFiles":[]},{"title":"SMTP Relay","description":"Send email through Mailjet's SMTP servers.","includeFiles":["docs/smtp-relay/**/*.md"],"excludeFiles":[]},{"title":"API Reference","description":"Complete generated reference for every Mailjet API endpoint.","includeFiles":["openapi/openapi-mailjet.yaml","openapi/openapi-passport.yaml","docs/api-reference/**/*.md"],"excludeFiles":[]},{"title":"Migrating from Mandrill","description":"Guides for switching from Mandrill to Mailjet.","includeFiles":["docs/mandrill/**/*.md"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"manage-contacts-via-csv-upload","__idx":0},"children":["Manage contacts via CSV Upload"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"using-a-csv-file-to-upload","__idx":1},"children":["Using a CSV file to upload"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To do a CSV upload, you need to complete the following three steps:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Create the CSV content in a format compatible with the Mailjet API."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Upload the CSV content to a Mailjet server via an API call."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Import the CSV file using the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/csvimport"]}," content"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"csv-content-requirements","__idx":2},"children":["CSV content requirements"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The first row must include the names of the different properties included in the CSV - e.g. \"email\", \"first_name\", \"age\". If there is no ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/contactmetadata"]}," object with the respective property name, if will be created automatically by the API with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["DataType: string"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The data for each contact should be included on a new line."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"examples","__idx":3},"children":["Examples"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"\"email\",\"age\"\n\"foo@example.org\",42\n\"bar@example.com\",13\n\"sam@ple.co.uk\",37\n"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the CSV includes ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["datetime"]}," contact properties, you should NOT include the property names in the first row. Instead, they should be specified using the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ImportOptions"]}," property in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /csvimport"]}," payloa"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example","__idx":4},"children":["Example"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"\"foo@example.org\",2018/10/12\n\"bar@example.com\",2016/10/12\n\"sam@ple.co.uk\",2017/10/12\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"upload-the-csv","__idx":5},"children":["Upload the CSV"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To upload the CSV you need to specify the target contact list ID and, of course, the CSV content."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-1","__idx":6},"children":["Example"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"cURL","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"# Import the CSV file through the DATA API\ncurl -s \\\n-X POST \\\n--user \"$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE\" \\\nhttps://api.mailjet.com/v3/DATA/contactslist/$ID_CONTACTLIST/CSVData/text:plain \\\n-H \"Content-Type: text/plain\" \\\n--data-binary \"@./test.csv\"\n","lang":"shell"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"<?php\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n// View: CSV upload\n$CSVContent = file_get_contents('./test.csv');\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$response = $mj->post(Resources::$ContactslistCsvdata, ['body' => $CSVContent, 'id' => $ID_CONTACTLIST]);\n$response->success() && var_dump($response->getData());\n?>\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const fs = require ('fs')\nconst mailjet = require ('node-mailjet')\n    .connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)\nfs.readFile('./data.csv', (err, data) => {\n  if (err) { return console.error(err) }\n  const request = mailjet.post('contactslist')\n      .id(\"$ID_CONTACTLIST\")\n      .action('csvdata')\n      .request(data);\n  request\n  .then(result => {\n    console.log(result.body)\n  })\n  .catch(error => {\n    console.log(error.statusCode)\n  })\n})\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Ruby","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"# unsupported at the moment, please refer to cURL\n","lang":"ruby"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Python","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from mailjet_rest import Client\nimport os\napi_key = os.environ['MJ_APIKEY_PUBLIC']\napi_secret = os.environ['MJ_APIKEY_PRIVATE']\nmailjet = Client(auth=(api_key, api_secret))\nf = open('./data.csv')\nresult = mailjet.contactslist_csvdata.create(id='$ID_CONTACTLIST', data=f.read())\nprint result.status_code\nprint result.json()\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"package com.my.project;\nimport com.mailjet.client.errors.MailjetException;\nimport com.mailjet.client.errors.MailjetSocketTimeoutException;\nimport com.mailjet.client.MailjetClient;\nimport com.mailjet.client.MailjetRequest;\nimport com.mailjet.client.MailjetResponse;\nimport com.mailjet.client.resource.Csvimport;\nimport org.json.JSONArray;\nimport org.json.JSONObject;\npublic class MyClass {\n    /**\n     * Modify : A wrapper for the CSV importer\n     */\n    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {\n      MailjetClient client;\n      MailjetRequest request;\n      MailjetResponse response;\n      client = new MailjetClient(System.getenv(\"MJ_APIKEY_PUBLIC\"), System.getenv(\"MJ_APIKEY_PRIVATE\"));\n      request = new MailjetRequest(Csvimport.resource, ID)\n        .property(Csvimport.DATA, MYFILE);\n      response = client.put(request);\n      System.out.println(response.getStatus());\n      System.out.println(response.getData());\n    }\n}\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Go","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"package main\nimport (\n    \"fmt\"\n    \"io/ioutil\"\n    . \"github.com/mailjet/mailjet-apiv3-go\"\n    \"os\"\n)\nfunc check(e error) {\n    if e != nil {\n        panic(e)\n    }\n}\nfunc main () {\n    dat, err := ioutil.ReadFile(\"./data.csv\")\n    check(err)\n    mailjetClient := NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n    type MyStruct struct {\n\t   ID int\n    }\n    var data = new(MyStruct)\n    mr := &DataRequest{\n      SourceType: \"contactslist\",\n      SourceTypeID: \"$ID_CONTACTLIST\",\n      DataType: \"CSVData\",\n      MimeType: \"text:plain\",\n    }\n    fmr := &FullDataRequest{\n      Info: mr,\n      Payload: string(dat),\n    }\n    err1 := mailjetClient.PostData(fmr, &data)\n    if err1 != nil {\n      fmt.Println(err1)\n    }\n    fmt.Printf(\"Data array: %+v\\n\", data)\n}\n","lang":"go"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"# unsupported at the moment, please refer to cURL\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Save the ID - it’s used to specify the Data ID during ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /csvimport"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"import-csv-content-to-a-list","__idx":7},"children":["Import CSV content to a list"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You now need to use the uploaded data to manage the contacts in a specific contact list using the /csvimport resource."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The actions you can perform are:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["addforce "]},": Add the contacts to the list and subscribe all of them. If the contact is already present in the list as unsubscribed, it will be forcibly subscribed once again."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["addnoforce"]}," : Add the contacts to the list and subscribe them to it. If the contact is already present, it will retain its subscription status, i.e. if a contact is part of the list, but unsubscribed, it will not be forcibly subscribed again."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["remove"]}," : Remove the contacts from the list"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["unsub"]},": Unsubscribe the contacts from the list"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Select the action / method, the list ID and the data ID in the payload:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-2","__idx":8},"children":["Example"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"cURL","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"curl -s \\\n\t-X POST \\\n\t--user \"$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE\" \\\n\thttps://api.mailjet.com/v3/REST/csvimport \\\n\t-H 'Content-Type: application/json' \\\n\t-d '{\n      \"ErrTreshold\":\"1\",\n      \"ImportOptions\":\"\",\n      \"Method\":\"addnoforce\",\n      \"ContactsListID\":\"123456\",\n      \"DataID\":\"98765432123456789\"\n\t}'\n","lang":"shell"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"<?php\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3']);\n$body = [\n  'ErrTreshold' => \"1\",\n  'ImportOptions' => \"\",\n  'Method' => \"addnoforce\",\n  'ContactsListID' => \"123456\",\n  'DataID' => \"98765432123456789\"\n];\n$response = $mj->post(Resources::$Csvimport, ['body' => $body]);\n$response->success() && var_dump($response->getData());\n?>\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const mailjet = require ('node-mailjet')\n\t.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)\nconst request = mailjet\n\t.post(\"csvimport\", {'version': 'v3'})\n\t.request({\n      \"ErrTreshold\":\"1\",\n      \"ImportOptions\":\"\",\n      \"Method\":\"addnoforce\",\n      \"ContactsListID\":\"123456\",\n      \"DataID\":\"98765432123456789\"\n    })\nrequest\n\t.then((result) => {\n\t\tconsole.log(result.body)\n\t})\n\t.catch((err) => {\n\t\tconsole.log(err.statusCode)\n\t})\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Ruby","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"require 'mailjet'\nMailjet.configure do |config|\n  config.api_key = ENV['MJ_APIKEY_PUBLIC']\n  config.secret_key = ENV['MJ_APIKEY_PRIVATE']\n  config.api_version = \"v3\"\nend\nvariable = Mailjet::Csvimport.create(\n  err_treshold: \"1\",\n  import_options: \"\",\n  method: \"addnoforce\",\n  contacts_list_id: \"123456\",\n  data_id: \"98765432123456789\"\n)\np variable.attributes['Data']\n","lang":"ruby"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Python","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from mailjet_rest import Client\nimport os\napi_key = os.environ['MJ_APIKEY_PUBLIC']\napi_secret = os.environ['MJ_APIKEY_PRIVATE']\nmailjet = Client(auth=(api_key, api_secret), version='v3')\ndata = {\n  'ErrTreshold': \"1\",\n  'ImportOptions': \"\",\n  'Method': \"addnoforce\",\n  'ContactsListID': \"123456\",\n  'DataID': \"98765432123456789\"\n}\nresult = mailjet.csvimport.create(data=data)\nprint result.status_code\nprint result.json()\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"package com.my.project;\nimport com.mailjet.client.errors.MailjetException;\nimport com.mailjet.client.errors.MailjetSocketTimeoutException;\nimport com.mailjet.client.MailjetClient;\nimport com.mailjet.client.MailjetRequest;\nimport com.mailjet.client.MailjetResponse;\nimport com.mailjet.client.ClientOptions;\nimport com.mailjet.client.resource.Csvimport;\nimport org.json.JSONArray;\nimport org.json.JSONObject;\npublic class MyClass {\n    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {\n      MailjetClient client;\n      MailjetRequest request;\n      MailjetResponse response;\n      client = new MailjetClient(System.getenv(\"MJ_APIKEY_PUBLIC\"), System.getenv(\"MJ_APIKEY_PRIVATE\"), new ClientOptions(\"v3\"));\n      request = new MailjetRequest(Csvimport.resource)\n            .property(Csvimport.ERRTRESHOLD, \"1\")\n            .property(Csvimport.IMPORTOPTIONS, )\n            .property(Csvimport.METHOD, \"addnoforce\")\n            .property(Csvimport.CONTACTSLISTID, \"123456\")\n            .property(Csvimport.DATAID, \"98765432123456789\")\n      );\n      response = client.post(request);\n      System.out.println(response.getStatus());\n      System.out.println(response.getData());\n    }\n}\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Go","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"package main\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\tmailjet \"github.com/mailjet/mailjet-apiv3-go\"\n\t\"github.com/mailjet/mailjet-apiv3-go/resources\"\n)\nfunc main () {\n\tmailjetClient := NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Csvimport\n\tmr := &Request{\n\t  Resource: \"csvimport\",\n\t}\n\tfmr := &FullRequest{\n\t  Info: mr,\n\t  Payload: &resources.Csvimport { \n\t  ErrTreshold:\"1\",\n\t  ImportOptions:\"\",\n\t  Method:\"addnoforce\",\n\t  ContactsListID:\"123456\",\n\t  DataID:\"98765432123456789\"\n      }\n\t}\n\terr := mailjetClient.Post(fmr, &data)\n\tif err != nil {\n\t  fmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n","lang":"go"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using Mailjet.Client;\nusing Mailjet.Client.Resources;\nusing System;\nusing Newtonsoft.Json.Linq;\nnamespace Mailjet.ConsoleApplication\n{\n   class Program\n   {\n      static void Main(string[] args)\n      {\n         RunAsync().Wait();\n      }\n      static async Task RunAsync()\n      {\n         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"), Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"))\n         {\n            Version = ApiVersion.V3,\n         };\n         MailjetRequest request = new MailjetRequest\n         {\n            Resource = Csvimport.Resource,\n         }\n             .Property(Csvimport.ErrTreshold, \"1\")\n             .Property(Csvimport.ImportOptions, )\n             .Property(Csvimport.Method, \"addnoforce\")\n             .Property(Csvimport.ContactsListID, \"123456\")\n             .Property(Csvimport.DataID, \"98765432123456789\");\n         MailjetResponse response = await client.PostAsync(request);\n         if (response.IsSuccessStatusCode)\n         {\n            Console.WriteLine(string.Format(\"Total: {0}, Count: {1}\\n\", response.GetTotal(), response.GetCount()));\n            Console.WriteLine(response.GetData());\n         }\n         else\n         {\n            Console.WriteLine(string.Format(\"StatusCode: {0}\\n\", response.StatusCode));\n            Console.WriteLine(string.Format(\"ErrorInfo: {0}\\n\", response.GetErrorInfo()));\n            Console.WriteLine(response.GetData());\n            Console.WriteLine(string.Format(\"ErrorMessage: {0}\\n\", response.GetErrorMessage()));\n         }\n      }\n   }\n}\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"api-response","__idx":9},"children":["API Response"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"{\n\t\"Count\": 1,\n\t\"Data\": [\n\t\t{\n\t\t\t\"ErrTreshold\": 1,\n\t\t\t\"ImportOptions\": \"\",\n\t\t\t\"Method\": \"addnoforce\",\n\t\t\t\"AliveAt\": \"2018-01-01T00:00:00\",\n\t\t\t\"ContactsListID\": 123456,\n\t\t\t\"Count\": 12,\n\t\t\t\"Current\": 10,\n\t\t\t\"DataID\": 98765432123456780,\n\t\t\t\"Errcount\": 0,\n\t\t\t\"ID\": 987654,\n\t\t\t\"JobEnd\": \"2018-01-01T00:00:00\",\n\t\t\t\"JobStart\": \"2018-01-01T00:00:00\",\n\t\t\t\"RequestAt\": \"2018-01-01T00:00:00\",\n\t\t\t\"Status\": \"Upload\"\n\t\t}\n\t],\n\t\"Total\": 1\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ID returned is the ID of the import job - use it to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["monitor the import progress"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"using-csv-with-datetime-contact-data","__idx":10},"children":["Using CSV with Datetime contact data"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When trying to import contact data with type datetime, you should define an additional property in the payload - ImportOptions. Its value should be passed as a string, containing the following options:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["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')."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TimezoneOffset"]}," : used to select timezone offset. The value is an integer in the -12 to 12 range."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["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."]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-3","__idx":11},"children":["Example"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"cURL","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"# Create: A wrapper for the CSV importer\ncurl -s \\\n\t-X POST \\\n\t--user \"$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE\" \\\n\thttps://api.mailjet.com/v3/REST/csvimport \\\n\t-H 'Content-Type: application/json' \\\n\t-d '{\n\t\t\"ContactsListID\":\"$ID_CONTACTLIST\",\n\t\t\"DataID\":\"$ID_DATA\",\n\t\t\"Method\":\"addnoforce\",\n\t\t\"ImportOptions\":\"{\\\"DateTimeFormat\\\": \\\"yyyy/mm/dd\\\",\\\"TimezoneOffset\\\": 2,\\\"FieldNames\\\": [\\\"email\\\",\\\"birthday\\\"]}\"\n\t}'\n","lang":"shell"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"<?php\n/*\nCreate: A wrapper for the CSV importer\n*/\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$body = [\n    'ContactsListID' => \"$ID_CONTACTLIST\",\n    'DataID' => \"$ID_DATA\",\n    'Method' => \"addnoforce\",\n    'ImportOptions' => \"{\\\\\"DateTimeFormat\\\\\": \\\\\"yyyy/mm/dd\\\\\",\\\\\"TimezoneOffset\\\\\": 2,\\\\\"FieldNames\\\\\": [\\\\\"email\\\\\",\\\\\"birthday\\\\\"]}\"\n];\n$response = $mj->post(Resources::$Csvimport, ['body' => $body]);\n$response->success() && var_dump($response->getData());\n?>\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"/**\n *\n * Create: A wrapper for the CSV importer\n *\n */\nconst mailjet = require ('node-mailjet')\n\t.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)\nconst request = mailjet\n\t.post(\"csvimport\")\n\t.request({\n\t\t\"ContactsListID\":\"$ID_CONTACTLIST\",\n\t\t\"DataID\":\"$ID_DATA\",\n\t\t\"Method\":\"addnoforce\",\n\t\t\"ImportOptions\":\"{\\\"DateTimeFormat\\\": \\\"yyyy/mm/dd\\\",\\\"TimezoneOffset\\\": 2,\\\"FieldNames\\\": [\\\"email\\\",\\\"birthday\\\"]}\"\n\t})\nrequest\n\t.then((result) => {\n\t\tconsole.log(result.body)\n\t})\n\t.catch((err) => {\n\t\tconsole.log(err.statusCode)\n\t})\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Ruby","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"# Create: A wrapper for the CSV importer\nrequire 'mailjet'\nMailjet.configure do |config|\n  config.api_key = ENV['MJ_APIKEY_PUBLIC']\n  config.secret_key = ENV['MJ_APIKEY_PRIVATE']  \nend\nvariable = Mailjet::Csvimport.create(contacts_list_id: \"$ID_CONTACTLIST\",\ndata_id: \"$ID_DATA\",\nmethod: \"addnoforce\",\nimport_options: \"{\\\"DateTimeFormat\\\": \\\"yyyy/mm/dd\\\",\\\"TimezoneOffset\\\": 2,\\\"FieldNames\\\": [\\\"email\\\",\\\"birthday\\\"]}\"\n)\np variable.attributes['Data']\n","lang":"ruby"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Python","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"\"\"\"\nCreate: A wrapper for the CSV importer\n\"\"\"\nfrom mailjet_rest import Client\nimport os\napi_key = os.environ['MJ_APIKEY_PUBLIC']\napi_secret = os.environ['MJ_APIKEY_PRIVATE']\nmailjet = Client(auth=(api_key, api_secret))\ndata = {\n  'ContactsListID': '$ID_CONTACTLIST',\n  'DataID': '$ID_DATA',\n  'Method': 'addnoforce',\n  'ImportOptions': '{\\\"DateTimeFormat\\\": \\\"yyyy/mm/dd\\\",\\\"TimezoneOffset\\\": 2,\\\"FieldNames\\\": [\\\"email\\\",\\\"birthday\\\"]}'\n}\nresult = mailjet.csvimport.create(data=data)\nprint result.status_code\nprint result.json()\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"package com.my.project;\nimport com.mailjet.client.errors.MailjetException;\nimport com.mailjet.client.errors.MailjetSocketTimeoutException;\nimport com.mailjet.client.MailjetClient;\nimport com.mailjet.client.MailjetRequest;\nimport com.mailjet.client.MailjetResponse;\nimport com.mailjet.client.resource.Csvimport;\nimport org.json.JSONArray;\nimport org.json.JSONObject;\npublic class MyClass {\n    /**\n     * Create: A wrapper for the CSV importer\n     */\n    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {\n      MailjetClient client;\n      MailjetRequest request;\n      MailjetResponse response;\n      client = new MailjetClient(System.getenv(\"MJ_APIKEY_PUBLIC\"), System.getenv(\"MJ_APIKEY_PRIVATE\"));\n      request = new MailjetRequest(Csvimport.resource)\n\t\t\t.property(Csvimport.CONTACTSLISTID, \"$ID_CONTACTLIST\")\n\t\t\t.property(Csvimport.DATAID, \"$ID_DATA\")\n\t\t\t.property(Csvimport.METHOD, \"addnoforce\")\n\t\t\t.property(Csvimport.IMPORTOPTIONS, \"{\\\\\"DateTimeFormat\\\\\": \\\\\"yyyy/mm/dd\\\\\",\\\\\"TimezoneOffset\\\\\": 2,\\\\\"FieldNames\\\\\": [\\\\\"email\\\\\",\\\\\"birthday\\\\\"]}\");\n      response = client.post(request);\n      System.out.println(response.getStatus());\n      System.out.println(response.getData());\n    }\n}\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Go","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"/*\nCreate: A wrapper for the CSV importer\n*/\npackage main\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\tmailjet \"github.com/mailjet/mailjet-apiv3-go\"\n\t\"github.com/mailjet/mailjet-apiv3-go/resources\"\n)\nfunc main () {\n\tmailjetClient := NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Csvimport\n\tmr := &Request{\n\t  Resource: \"csvimport\",\n\t}\n\tfmr := &FullRequest{\n\t  Info: mr,\n\t  Payload: &resources.Csvimport {\n      ContactsListID: \"$ID_CONTACTLIST\",\n      DataID: \"$ID_DATA\",\n      Method: \"addnoforce\",\n    ImportOptions: \"{\\\"DateTimeFormat\\\": \\\"yyyy/mm/dd\\\",\\\"TimezoneOffset\\\": 2,\\\"FieldNames\\\": [\\\"email\\\",\\\"birthday\\\"]}\",\n    },\n\t}\n\terr := mailjetClient.Post(fmr, &data)\n\tif err != nil {\n\t  fmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n","lang":"go"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using Mailjet.Client;\nusing Mailjet.Client.Resources;\nusing System;\nusing Newtonsoft.Json.Linq;\nnamespace Mailjet.ConsoleApplication\n{\n   class Program\n   {\n      /// <summary>\n      /// Create: A wrapper for the CSV importer\n      /// </summary>\n      static void Main(string[] args)\n      {\n         RunAsync().Wait();\n      }\n      static async Task RunAsync()\n      {\n         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"), Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"));\n         MailjetRequest request = new MailjetRequest\n         {\n            Resource = Csvimport.Resource,\n         }\n            .Property(Csvimport.ContactsListID, \"$ID_CONTACTLIST\")\n            .Property(Csvimport.DataID, \"$ID_DATA\")\n            .Property(Csvimport.Method, \"addnoforce\")\n            .Property(Csvimport.ImportOptions, \"{\\\\\"DateTimeFormat\\\\\": \\\\\"yyyy/mm/dd\\\\\",\\\\\"TimezoneOffset\\\\\": 2,\\\\\"FieldNames\\\\\": [\\\\\"email\\\\\",\\\\\"birthday\\\\\"]}\");\n         MailjetResponse response = await client.PostAsync(request);\n         if (response.IsSuccessStatusCode)\n         {\n            Console.WriteLine(string.Format(\"Total: {0}, Count: {1}\\n\", response.GetTotal(), response.GetCount()));\n            Console.WriteLine(response.GetData());\n         }\n         else\n         {\n            Console.WriteLine(string.Format(\"StatusCode: {0}\\n\", response.StatusCode));\n            Console.WriteLine(string.Format(\"ErrorInfo: {0}\\n\", response.GetErrorInfo()));\n            Console.WriteLine(response.GetData());\n            Console.WriteLine(string.Format(\"ErrorMessage: {0}\\n\", response.GetErrorMessage()));\n         }\n      }\n   }\n}\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"monitor-the-import-progress","__idx":12},"children":["Monitor the Import Progress"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can now make sure the task is 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 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["JobID"]}," returned in the previous step, you can retrieve the job status."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-4","__idx":13},"children":["Example"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"cURL","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"curl -s \\\n\t-X GET \\\n\t--user \"$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE\" \\\n\thttps://api.mailjet.com/v3/REST/csvimport/$importjob_ID \\\n","lang":"shell"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"<?php\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3']);\n$response = $mj->get(Resources::$Csvimport, ['id' => $id]);\n$response->success() && var_dump($response->getData());\n?>\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const mailjet = require ('node-mailjet')\n\t.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)\nconst request = mailjet\n\t.get(\"csvimport\", {'version': 'v3'})\n\t.id($importjob_ID)\n\t.request()\nrequest\n\t.then((result) => {\n\t\tconsole.log(result.body)\n\t})\n\t.catch((err) => {\n\t\tconsole.log(err.statusCode)\n\t})\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Ruby","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"require 'mailjet'\nMailjet.configure do |config|\n  config.api_key = ENV['MJ_APIKEY_PUBLIC']\n  config.secret_key = ENV['MJ_APIKEY_PRIVATE']\n  config.api_version = \"v3\"\nend\nvariable = Mailjet::Csvimport.find($importjob_ID\n)\np variable.attributes['Data']\n","lang":"ruby"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Python","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from mailjet_rest import Client\nimport os\napi_key = os.environ['MJ_APIKEY_PUBLIC']\napi_secret = os.environ['MJ_APIKEY_PRIVATE']\nmailjet = Client(auth=(api_key, api_secret), version='v3')\nid = '$importjob_ID'\nresult = mailjet.csvimport.get(id=id)\nprint result.status_code\nprint result.json()\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"package com.my.project;\nimport com.mailjet.client.errors.MailjetException;\nimport com.mailjet.client.errors.MailjetSocketTimeoutException;\nimport com.mailjet.client.MailjetClient;\nimport com.mailjet.client.MailjetRequest;\nimport com.mailjet.client.MailjetResponse;\nimport com.mailjet.client.ClientOptions;\nimport com.mailjet.client.resource.Csvimport;\nimport org.json.JSONArray;\nimport org.json.JSONObject;\npublic class MyClass {\n    public static void main(String[] args) throws MailjetException, MailjetSocketTimeoutException {\n      MailjetClient client;\n      MailjetRequest request;\n      MailjetResponse response;\n      client = new MailjetClient(System.getenv(\"MJ_APIKEY_PUBLIC\"), System.getenv(\"MJ_APIKEY_PRIVATE\"), new ClientOptions(\"v3\"));\n      request = new MailjetRequest(Csvimport.resource, ID);\n      response = client.get(request);\n      System.out.println(response.getStatus());\n      System.out.println(response.getData());\n    }\n}\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Go","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"package main\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\tmailjet \"github.com/mailjet/mailjet-apiv3-go\"\n\t\"github.com/mailjet/mailjet-apiv3-go/resources\"\n)\nfunc main () {\n\tmailjetClient := NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Csvimport\n\tmr := &Request{\n\t  Resource: \"csvimport\",\n\t  ID: RESOURCE_ID,\n\t}\n\terr := mailjetClient.Get(mr, &data)\n\tif err != nil {\n\t  fmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n","lang":"go"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using Mailjet.Client;\nusing Mailjet.Client.Resources;\nusing System;\nusing Newtonsoft.Json.Linq;\nnamespace Mailjet.ConsoleApplication\n{\n   class Program\n   {\n      static void Main(string[] args)\n      {\n         RunAsync().Wait();\n      }\n      static async Task RunAsync()\n      {\n         MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"), Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"))\n         {\n            Version = ApiVersion.V3,\n         };\n         MailjetRequest request = new MailjetRequest\n         {\n            Resource = Csvimport.Resource,\n            ResourceId = ResourceId.Numeric(ID)\n         }\n         MailjetResponse response = await client.GetAsync(request);\n         if (response.IsSuccessStatusCode)\n         {\n            Console.WriteLine(string.Format(\"Total: {0}, Count: {1}\\n\", response.GetTotal(), response.GetCount()));\n            Console.WriteLine(response.GetData());\n         }\n         else\n         {\n            Console.WriteLine(string.Format(\"StatusCode: {0}\\n\", response.StatusCode));\n            Console.WriteLine(string.Format(\"ErrorInfo: {0}\\n\", response.GetErrorInfo()));\n            Console.WriteLine(response.GetData());\n            Console.WriteLine(string.Format(\"ErrorMessage: {0}\\n\", response.GetErrorMessage()));\n         }\n      }\n   }\n}\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"api-respoonse","__idx":14},"children":["API Respoonse"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"{\n\t\"Count\": 1,\n\t\"Data\": [\n\t\t{\n\t\t\t\"ErrTreshold\": 1,\n\t\t\t\"ImportOptions\": \"\",\n\t\t\t\"Method\": \"addnoforce\",\n\t\t\t\"AliveAt\": \"2018-01-01T00:00:00\",\n\t\t\t\"ContactsListID\": 123456,\n\t\t\t\"Count\": 12,\n\t\t\t\"Current\": 10,\n\t\t\t\"DataID\": 98765432123456780,\n\t\t\t\"Errcount\": 0,\n\t\t\t\"ID\": 987654,\n\t\t\t\"JobEnd\": \"2018-01-01T00:00:00\",\n\t\t\t\"JobStart\": \"2018-01-01T00:00:00\",\n\t\t\t\"RequestAt\": \"2018-01-01T00:00:00\",\n\t\t\t\"Status\": \"Upload\"\n\t\t}\n\t],\n\t\"Total\": 1\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"error-handling","__idx":15},"children":["Error Handling"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ErrCount"]}," in the response of the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GET /csvimport/$job_ID"]}," request is different than 0, you can retrieve a file with information about the errors that occurred during the import."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-5","__idx":16},"children":["Example"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"cURL","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"shell","header":{"controls":{"copy":{}}},"source":"curl --user \"$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE\" \\\nhttps://api.mailjet.com/v3/DATA/BatchJob/$job_id/CSVError/text:csv\n","lang":"shell"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"<?php\nrequire 'vendor/autoload.php';\nuse \\Mailjet\\Resources;\n$mj = new \\Mailjet\\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));\n$response = $mj->get(Resources::$BatchjobCsverror, ['id' => $job_id]);\n$response->success() && var_dump($response->getBody());\n?>\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"/**\n *\n * Not available in Node, please refer to Curl\n *\n */\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Ruby","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"# Not available in Ruby, please refer to Curl\n","lang":"ruby"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Python","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"\"\"\"\nNot available in Python, please refer to Curl\n\"\"\"\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"/**\n* Not available in Java , please refer to Curl\n*/\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Go","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"/*\nNot available in Go, please refer to Curl\n*/\n","lang":"go"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The returned file will be a copy of your original file with an added column describing the error for each line in error."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["File uploaded with error:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"\"email\",\"age\"\n\"foo@example.org\",42\n\"bar@example.com\"\n\"sam@ple.co.uk\",37\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Error file content:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"email,age,error\n\"bar@example.com\", ###Too few columns at line\n"},"children":[]}]},"headings":[{"value":"Manage contacts via CSV Upload","id":"manage-contacts-via-csv-upload","depth":1},{"value":"Using a CSV file to upload","id":"using-a-csv-file-to-upload","depth":2},{"value":"CSV content requirements","id":"csv-content-requirements","depth":2},{"value":"Examples","id":"examples","depth":3},{"value":"Example","id":"example","depth":3},{"value":"Upload the CSV","id":"upload-the-csv","depth":2},{"value":"Example","id":"example-1","depth":3},{"value":"Import CSV content to a list","id":"import-csv-content-to-a-list","depth":2},{"value":"Example","id":"example-2","depth":3},{"value":"API Response","id":"api-response","depth":3},{"value":"Using CSV with Datetime contact data","id":"using-csv-with-datetime-contact-data","depth":3},{"value":"Example","id":"example-3","depth":3},{"value":"Monitor the Import Progress","id":"monitor-the-import-progress","depth":2},{"value":"Example","id":"example-4","depth":3},{"value":"API Respoonse","id":"api-respoonse","depth":3},{"value":"Error Handling","id":"error-handling","depth":2},{"value":"Example","id":"example-5","depth":3}],"frontmatter":{"title":"Mailjet Send Contact Management","seo":{"description":"Upload contacts in bulk to Mailjet using a CSV file: format the data, post it to the DATA API, then trigger an async import via /csvimport.","title":"Manage contacts via CSV Upload"}},"lastModified":"2026-08-26T10:53:57.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/email-api/contact-management/manage-contacts-csv","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}