Closed AxelTheGerman closed 2 years ago
Somehow I seem to be getting weird results with either PostalCode
or InPostalCode
😭
Hi @AxelTheGerman , thanks for opening a github issues. While trying to recreate your issue, we believe that this is the library expected behavior. The library only returns exact matches, as there are no available numbers under postal code l5b3z3 nor locality Vancouver, hence it's returning an empty array.
Looking at the results from the CURL request, the api returns the number from the same country but not necessarily the exact postal code/locality.
Yes, thank you for looking into this @claudiachua !
I think I need to bring this back to support as it's not the fault of the Ruby SDK but in general the API behaves differently from the Twilio Console "Buy a number"
Just to document this here in case others have similar issues:
Vancouver
numbers from Ruby:client.available_phone_numbers('CA').local.list(in_locality: 'Vanco
uver')
=> []
Vancouver
numbers from CURL:$ curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/CA/Local.json?InLocality=Vancouver&PageSize=20' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
{"available_phone_numbers": [], "uri": "/2010-04-01/Accounts/AC891d08c136b401ce1a77b90924a2da4e/AvailablePhoneNumbers/CA/Local.json?PageSize=20&InLocality=Vancouver"}
Note: changing the InLocality
argument to Locality
does - as you mentioned - simply return random Canadian numbers as it's an invalid argument and therefore doesn't filter the numbers at all.
Vancouver
in Twilio Console:☝️ this does give me a whole bunch of numbers in the Vancouver area that I'm not getting via the API
2.7.5 :006 > numbers = client.available_phone_numbers('CA').local.list(contains:
'2367085606')
=> [<Twilio.Api.V2010.LocalInstance>]
2.7.5 :007 > numbers.first.phone_number
=> "+12367085606"
2.7.5 :008 > numbers.first.locality
=> "West Vancouver"
> client.available_phone_numbers('CA').local.list(in_locality: 'West
Vancouver')
=> [<Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>, <Twilio.Api.V2010.LocalInstance>]
So TLDR when I search on twilio.com/console for "Vancouver" I'm getting numbers (expected) when I search via the API I don't - this is not expected but will take it up with support as this is the same for Ruby SDK and CURL
Issue Summary
I am trying to search available phone numbers by postal code and locality and am not getting any results.
I believe this is due to wrong parameter names here: https://github.com/twilio/twilio-ruby/blob/a2033d3eaa3f9899b1d7886615ed70e5a0c5af5e/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/local.rb#L304
And here https://github.com/twilio/twilio-ruby/blob/a2033d3eaa3f9899b1d7886615ed70e5a0c5af5e/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/local.rb#L308
Thanks for looking into this, some other params such as region and lata seem to work but might be worth double checking all of them.
Steps to Reproduce
Use the API directly (via curl) to verify numbers are available - with correct parameter name
PostalCode
$ curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/CA/Local.json?PostalCode=l5b3z3&PageSize=1' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Returned numbers:
Use the API with the parameter name used in the gem -
InPostalCode
$ curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/CA/Local.json?InPostalCode=l5b3z3&PageSize=1' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
No numbers are returned
I'm having the same issue for
InLocality
vsLocality
:$ curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/CA/Local.json?InLocality=Vancouver&PageSize=1' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
$ curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_ACCOUNT_SID'/AvailablePhoneNumbers/CA/Local.json?Locality=Vancouver&PageSize=1' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Code Snippet
Using
postal_code
orlocality
results inArgumentError (unknown keyword: :postal_code)
Exception/Log
n/a
Technical details: