Loading...

Ruby Setup


To invoke the API using Ruby, first install a REST client such as: rest-client

gem install rest-install

Step 1: Configure the REST client to POST the request

Use HTTP BASIC Authentication

Username: {Login}

Password: {Password}


Set the HTTP headers

Accept: application/json

Content-Type: application/json


Construct the JSON body

{
 "ChannelIds": 22,
 "Targets": ["+1{PhoneNumber}"],
 "Message": "Welcome to mobile club!",
 "Execute": "true" 
}

Step 2: Push the Campaign

Create a file named push_campaign.rb with the Ruby code provided below. Replace {Login}, {Password}, {AccountId}and {PhoneMumber} with valid values. Run the code to push the campaign.

require 'base64'
require 'rest_client'

def mobile_club(login, password, accountID, channelID, phone_number)
    targets = phone_number.gsub(/[^0-9]/, "")
    if targets.length != 10
      puts "Please enter a valid 10 digit phone number"
      return
    end
    targets = [ "+1#{targets}" ]
     
    auth = "Basic " + Base64.encode64( "#{login}:#{password}" ).chomp
 
    begin
        response = RestClient.post "https://api.3seventy.com/api/v2.1/account/#{accountID}/action-pushcampaign",
                { 
                        :ChannelIds => channelID, 
                        :Targets => targets, 
                        :Message => "Welcome to mobile club!",
                        :Execute => "true"
                }, :content_type => :json, :accept => :json, :Authorization => auth
        
        puts "Thank you for signing up for the mobile club!"
    rescue => e
      puts "Mobile Club signup failed: HTTP #{e.response.code} #{e.response.to_s}"
    end
end

# Replace {Login}, {Password}, {AccountId} and {PhoneMumber} with valid values
mobile_club("{Login}","{Password}",{AccountID},22,"{PhoneMumber}")