Skip to content

Domains

tomek-ac edited this page Jun 22, 2022 · 6 revisions

With API client you can easily manage all your account domains. Check out the examples of some of the API requests you can do with the library.

For these API requests you will need to use a account API token. Once you obtain it, you will need to use account API client.

account_token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
client = Postmark::AccountApiClient.new(account_token, secure: true)

List domains

client.get_domains(offset: 0, count: 30)

# => [{"name": "example.com", "spf_verified": true, "dkim_verified": true, "weak_dkim": false, "return_path_domain_verified": false, "id": 3 }]

To retrieve domains enumerator:

client.domains.map { |s| s[:id] }
# => [2]

client.domains.lazy.select { |s| s[:name] == 'example.com' }.first(2)

# => [{"name": "example.com", "spf_verified": true, "dkim_verified": true, "weak_dkim": false, "return_path_domain_verified": false, "id": 3 }]

client.domains.size # Lazily evaluated on Ruby 2.0.0 and above, not supported on legacy Ruby versions
# => 1

client.domains.count # Calculates a count through iteration
# => 1

Retrieve single domain details

client.get_domain(1)

Create a new domain

client.create_domain(name: 'postmarkapp.com', return_path_domain: 'return.postmarkapp.com')

# => {"name": "postmarkapp.com", return_path_domain:"return.postmarkapp.com", "spf_verified": false, "spf_host": "postmarkapp.com", "spf_text_value": "v=spf1 a mx include:spf.mtasv.net ~all", "dkimverified": false, ..., "id": 1}

Update existing domain details

client.update_domain(1, return_path_domain: 'updated-return.postmarkapp.com')

# => {"name": "postmarkapp.com", return_path_domain:"updated-return.postmarkapp.com", "spf_verified": false, "spf_host": "postmarkapp.com", "spf_text_value": "v=spf1 a mx include:spf.mtasv.net ~all", "dkimverified": false, ..., "id": 1}

Trigger SPF verification for your domain

client.verified_domain_spf?(1345)

# => true

Trigger rotation of domain DKIM key

client.rotate_domain_dkim(1)

# => {:dkim_text_value => '', ...}

Delete one of existing domains

client.delete_domain(1)

# => {:error_code=>0, :message=>"Domain postmarkapp.com removed."}