Getting Started
The SpamExperts REST API lets you automate the same core actions available in the product interface.
You can use it from any language that can send HTTPS requests and work with JSON.
To use the API, you need to request an API token from the support team.
Most endpoints require authentication with this token, given with the HTTP-X-AUTH-TOKEN header.
We use the $BASE_URL variable for indicating the hostname throughout this guide. If you're a MailAssure customer, this is
https://antispamcloud.com
Basics
- All connections use HTTPS.
- Requests and responses are JSON by default.
- The API follows common REST patterns.
Most code examples in this guide use
curlso they can be easily copy-pasted into a terminal. However, more complex requests with nested JSON structures will usepythonand therequestslibrary for readability.
Prove connectivity and basic access first by checking the version:
curl -sS \
-H "HTTP-X-AUTH-TOKEN: $API_TOKEN" \
"$BASE_URL/api-v1/version/"URL shapes
Most collection endpoints support multiple URL shapes:
Collection name-only
/collection/ applies to multiple instances (e.g. /address_aliases/)
Collection name with identifier
Many collections support multiple identifiers.
For example, the address_aliases collection supports a domain, local, alias_domain, alias_local.
You may use any number of identifiers, in the order they're defined in the API schema.
For address_aliases, you can use:
/address_aliases/*domain*/(applies to many instances)/address_aliases/*domain*/*local*/(applies to many instances)/address_aliases/*domain*/*local*/*alias_domain*/(applies to many instances)/address_aliases/*domain*/*local*/*alias_domain*/*alias_local*/(applies to one instance)
In general, only if you include all the identifiers for a collection then the request will apply to one instance. If you omit any identifier, the request applies to multiple instances.
Collection name with identifier and property
After including the collection and identifiers, you can optionally include a property name to access or modify just that property.
For address_aliases, you can use:
/address_aliases/*domain*/*local*/*alias_domain*/*alias_local*/relay(applies to one instance property)
Note how in the property endpoint, there is not trailing slash. For the other endpoints, the trailing slash is required. If you don't include a trailing slash, you will be redirected to the URL with the trailing slash.
HTTP Methods
Most collections support these methods:
GETfor retrieving one or more instancesPOSTfor creating one or more instancesPUTfor updating one or more instancesDELETEfor removing one or more instances
Request body rules
GETandDELETE: no request bodyPUT: a JSON objectPUTon a property endpoint: a JSON valuePOSTfor one instance: a JSON objectPOSTfor many instances: a JSON list of objects
Set Content-Type: application/json on requests that send JSON.
Common query features
The q parameter
q parameterMost endpoints support the q parameter for selecting fields, filtering, ordering, grouping, and aggregate functions.
Use fields to select which fields are returned
fields to select which fields are returnedcurl -sS --get \
-H "HTTP-X-AUTH-TOKEN: $API_TOKEN" \
--data-urlencode 'q={"fields":[{"field":"domain"}]}' \
"$BASE_URL/api-v1/relays/"The
fieldsoption is required for allGETrequests.
filters lets you select records that match specific criteria
filters lets you select records that match specific criteriaCommon operators include:
==,!=>,<,>=,<=in,not_inlike,not_likeip_matchis_null,is_not_null
Filters can be combined into Boolean expressions with and and or.
Sorting, grouping, and counts
Use these options inside q as needed:
order_bygroup_bycountdistinctpage_count
Most endpoints also support aggregate field functions such as sum and group_concat.
Other parameters
page_size: number of results per pagepage: page number, starting at1count: whether to include the total count of matching records in the response (defaultfalse)
Datetime values
Date and datetime filters can usually be expressed as:
- ISO-formatted values
- relative values such as
20 minutes ago,2 hours ago, or7 days ago
Example requests
List domains
curl -sS --get \
-H "HTTP-X-AUTH-TOKEN: $API_TOKEN" \
--data-urlencode 'q={"fields":[{"field":"domain"}]}' \
"$BASE_URL/api-v1/relays/"Add a domain
The minimum required fields are:
domainusernamequarantine_password
If the domain contains non-ASCII characters, send the IDNA-encoded value in domain.
curl -sS \
-H "HTTP-X-AUTH-TOKEN: $API_TOKEN" \
-H "Content-Type: application/json" \
-d '[{"domain":"api.example.org","username":"legacy","quarantine_password":""}]' \
"$BASE_URL/api-v1/relays/"A domain without destinations cannot process mail. In practice, include routes when you create the domain:
curl -sS \
-H "HTTP-X-AUTH-TOKEN: $API_TOKEN" \
-H "Content-Type: application/json" \
-d '[{"domain":"api2.example.org","username":"legacy","quarantine_password":"","routes":[{"host":"mx.example.org","port":25}]}]' \
"$BASE_URL/api-v1/relays/"Updated 2 months ago