plivo / plivo-php

Plivo PHP Helper Library
http://www.plivo.com
MIT License
110 stars 117 forks source link

Unable to search phone numbers #232

Closed awais-vteams closed 3 years ago

awais-vteams commented 3 years ago

Getting exception Exception 'Plivo\Exceptions\PlivoResponseException' with message ''

I am calling this code to search available phone numbers

$object = $this->client
            ->phonenumbers
            ->list('US', [
                'type' => 'fixed',
                'services' => 'voice,sms',
            ]);

It is because https://github.com/plivo/plivo-php/blob/master/src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php#L62 you are checking the error key but it's getting even in the success response.

awais-vteams commented 3 years ago

here is the response I am getting

Array
(
    [api_id] => *********
    [error] =>
    [meta] => Array
        (
            [limit] => 20
            [next] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/?limit=20&offset=20&services=voice,sms&type=fixed&country_iso=US
            [offset] => 0
            [previous] =>
            [total_count] => 7086
        )

    [objects] => Array
        (
            [0] => Array
                (
                    [city] => Grants Pass
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 670
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15417872041
                    [prefix] => 541
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Grants Pass
                    [region] => Oregon
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15417872041/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [1] => Array
                (
                    [city] => Pendleton
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 672
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15419707159
                    [prefix] => 541
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Pendleton
                    [region] => Oregon
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15419707159/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [2] => Array
                (
                    [city] => Chalfont
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 228
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 12679568064
                    [prefix] => 267
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Line Lexington
                    [region] => Pennsylvania
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/12679568064/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [3] => Array
                (
                    [city] => Milano
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 558
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15128127170
                    [prefix] => 512
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Milano
                    [region] => Texas
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15128127170/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [4] => Array
                (
                    [city] => Denton
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 424
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 13364902050
                    [prefix] => 336
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Denton
                    [region] => North Carolina
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/13364902050/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [5] => Array
                (
                    [city] => Wayne-Bradner
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 326
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 14192888175
                    [prefix] => 419
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Wayne-Bradner
                    [region] => Ohio
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/14192888175/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [6] => Array
                (
                    [city] => O'Brien
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 670
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15415964073
                    [prefix] => 541
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => O Brien
                    [region] => Oregon
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15415964073/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [7] => Array
                (
                    [city] => Palmer
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 552
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 19724498185
                    [prefix] => 972
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Palmer
                    [region] => Texas
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/19724498185/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [8] => Array
                (
                    [city] => Genoa
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 644
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 14029488167
                    [prefix] => 402
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Genoa
                    [region] => Nebraska
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/14029488167/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [9] => Array
                (
                    [city] => Olympia
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 674
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15644644064
                    [prefix] => 564
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Olympia
                    [region] => Washington
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15644644064/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [10] => Array
                (
                    [city] => Coos Bay
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 670
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15419823109
                    [prefix] => 541
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Coos Bay
                    [region] => Oregon
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15419823109/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [11] => Array
                (
                    [city] => Paden City
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 256
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 13043174002
                    [prefix] => 304
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Paden City
                    [region] => West Virginia
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/13043174002/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [12] => Array
                (
                    [city] => Philadelphia Zone 4
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 228
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 12157709476
                    [prefix] => 215
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Philadelphia Zone 4
                    [region] => Pennsylvania
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/12157709476/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [13] => Array
                (
                    [city] => Scottsville
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 462
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 12702666092
                    [prefix] => 270
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Scottsville
                    [region] => Kentucky
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/12702666092/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [14] => Array
                (
                    [city] => Anaheim
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 730
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 17144222774
                    [prefix] => 714
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Anaheim
                    [region] => California
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/17144222774/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [15] => Array
                (
                    [city] =>
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] =>
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 17035527899
                    [prefix] => 703
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Dulles Metro
                    [region] => Virginia
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/17035527899/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [16] => Array
                (
                    [city] => Richton
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 482
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 16019126363
                    [prefix] => 601
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Richton
                    [region] => Mississippi
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/16019126363/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [17] => Array
                (
                    [city] => Jefferson
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 670
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 15412097079
                    [prefix] => 541
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Jefferson
                    [region] => Oregon
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/15412097079/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [18] => Array
                (
                    [city] => Julian
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 958
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 14022424198
                    [prefix] => 402
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Julian
                    [region] => Nebraska
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/14022424198/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

            [19] => Array
                (
                    [city] => Pilot Mountain
                    [compliance_requirement] => Array
                        (
                            [business] =>
                            [individual] =>
                        )

                    [country] => UNITED STATES
                    [lata] => 424
                    [mms_enabled] => 1
                    [mms_rate] => 0.00500
                    [monthly_rental_rate] => 0.08000
                    [number] => 13364449842
                    [prefix] => 336
                    [prerequisites] => Array
                        (
                        )

                    [rate_center] => Pilot Mountain
                    [region] => North Carolina
                    [resource_uri] => /v1/Account/SANDE4NGVLNDITZDQ5YY/PhoneNumber/13364449842/
                    [restriction] =>
                    [restriction_text] =>
                    [setup_rate] => 0.00000
                    [sms_enabled] => 1
                    [sms_rate] => 0.00000
                    [sub_type] => local
                    [type] => fixed
                    [voice_enabled] => 1
                    [voice_rate] => 0.00300
                )

        )

)
IronSinew commented 3 years ago

https://github.com/plivo/plivo-php/blob/master/src/Plivo/Resources/PhoneNumber/PhoneNumberInterface.php#L62

image

The response is now including an error value, even if it's a "good" response with proper data, so the SDK is throwing the exception regardless because the key exists. Either this should be using empty() in the "PhoneNumberInterface" (also, that's not a real interface?) or it shouldn't be included in the response because it's causing the PHP SDK to throw exceptions when it shouldn't be.

huzaif-plivo commented 3 years ago

@awais-vteams @IronSinew Thank you for the feedback! We would like to inform you that we have fixed this in our latest release. In case of any queries, please feel free to contact our support-team.