Skip to content

sendx/sendx-api-ruby

Repository files navigation

Ruby SendX API

NOTE: All API calls contain 2 parameters - 'api_key' and 'team_id'. These can be inferred from your settings page 'https://app.sendx.io/setting' under the sections 'Api Key' and 'Team Id' respectively.

SendX API has two methods:

Identify API Method

Identify API Method is used to attach data to a visitor. If a contact is not yet created then we will create the contact. In case contact already exists then we update it.

Example Request:

{
  email: "john.doe@gmail.com",  
  firstName: "John",
  lastName: "Doe",
  birthday: "1989-03-03",
  customFields: { "Designation": "Software Engineer", "Age": "27", "Experience": "5"},  
  tags: ["Developer", "API Team"],  
 }

Note that tags are an array of strings. In case they don't exist previously then API will create them and associate them with the contact.

Similarly if a custom field doesn't exist then it is first created and then associated with the contact along-with the corresponding value. In case custom field exists already then we simply update the value of it for the aforementioned contact.

We don't delete any of the properties based on identify call. What this means is that if for the same contact you did two API calls like:

API Call A

{
   email: "john.doe@gmail.com", 
   firstName: "John",
   birthday: "1989-03-03",
   customFields: { "Designation": "Software Engineer"},  
   tags: ["Developer"],  
}

API Call B

{  
  email: "john.doe@gmail.com",  
  customFields: { "Age": "29"},  
  tags: ["API Team"],  
}

The final contact will have firstName as John, birthday as 1989-03-03 present. Also both tags Developer and API Team shall be present alongwith custom fields Designation and Age.

Properties:

  • firstName: type string
  • lastName: type string
  • email: type string
  • newEmail: type string
  • company: type string
  • birthday: type string with format YYYY-MM-DD eg: 2016-11-21
  • customFields: type map[string]string
  • tags: type array of string

In case email of an already existing contact needs to be updated then specify current email under email property and updated email under newEmail property.

Response:

{ "status": "200", "message": "OK", "data": { "encryptedTeamId": "CLdh9Ig5GLIN1u8gTRvoja", "encryptedId": "c9QF63nrBenCaAXe660byz", "tags": [ "API Team", "Tech" ], "firstName": "John", "lastName": "Doe", "email": "john.doe@gmail.com", "company": "", "birthday": "1989-03-03", "customFields": { "Age": "29", "Designation": "Software Engineer" } } }

Track API Method

Track API Method is used to track a contact. In the track API object you can:

  • addTags:
  • removeTags:

You can have automation rules based on tag addition as well as tag removal and they will get executed. For eg:

  • On user registration tag start onboarding drip for him / her.
  • Account Upgrade tag start add user to paid user list and start account expansion drip.
  • On removal of trial user tag start upsell trial completed users drip.

Example Request:

{ "addTags": ["blogger", "female"] }

{ "addTags": ["paid user"], "removeTags": ["trial user"] }

Response:

{ "status": "200", "message": "OK", "data": "success" }

This SDK is automatically generated by the Swagger Codegen project:

  • API version: v1
  • Package version: 1.0.0
  • Build package: class io.swagger.codegen.languages.RubyClientCodegen

Installation

Build a gem

To build the Ruby code into a gem:

gem build swagger_client.gemspec

Then either install the gem locally:

gem install ./swagger_client-1.0.0.gem

(for development, run gem install --dev ./swagger_client-1.0.0.gem to install the development dependencies)

or publish the gem to a gem hosting service, e.g. RubyGems.

Finally add this to the Gemfile:

gem 'swagger_client', '~> 1.0.0'

Install from Git

If the Ruby gem is hosted at a git repository: https://github.com/YOUR_GIT_USERNAME/YOUR_GIT_REPO, then add the following in the Gemfile:

gem 'swagger_client', :git => 'https://github.com/YOUR_GIT_USERNAME/YOUR_GIT_REPO.git'

Include the Ruby code directly

Include the Ruby code directly using -I as follows:

ruby -Ilib script.rb

Getting Started

Please follow the installation procedure and then run the following code:

# Load the gem
require 'swagger_client'

api_instance = SwaggerClient::ContactApi.new

api_key = "api_key_example" # String | 

team_id = "team_id_example" # String | 

contact_details = SwaggerClient::ContactRequest.new # ContactRequest | Contact details
contact_details.email = "rubyapi@sendx.io"


begin
  #Identify a contact as user
  result = api_instance.contact_identify_post(api_key, team_id, contact_details)
  p result
rescue SwaggerClient::ApiError => e
  puts "Exception when calling ContactApi->contact_identify_post: #{e}"
end


track_details = SwaggerClient::TrackRequest.new # TrackRequest | Track details
track_details.add_tags = ["paid user", "startup plan"]
track_details.remove_tags = ["trial user"]


begin
  #Track a contact
  result = api_instance.contact_track_post(api_key, team_id, "rubyapi@sendx.io", track_details)
  p result
rescue SwaggerClient::ApiError => e
  puts "Exception when calling ContactApi->contact_track_post: #{e}"
end

Documentation for API Endpoints

All URIs are relative to http://app.sendx.io/api/v1

Class Method HTTP request Description
SwaggerClient::ContactApi contact_identify_post POST /contact/identify Identify a contact as user
SwaggerClient::ContactApi contact_track_post POST /contact/track Add tracking info using tags to a contact

Documentation for Models

Documentation for Authorization

All endpoints do not require authorization.

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •