Skip to content

Instantly share code, notes, and snippets.

@jbender
Created April 5, 2016 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbender/477afc6cdc48c5b70d514369459b27f8 to your computer and use it in GitHub Desktop.
Save jbender/477afc6cdc48c5b70d514369459b27f8 to your computer and use it in GitHub Desktop.
Getting Started with Contactually API v2 - Ruby
require 'faraday'
require 'faraday_middleware'
client = Faraday.new(
url: 'https://api.contactually.com',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN_HERE'
}
) do |connection|
connection.response :json, :content_type => 'application/json'
connection.adapter Faraday.default_adapter
end
response = client.get '/v2/me'
puts response.body
contact_attributes = {
first_name: 'Jonathan',
last_name: 'Bender',
email: 'jbender@contactually.com'
}
# Create the contact
contact = client.post('/v2/contacts', body: { data: contact_attributes}).body['data']
# Get the available buckets
buckets = client.get('/v2/buckets').body['data']
# Add the bucket to the created contact
new_buckets = [{ id: buckets.first['id'] }]
client.post("/v2/contacts/#{contact['id']}/buckets", body: { data: new_buckets })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment