twilio / twilio-ruby

A Ruby gem for communicating with the Twilio API and generating TwiML
MIT License
1.35k stars 462 forks source link

Unable to POST to `tollfree_verifications.create` - getting missing parameter even though it is included #674

Open dodontommy opened 12 months ago

dodontommy commented 12 months ago

Issue Summary

When trying to submit a tollfree_verification through the Ruby SDK, I get Missing required parameter *param* in the post body for any array params, so for OptInImageUrls and UseCaseCategories, even though those params are included and are of type Array. I am doing this through a sub account - by initializing the Twilio::REST::Client like so @sub_account_client ||= Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN, sub_account_sid).

I've also embedded some output in twilio-ruby-6.5.0/lib/twilio-ruby/rest/messaging/v1/tollfree_verification.rb in the create and I can see that the OptInImageUrls and UseCaseCategories are present there.

Steps to Reproduce

  1. Initialize client with a sub account SID
  2. Call client.messaging.v1.tollfree_verifications.create(params)

Code Snippet

def sub_account_client
  @sub_account_client ||= Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN, sub_account_sid)
end

USE_CASE_SUMMARY = 'Foo bar'
PRODUCTION_MESSAGE_SAMPLE_1 = "EXAMPLE 1 STOP TO OPT OUT"
PRODUCTION_MESSAGE_SAMPLE_2 = "EXAMPLE 2 STOP TO OPT OUT"
OPT_IN_IMAGE_URLS = ['valid_image_url', 'valid_image_url_2', 'valid_image_url_3'].freeze
sub_account_client.messaging.v1.tollfree_verifications.create(
  business_street_address: verification_params[:street],
  business_street_address2: verification_params[:street_2],
  business_city: verification_params[:city],
  business_state_province_region: verification_params[:state],
  business_postal_code: verification_params[:zip_code],
  business_country: verification_params[:country],
  business_contact_first_name: verification_params[:first_name],
  business_contact_last_name: verification_params[:last_name],
  business_contact_email: verification_params[:email],
  business_contact_phone: verification_params[:phone_number],
  additional_information: verification_params[:additional_information],
  business_name: verification_params[:business_name],
  business_website: verification_params[:business_website],
  notification_email: 'it@foo.net',
  use_case_categories: ['ACCOUNT_NOTIFICATIONS','EVENTS'],
  use_case_summary: USE_CASE_SUMMARY,
  production_message_sample: [PRODUCTION_MESSAGE_SAMPLE_1, PRODUCTION_MESSAGE_SAMPLE_2].join('; '),
  opt_in_image_urls: OPT_IN_IMAGE_URLS,
  opt_in_type: 'WEB_FORM',
  message_volume: '1,000',
  tollfree_phone_number_sid: phone_number_sid
)

Exception/Log

/app/vendor/bundle/ruby/2.7.0/gems/twilio-ruby-6.5.0/lib/twilio-ruby/framework/rest/version.rb:146:in `create': [HTTP 400] 20001 : Unable to create record (Twilio::REST::RestError)
Missing required parameter OptInImageUrls in the post body
https://www.twilio.com/docs/errors/20001

Or when just sending a single string for OptInImageUrls:

/app/vendor/bundle/ruby/2.7.0/gems/twilio-ruby-6.5.0/lib/twilio-ruby/framework/rest/version.rb:146:in `create': [HTTP 400] 20001 : Unable to create record (Twilio::REST::RestError)
Missing required parameter UseCaseCategories in the post body
https://www.twilio.com/docs/errors/20001

Faraday Request

I, [2023-08-29T14:12:53.062589 #41]  INFO -- request: POST https://messaging.twilio.com/v1/Tollfree/Verifications
I, [2023-08-29T14:12:53.062668 #41]  INFO -- request: User-Agent: "twilio-ruby/6.3.0 (linux-gnu x86_64) Ruby/2.7.2"
Accept-Charset: "utf-8"
Content-Type: "application/x-www-form-urlencoded"
Accept: "application/json"
I, [2023-08-29T14:12:53.063234 #41]  INFO -- request: {"BusinessName"=>"FOO BAR",
 "BusinessWebsite"=>"https://www.foo.com/",
 "NotificationEmail"=>"it@foo.net",
 "UseCaseCategories"=>["ACCOUNT_NOTIFICATIONS", "EVENTS"],
 "UseCaseSummary"=>
  "This is our use case",
 "ProductionMessageSample"=>
  "These are our production message samples,
 "OptInImageUrls"=>
  ["https://i.imgur.com/valid_id_1.png",
   "https://i.imgur.com/valid_id_2.png",
   "https://i.imgur.com/valid_id_3.png"],
 "OptInType"=>"WEB_FORM",
 "MessageVolume"=>"1,000",
 "TollfreePhoneNumberSid"=>"tollfreesid",
 "BusinessStreetAddress"=>"123 Test",
 "BusinessStreetAddress2"=>nil,
 "BusinessCity"=>"Test City",
 "BusinessStateProvinceRegion"=>"KS",
 "BusinessPostalCode"=>"11111",
 "BusinessCountry"=>"US",
 "AdditionalInformation"=>nil,
 "BusinessContactFirstName"=>"First",
 "BusinessContactLastName"=>"Name",
 "BusinessContactEmail"=>"foo@bar.net",
 "BusinessContactPhone"=>"5555555555"}

I, [2023-08-29T14:12:53.099626 #41]  INFO -- response: Status 400
I, [2023-08-29T14:12:53.099702 #41]  INFO -- response: date: "Tue, 29 Aug 2023 14:12:53 GMT"
content-type: "application/json; charset=utf-8"
content-length: "160"
connection: "keep-alive"
twilio-request-id: "RQ255024230fbe1ade3b571cd12d7ac195"
twilio-request-duration: "0.004"
access-control-allow-origin: "*"
access-control-allow-headers: "Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Idempotency-Key"
access-control-allow-methods: "GET, POST, DELETE, OPTIONS"
access-control-expose-headers: "ETag"
access-control-allow-credentials: "true"
x-powered-by: "AT-5000"
strict-transport-security: "max-age=31536000"
twilio-concurrent-requests: "1"
x-shenanigans: "none"
x-home-region: "us1"
x-api-domain: "messaging.twilio.com"
I, [2023-08-29T14:12:53.099743 #41]  INFO -- response: {"code": 20001, "message": "Missing required parameter OptInImageUrls in the post body", "more_info": "https://www.twilio.com/docs/errors/20001", "status": 400}

Technical details: