team-telnyx / telnyx-dotnet

.NET SDK for the Telnyx API
MIT License
9 stars 9 forks source link

NumberLookupService incorrectly formatting URL for Type #79

Open jaimefuhr opened 8 months ago

jaimefuhr commented 8 months ago

The NumberLookupService never returns carrier or caller-name information despite providing the Type in NumberLookupRecordOptions.

The type is included in the URL as JSON instead of a name-value pair:

Invalid URL generated by Service.ApplyAllParameters method:

https://api.telnyx.com/v2/number_lookup/%2B18665552368?{"type":"carrier"}

Correct URL:

https://api.telnyx.com/v2/number_lookup/%2B18665552368?type=carrier

The invalid URL will return a 200 but NO carrier information. Likewise if type is set to caller-name, that data is null.

var number = "+118665552368";
var request = new RequestOptions();
request.ApiKey = APIKey;

var lookupOptions = new NumberLookupRecordOptions {
    Type = "carrier"
};

var lookup = new NumberLookupService();
var response = lookup.Get(number, lookupOptions, request);

Response:
{
  "data":{
    "country_code":"US",
    "national_format":"(866) 555-2368",
    "phone_number":"+18665552368",
    "fraud":null,
    "carrier":null,
    "caller_name":null,
    "nnid_override":null,
    "portability":{
      "lrn":null,
      "ported_status":"",
      "ported_date":"",
      "ocn":null,
      "line_type":"",
      "spid":"",
      "spid_carrier_name":null,
      "spid_carrier_type":"",
      "altspid":"",
      "altspid_carrier_name":"",
      "altspid_carrier_type":"",
      "city":"",
      "state":""
    },
    "valid_number":true,
    "record_type":"number_lookup"
  }
}

The workaround is to not set the Type property in NumberLookupRecordOptions and use the ExtraParams property:

options.ExtraParams.Add("type", "carrier");
//options.ExtraParams.Add("type","caller-name");