Mailrelay API Reference

Add a new API batch

POST https://{account}/api/v1/api_batches

Authentication

Requires an API key sent in the X-AUTH-TOKEN header.

Use this method create a new API batch. You can specify up to 500 operations in the same batch.

This an example showing how to create a group, update a subscriber and pause a sent campaign in the same API batch:

{
  "callback_url": "https://my-callback-url.example.com/",
  "operations_attributes": [{
    "request_path": "/api/v1/groups",
    "request_method": "post",
    "request_body": "{\"name\":\"My group name\"}"
  }, {
    "request_path": "/api/v1/subscribers/1",
    "request_method": "patch",
    "request_body": "{\"name\":\"New subscriber name\"}"
  }, {
    "request_path": "/api/v1/sent_campaigns/1/pause",
    "request_method": "patch"
  }]
}

The response will include the ID of the batch, which can be used to check the results later. Note that finished batches are automatically removed after 7 days.

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

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":"api_batch_finished","id":1}'

Parameters

NameTypeRequiredDescription
operations_attributes array Yes An array of API batches
callback_url string No A URL that will be called when the api batch is processed. A POST request will be sent to this URL with a JSON payload containing the ID of the API batch.

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
429 Too many requests. You have exceeded the rate limit, wait and try again later.
500 An internal error happened. Try again later.

Response fields

NameTypeDescription
id integer Id
callback_url string A URL that will be called when the api batch is processed. A POST request will be sent to this URL with a JSON payload containing the ID of the API batch.
status string Status
finished_at string Finished at
operations array Operations