Mailrelay API Reference

Import a new file

POST /imports

This function should be used when you need to import a large number of subscribers and adding then individually is very slow.

This function expects you to provide importfieldsattributes which is an array indicating what each column in your file represents. If you have the following CSV where the first column is an email, the second is the name of the subscriber and the third is the value for a custom field with id 4:

[email protected],John Doe,my custom value
[email protected],Lisa Doe,another custom value

The following value for importfieldsattributes should be sent:

[
  {
    column: 0,
    field: 'email'
  },
  {
    column: 1,
    field: 'name'
  },
  {
    column: 2,
    field: 'custom_field_4'
  }
]

If you specify a callback URL, we will send a POST request right after the import is processed. It will contain a JSON with the type of the callback and the ID of the import.

You can use the following command to simulate a callback request:

curl --request POST \
  --url https://your-callback-domain.com/callback-url \
  --header 'content-type: application/json' \
  --data '{"type":"import_finished","id":1}'

Parameters

NameTypeDescription
file
existing_subscribers string If a subscriber already exists, what should we do?
callback_url string A URL that will be called when the import process has finished. A POST request will be sent to this URL with a JSON payload containing the ID of the import.
import_fields_attributes array Import fields attributes
group_ids array Group ids

Responses

StatusDescription
201 Success
400 The request is invalid. Check if the field names in the request and the request data is valid.
422 A validation error occurred. Check the response body for more information.
401 The API key wasn't sent or is invalid
500 An internal error happened. Try again later.