Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Formatting a CSV


(information)

Covers Marketing Campaigns v3

These tutorials cover the latest version of Marketing Campaigns. If you're using the legacy version of Marketing Campaigns, your experience might differ. To send email with the Twilio SendGrid Email API, see the API reference or the SMTP Reference.

To add contacts to your contact database, upload a comma-separated value (CSV) file into Marketing Campaigns.

  • Save a spreadsheet as a CSV file.
  • Export your contacts from most database systems as a CSV file.
  • Before uploading a CSV file generated in another application, check it for issues in a plain-text editor like NotePad or TextEdit.

General formatting rules

general-formatting-rules page anchor

To upload a CSV into Marketing Campaigns, format your data using the following rules. To see an example, download this sample CSV.

emailfirst_namelast_nameaddress_line_1address_line_2citystate_province_regionpostal_codecountryphone_number_id external_id anonymous_id

example@example.com

John

Doe

123 Neverland Lane

Suite 42

Denver

CO

80202

USA

+18778894546

example_external_id

example_anonymous_id

Contact info

contact-info page anchor

Your CSV requires the following information about each contact:

  • email or phone_number_id or external_id or anonymous_id (choose one)
  • first_name
  • last_name

You can use other reserved fields such as city and zipcode. You can also include custom fields with additional identifying information for each contact in the CSV.

For example: You could specify birthday, occupation, and age as the custom fields. The data in the custom fields aid in segmentation and content personalization.

The first row of your CSV must include labels for each column. These labels are also called fields.

  • These labels can only use letters, numbers, and underscores.
  • Header fields don't need to be in your CSV, but must be assigned a label and defined data type during the upload process.
  • If you add custom field data to your CSV, use the defined custom field label as the header label.
  • One of the header fields must be the unique identifier for your contacts: email, phone_number_id, external_id, or anonymous_id.
    • Without one of the required identifier columns, Twilio SendGrid doesn't add your contact, but continues with the remainder of the upload. For this reason, the number of contacts might change between your CSV and your Marketing Campaigns list.

Use Unicode character encoding

use-unicode-character-encoding page anchor

If your contacts list has non-English characters, encode your CSV file with UTF-8.

Remove invalid and duplicate identifiers

remove-invalid-and-duplicate-identifiers page anchor

Twilio SendGrid removes duplicate and invalid identifiers.

  • Invalid identifers include email addresses with any special characters except for underscores.
  • Each contact requires at least one unique identifier per contact.
  • When updating a contact, include all of its existing identifiers.
  • When uploading your CSV, choose the correct data type as your Field type.

  • Numbers data types can't include anything other than numbers or a decimal separator.
    Twilio considers the inclusion of any other character makes the value a string.

    Examples of string field types with numbers in them

    examples-of-string-field-types-with-numbers-in-them page anchor
    1
    - US Zip Code: 80202-1713
    2
    - Phone numbers: "(555) 555-5555" or "555.555.5555"
    3
    - Monetary Values with the currency indicator such as $3.50 or €5.73
Text field examplesNumber field examples
$9.959.95
-100100
123.45.67.890100.00

Use one of the following date formats:

  • MM/DD/YYYY
  • `MM/D/YYYY
  • M/D/YYYY
  • M/DD/YYYY

When uploading a CSV to Marketing Campaigns, you might encounter the following errors. To correct the root issue, see the offered options.

We were unable to detect an identifier column in the CSV file headers. The identifier column must always have a header of email, phone_number_id, external_id, or anonymous_id

we-were-unable-to-detect-an-identifier-column-in-the-csv-file-headers-the-identifier-column-must-always-have-a-header-of-email-phone_number_id-external_id-or-anonymous_id page anchor
  • If you include a header labeled as one of the accepted identifiers, move it to the first position in your header row.
  • Your CSV must include a header with one of the accepted identifiers.

Bad example with incorrect identifier header label

bad-example-with-incorrect-identifier-header-label page anchor
1
Email Address,first_name,last_name
2
emailtesting@gmail.com,John,Doe

Good example with correct identifier header label

good-example-with-correct-identifier-header-label page anchor
1
email,first_name,last_name
2
emailtesting@gmail.com,John,Doe

Some of your custom fields have not been selected

some-of-your-custom-fields-have-not-been-selected page anchor
  • Look for hidden characters in your CSV file.
  • Select all data in your spreadsheet and copy your data to a new CSV spreadsheet. This should remove any hidden characters.

Each custom field can only be applied to a column once. Please check your columns and try again

each-custom-field-can-only-be-applied-to-a-column-once-please-check-your-columns-and-try-again page anchor

Your CSV can't have duplicate fields. This applies to fields with values that match your email, first_name and last_name fields. These reserved field names can't be edited.

  • For example: If you have a Name field, it may conflict with your first_name reserved field.

Bad example with ambiguous header labels

bad-example-with-ambiguous-header-labels page anchor
1
email,first_name,last_name,Name
2
emailtesting@gmail.com,John,Doe,Twilio

Good example with distinct header labels

good-example-with-distinct-header-labels page anchor
1
email,first_name,last_name,Company_Name
2
emailtesting@gmail.com,John,Doe,Twilio

We were unable to detect any headers in your CSV file

we-were-unable-to-detect-any-headers-in-your-csv-file page anchor

Include header fields at the top of each column. All CSV uploads must contain the email header. Header fields can be blank in your CSV but must be defined later during the upload process.

Bad example without a header row

bad-example-without-a-header-row page anchor
emailtesting@gmail.com,John,Doe

Good example with a header row

good-example-with-a-header-row page anchor
1
email,first_name,last_name
2
emailtesting@gmail.com,John,Doe

Float type conversion error

float-type-conversion-error page anchor
  • Categorize dashes or decimal places that are past the hundredth place as text_fields (-100, 123.123 are text fields, 100, 12.12 can be number fields).
  • Number fields can include monetary values without the currency symbols. For example, 19.95 would be a number field, and $19.95, including the ($), would be a text field.
  • As you are uploading your CSV, make sure you select the correct fields for your Field type.
Text field examplesNumber field examples
$9.959.95
-100100
123.45.67.890100.00

We encountered an error attempting to process your CSV file. Please ensure the file is a valid CSV file

we-encountered-an-error-attempting-to-process-your-csv-file-please-ensure-the-file-is-a-valid-csv-file page anchor