Skip to content

Servers

Igor Balos edited this page Oct 3, 2018 · 6 revisions

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)

Get server by ID

client.get_server(2)

# => {:id=>2, :name=>"Server", ... }

Create server

client.create_server(name: 'Server', color: 'red')

# => {:id=>2, :name=>"Server", :api_tokens=>[...], :server_link=>"...", :color=>"red", :smtp_api_activated=>false, :raw_email_enabled=>false, :inbound_address=>"...", :inbound_hook_url=>"", :bounce_hook_url=>"", :inbound_domain=>"", :inbound_hash=>"..."}

Update server

client.update_server(1, {
  "Name": "Staging Testing",
  "Color": "red",
  "SmtpApiActivated": true,
  "RawEmailEnabled": false
})

Get list of servers

You can automatically scale your architecture by exploiting the Servers API. Start with loading a list of your first 10 servers:

client.get_servers(count: 10)

# => [{:id=>1, :name=>"postmark", :api_tokens=>[...], :color=>"blue", :smtp_api_activated=>false, :raw_email_enabled=>false, :inbound_address=>"...", :inbound_hook_url=>"", :bounce_hook_url=>"", :inbound_domain=>"", :inbound_hash=>"..."}] 

You can also access the full servers list using a handy enumerator:

client.servers.take(3).map { |s| s[:id] }
# => [1]

Delete a server

client.delete_server(2)

# => {:error_code=>0, :message=>"Server Server 2 removed."}