Sorry, you need to enable JavaScript to visit this website.

You are here

When Using The Ruby SDK I'm Getting a "Bad request" Error

2 posts / 0 new
Last post

thoran's picture
by thoran

When Using The Ruby SDK I'm Getting a "Bad request" Error

The following (not the prettiest code): ... 


def deliver raise unless content && phone_number begin authentication_api_instance = Telstra_Messaging::AuthenticationApi.new p access_token = authentication_api_instance.auth_token(api_key, api_secret, grant_type) p access_token.access_token rescue Telstra_Messaging::ApiError => e puts "Exception when calling AuthenticationApi->auth_token: #{e}" return end Telstra_Messaging.configure do |config| config.access_token = access_token.access_token end message_segments.each do |message_segment| begin p send_sms_request = Telstra_Messaging::SendSMSRequest.new send_sms_request.to = phone_number send_sms_request.body = message_segment @responses << messaging_api_instance.send_sms(send_sms_request) rescue Telstra_Messaging::ApiError => e puts "Exception when calling MessagingApi->send_sms: #{e}" end end p @responses p messaging_api_instance.get_sms_status(message_id) if delivered? {success: true} else {failure: true} end end 

Produces:

# "8uWKZclyhE71c2bvuMJu6jRtwyg1" # Exception when calling MessagingApi->send_sms: Bad Request [] Traceback (most recent call last): 6: from /Users/thoran/bin/sms:52:in `' 5: from /Users/thoran/bin/sms:39:in `main' 4: from /Users/thoran/lib/ruby/SMS.rb:42:in `deliver' 3: from /Users/thoran/lib/ruby/SMS/Service/Telstra.rb:75:in `deliver' 2: from /Users/thoran/.gem/ruby/2.5.3/gems/Telstra_Messaging-1.0.6.2/lib/Telstra_Messaging/api/messaging_api.rb:80:in `get_sms_status' 1: from /Users/thoran/.gem/ruby/2.5.3/gems/Telstra_Messaging-1.0.6.2/lib/Telstra_Messaging/api/messaging_api.rb:114:in `get_sms_status_with_http_info' /Users/thoran/.gem/ruby/2.5.3/gems/Telstra_Messaging-1.0.6.2/lib/Telstra_Messaging/api_client.rb:65:in `call_api': Bad Request (Telstra_Messaging::ApiError) 

Not sure what's going wrong. I have followed the Ruby SDK examples and think I'm doing everything OK at my end. Ideas?

 

DeveloperSteve's picture
by DeveloperSteve

Hi Bulk

Heres some sample code that might help, did you provision a number on the api keys first?

require 'Telstra_Messaging'

api_instance = Telstra_Messaging::AuthenticationApi.new

client_id = "" # String | 

client_secret = "" # String | 

grant_type = "client_credentials" # String | 

result = api_instance.auth_token(client_id, client_secret, grant_type)

Telstra_Messaging.configure do |config|
  # Configure OAuth2 access token for authorization: auth
  config.access_token = result.access_token
end

api_instance = Telstra_Messaging::ProvisioningApi.new

#activate number 
arr = {'activeDays' => 10}

body = Telstra_Messaging::ProvisionNumberRequest.new(arr)

result = api_instance.create_subscription(body)
p result


api_instance = Telstra_Messaging::MessagingApi.new

arr = {'to': 'mobile number', 'body' => 'hello world'};

payload = Telstra_Messaging::SendSMSRequest.new(arr)

result = api_instance.send_sms(payload)
p result

 

Log in or register to post comments