Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency between GuzzleClient and Twilio's CurlClient for GET parameters #752

Closed
trevorgehman opened this issue Dec 5, 2022 · 2 comments
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@trevorgehman
Copy link

Issue Summary

When using the GuzzleClient instead of the CurlClient, in some cases the GET parameters are not passed properly when making API calls according to Twilio documentation.

Steps to Reproduce

Inside the documentation it says we are to make the API call for looking up a phone number's carrier as follows:

$phone_number = $twilio->lookups->v1->phoneNumbers("+15108675310")
                                    ->fetch([
                                                "type" => ["carrier"]
                                            ]
                                    );

https://www.twilio.com/docs/lookup/quickstart?code-sample=code-lookup-with-national-formatted-number-1&code-language=PHP&code-sdk-version=6.x

The result returned is what you expect:

{
  "caller_name": null,
  "carrier": {
    "error_code": null,
    "mobile_country_code": "310",
    "mobile_network_code": "456",
    "name": "verizon",
    "type": "mobile"
  },
  "country_code": "US",
  "national_format": "(510) 867-5310",
  "phone_number": "(510)867-5310",
  "add_ons": null,
  "url": "https://lookups.twilio.com/v1/PhoneNumbers/+15108675310?Type=carrier"
}

However, if you use the GuzzleClient and make the same request, the response is different:

$twilio = new Client($sid, $token, new GuzzleClient);

$phone_number = $twilio->lookups->v1->phoneNumbers("+15108675310")
                                    ->fetch([
                                                "type" => ["carrier"]
                                            ]
                                    );
{
  "caller_name": null,
  "carrier": null,
  "country_code": "US",
  "national_format": "(510) 867-5310",
  "phone_number": "(510)867-5310",
  "add_ons": null,
  "url": "https://lookups.twilio.com/v1/PhoneNumbers/+15108675310"
}

Notice the "carrier" is null here instead of being an array, and the "url" is missing the ?Type=carrier portion. For some reason, the client is not passing the "type" GET parameter properly. To correct it, you can pass a string instead of an array for the "type" parameter, like so:

$twilio = new Client($sid, $token, new GuzzleClient);

$phone_number = $twilio->lookups->v1->phoneNumbers("+15108675310")
                                    ->fetch([
                                                "countryCode" => "US",
                                                "type" => "carrier"
                                            ]
                                    );

This is either a mistake in the documentation, or a mistake in the implementation of the GuzzleClient.

Technical details:

  • twilio-php version: 6.43.4
  • php version: 8.1.8
@charan678 charan678 added the type: bug bug in the library label Dec 7, 2022
@charan678
Copy link
Contributor

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@charan678 charan678 added the status: help wanted requesting help from the community label Dec 7, 2022
@hivokas
Copy link

hivokas commented Dec 7, 2022

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@charan678 +1. Twilio documentation has inconsistency.

cURL:

curl -X GET "https://lookups.twilio.com/v1/PhoneNumbers/(510)867-5310?CountryCode=US&Type=carrier" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

PHP:

<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$phone_number = $twilio->lookups->v1->phoneNumbers("(510)867-5310")
                                    ->fetch([
                                                "countryCode" => "US",
                                                "type" => ["carrier"]
                                            ]
                                    );

print($phone_number->carrier);

As you can see, type is string in cURL example, but array in PHP example. What's expected here: string or array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

4 participants