Created
April 5, 2016 17:16
-
-
Save jbender/477afc6cdc48c5b70d514369459b27f8 to your computer and use it in GitHub Desktop.
Getting Started with Contactually API v2 - Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response = client.get '/v2/me' | |
puts response.body |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contact_attributes = { | |
first_name: 'Jonathan', | |
last_name: 'Bender', | |
email: '[email protected]' | |
} | |
# 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