This guide will walk you through steps of deleting one contact from your account, by its email address, using the Bash library. To delete several contacts in one call, see deleteContacts.
Required Access Level: ModifyContacts
Find out more by checking our API's documentation: https://elasticemail.com/developers/api-documentation/rest-api#operation/contactsByEmailDelete
When using Elastic Email, you send emails to contacts – recipients who receive your emails. Contacts can be grouped by created segments or lists.
It's a Bash script so it's a program to be run by Unix shell. On linux (eg. Ubuntu) there's no need to install anything additional.
Create a new file eg. script.sh
Download the lib from ElasticEmail repository https://github.com/ElasticEmail/elasticemail-bash and make sure the script has executable rights
$ chmod u+x ElasticEmail
Put the below code to your file.
In the first line indicate that it's a bash script:
#!/bin/bashVariable for host value:
host=https://api.elasticemail.comRead your API key from the ELASTICEMAIL_API_KEY environment variable (remember to check a required access level). The script stops with an error if the variable is not set:
apiKey="${ELASTICEMAIL_API_KEY:?set ELASTICEMAIL_API_KEY}"and create header variables for api key:
apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKeyDefine a method that will be used:
apiMethod=contactsByEmailDelete
Specify the email address of the contact to delete:
email="johnsmith@domain.com"And finally, you can use the lib to make an api call:
./ElasticEmail --host "$host" "$apiMethod" email="$email" "$apiKeyHeader"#!/bin/bash
host=https://api.elasticemail.com
apiKey="${ELASTICEMAIL_API_KEY:?set ELASTICEMAIL_API_KEY}"
apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey
apiMethod=contactsByEmailDelete
email="johnsmith@domain.com"
./ElasticEmail --host "$host" "$apiMethod" email="$email" "$apiKeyHeader"export ELASTICEMAIL_API_KEY=your-api-key
bash script.sh