doesRegistrationCellNumberExist API
Description
The doesRegistrationCellNumberExist API call is used to check whether or not a cell number has been registered with TextKey
API Testing Page
To test the doesRegistrationCellNumberExist API Call in a fully interactive environment, click here.
Input Parameters
Name | Data Type | Description | Required |
---|---|---|---|
apiKey | String | This is a unique key that is used to authenticate an API request. It should never be exposed. | Yes |
cellNumber | String | The Cell Number or Cell Number proxy that was used when the user was registered with TextKey |
Yes |
Output
Name | Data Type | Description |
---|---|---|
cellNumberCount | Integer | The count of Cell Numbers on this account that match. This count is normally 0 or 1. ). If an error is detected, the cellNumberCount will be -2. |
errorDescr | String | If a error occurs, this is the error message. This will be blank if the call was successful. |
REST Example
RESTful URL
The TextKey
For instance:
https://secure.textkey.com/REST/TKRest.asmx/CommandName
The CommandName is the API call itself which in this case is doesRegistrationCellNumberExist.
Here is what the complete URL for this API call would look like:
https://secure.textkey.com/REST/TKRest.asmx/doesRegistrationCellNumberExist
All Restful calls must be made using the POST method and should be of the content type application/json.
Here is an example of what a request header should look like:
POST /REST/TKRest.asmx/doesRegistrationCellNumberExist HTTP/1.1
Host: secure.textkey.com
Accept: */*
Content-Type:application/json
Content-Length: 118
JSON Input Payload
All TextKey
The JSON Input payload for the doesRegistrationCellNumberExist API call should look something like this:
{
"DataIn": {
"apiKey": "9021fa44-f1bc-4590-b975-42fee031e078",
"cellNumber": "8181231234"
}
}
JSON Output Payload
The JSON response should look something like this:
JSON Response with a valid payload
{
"d":{
"__type":"TextKeyCommon.TKStructures+RegistrationExistence",
"cellNumberCount":1,
"userIDCount":-2,
"errorDescr":""
}
}
__type: TextKeyCommon.TKStructures+RegistrationExistence
cellNumberCount: 1
userIDCount: -2
errorDescr:
OR
JSON Response with an error
{
"d":{
"__type":"TextKeyCommon.TKStructures+RegistrationExistence",
"cellNumberCount":0,
"userIDCount":0,
"errorDescr":"No GUID Validation Row: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."
}
}
Error: No GUID Validation Row: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
REST Code Examples
PHP
Example 1 - Using the TextKey PHP Helper Library
The simplest way to use TextKey
You will be returned a PHP object and can reference all of the payload values directly from that object.
// Include the TextKey classes include_once("textkey_rest.php"); // Setup the API call parameters $cellnumber = "8181231234"; // Set the authentication $apikey = "9021fa44-f1bc-4590-b975-42fee031e078"; // Create a TK object $tk = new textKey($apikey); // Handle the operation $textkey_result = $tk->perform_DoesRegistrationCellNumberExist($cellnumber); // Handle the results if ($textkey_result->errorDescr == "") { $tkResultsArr = get_object_vars($textkey_result); $results = ""; foreach($tkResultsArr as $key => $value) { if (is_array($value)) { $results .= $key . ': ' . var_export($value, true) . "
";; } else if (is_object($value)) { $results .= $key . ': ' . print_r($value, true); } else { $results .= $key . ': ' . $value . "
";; } } echo $results; } else { $results = 'Error: ' . $textkey_result->errorDescr . "
"; echo $results; }
Here is an example of the PHP object returned:
stdClass Object
(
[__type] => TextKeyCommon.TKStructures+RegistrationExistence
[cellNumberCount] => 1
[userIDCount] => -2
[errorDescr] =>
)
Example 2 - Using the REST API Call directly
In order to use the TextKey
The POST header does need to be setup as a JSON request (i.e. an application/json header) or you will not get a response.
You will be returned a JSON string as the API call payload. That can be converted into a PHP object using the json_decode call.
// TextKey REST path define('TK_REST', 'https://secure.textkey.com/REST/TKRest.asmx/'); // Setup the API call parameters $cellnumber = "8181231234"; // Set the authentication $apikey = "9021fa44-f1bc-4590-b975-42fee031e078"; // Build the REST API URL $url = TK_REST . 'doesRegistrationCellNumberExist'; // Setup data $postdata = json_encode( array('DataIn' => array( 'apiKey' => urlencode($apikey), 'cellNumber' => urlencode($cellnumber) ) ), JSON_PRETTY_PRINT); // Handle the API request via CURL $curl = curl_init($url); // Set the CURL params and make sure it is a JSON request curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Wildcard certificate $response = curl_exec($curl); curl_close($curl); // Handle the payload $textkey_payload = json_decode($response); if ($textkey_payload->d) { $textkey_result = $textkey_payload->d; } else { $textkey_result = $textkey_payload; }; // Handle the results if ($textkey_result->errorDescr == "") { $tkResultsArr = get_object_vars($textkey_result); $results = ""; foreach($tkResultsArr as $key => $value) { if (is_array($value)) { $results .= $key . ': ' . var_export($value, true) . "
";; } else if (is_object($value)) { $results .= $key . ': ' . print_r($value, true); } else { $results .= $key . ': ' . $value . "
";; } } echo $results; } else { $results = 'Error: ' . $textkey_result->errorDescr . "
"; echo $results; }
JAVA
Example - Using the TextKey JAVA Helper Library
The simplest way to use TextKey
You will be returned a JSON string.
package com.textkey.rest.examples; import org.json.JSONObject; import com.textkey.rest.TextKeyRest; public class TestDoesRegistrationCellNumberExist { public static void main(String[] args) { /* Setup */ String TK_API = "9021fa44-f1bc-4590-b975-42fee031e078"; /* Create the TextKey object */ TextKeyRest textkey = new TextKeyRest(TK_API, false); /* Setup the API call parameters */ String CellNumber = "8181231234"; /* Make the REST API Call */ String JSONpayload = textkey.perform_DoesRegistrationCellNumberExist(CellNumber); /* Display the API Results */ try { JSONObject results = new JSONObject(JSONpayload).getJSONObject("d"); System.out.println("Test Results: \n" + TextKeyRest.toPrettyFormat(results.toString())); } catch(Exception pe){ pe.printStackTrace(); } } }
Here is an example of the JSON string with the d wrapper removed:
Test Results:
{
"__type": "TextKeyCommon.TKStructures+RegistrationExistence",
"cellNumberCount": 1,
"errorDescr": "",
"userIDCount": -2
}
NOTE: For more detais on the JAVA Library object and methods, you can take a look at the online documentation at http://textpower.github.io/RESTLibrary-java/.
RUBY
Example - Using the TextKey RUBY Helper Library
The simplest way to use TextKey
You will be returned a JSON string.
NOTE: To install the textkey_rest gem you can run gem install textkey_rest from a command line. To build the testkey_rest gem locally, get the latest repository at github and follow the instructions.
require 'json' require 'textkey_rest' # Setup apiKey = "9021fa44-f1bc-4590-b975-42fee031e078" # Create the textkey object textkey = TextKeyRest.new(apiKey, false) # Setup the API parameters cellNumber = "8181231234" # Make the API Call response = textkey.perform_DoesRegistrationCellNumberExist(cellNumber) # Pull out the data from the response response_obj = JSON.parse(response) response_data = response_obj['d'] # Display the response puts "TextKey Results:" puts JSON.pretty_generate response_data
Here is an example of the JSON string with the d wrapper removed:
Test Results:
{
"__type": "TextKeyCommon.TKStructures+RegistrationExistence",
"cellNumberCount": 1,
"errorDescr": "",
"userIDCount": -2
}
NOTE: For more detais on the RUBY Library object and methods, you can take a look at the online documentation at http://textpower.github.io/RESTLibrary-ruby/.
Javascript
All of the TextKey
In order to user the TextKey
You will be returned a JSON string as the API call payload.
NOTE: Exposing your API key via any client side code is not recommended. If you choose to use the TextKey
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> // Build a class to handle the API call input payload function textkeyPayload(apiKey, cellNumber) { this.apiKey = apiKey; this.cellNumber = cellNumber; this.toJsonString = function () { return JSON.stringify({ 'DataIn': this }); }; }; // Handle the API Request and response function textkeyAPIRequest(txtCommand, APIJSONData) { // Setup the API URL var urlAPI = 'http://www.textkey.com/REST/TKRest.asmx/'+txtCommand; // Make the API call via a JSON Ajax request $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: urlAPI, data: APIJSONData, dataType: "json", success: function (APIResponse, textStatus) { document.write("textStatus: "+textStatus+ "<HR>"); document.write("API Response: "+JSON.stringify(APIResponse, null, 4) + "<HR>"); if (textStatus == 'success') { if (APIResponse.hasOwnProperty('d')) { APIPayload = APIResponse.d; } else { APIPayload = APIResponse; } document.write("API Payload: "+JSON.stringify(APIPayload, null, 4) + "<HR>"); if (APIPayload.errorDescr == "") { document.write("cellNumberCount: " + APIPayload.cellNumberCount); } else { document.write("Error: " + APIPayload.errorDescr); } } else { document.write("Error: " + textStatus); } }, error: function (jqXHR, textStatus, errorThrown) { document.write("Error: " + jqXHR.status); } }); } // Setup the API command var txtCommand = 'doesRegistrationCellNumberExist'; // Build the API payload var doesRegistrationCellNumberExist = new textkeyPayload("9021fa44-f1bc-4590-b975-42fee031e078", "8181231234"); // Make the API Call textkeyAPIRequest(txtCommand, doesRegistrationCellNumberExist.toJsonString()); </script>
SOAP Example
Authentication Settings
A SOAP header is required on all SOAP API calls using the _Key variant and the header information is identical on all calls.
doesRegistrationCellNumberExist requires a SOAP header.
doesRegistrationCellNumberExist_Key does not require a SOAP header but uses the API Key in the body of the SOAP request.
Authentication Settings using an API Key
API Key: 9021fa44-f1bc-4590-b975-42fee031e078
OR
Authentication Settings using an UserID/Password Combination
userId: 1ed93006208f0540e452e3a37d8299bc
Password: Password12345
Campaign:
Keyword:
The WSDL document for the TextKey
The address for the SOAP calls on the TextKey
The name space for the SOAP calls on the TextKey
Call Parameters
The parameters should look something like this:
apiKey: 9021fa44-f1bc-4590-b975-42fee031e078
cellNumber: 8181231234
SOAP Request
The SOAP request should look something like this:
SOAP Request using the API Key
OR
SOAP Request using the UserID/Password
SOAP Response
The SOAP response should look something like this:
SOAP Response with an valid payload
OR
SOAP Response with an error
Output Results
The final results will need to be extracted from the XML response payload should look something like this:
SOAP Response with a valid payload
stdClass Object
(
[cellNumberCount] => 1
[userIDCount] => -2
[errorDescr] =>
)
cellNumberCount: -2
userIDCount: 0
errorDescr:
OR
SOAP Response with an error
stdClass Object
(
[cellNumberCount] => 0
[userIDCount] => 0
[errorDescr] => No GUID Validation Row: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
)
Error: No GUID Validation Row: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
SOAP Code Examples
PHP
The PHP Helper library contain a textkey class that makes calling TextKey
// Include the TextKey classes include_once("../textkey_soap.php"); // Setup the API call parameters $cellnumber = "8181231234"; // Set the authentication $apikey = "9021fa44-f1bc-4590-b975-42fee031e078"; // Create a textkey object if ($apikey != "") { $tk = new textKey("", "", "", "", $apikey); } // Handle the operation $textkey_result = $tk->perform_DoesRegistrationCellNumberExist($cellnumber); // Show the textkey API payload object print_r($textkey_result); echo "<HR>"; // Handle the results if ($textkey_result->errorDescr == "") { $tkResultsArr = get_object_vars($textkey_result); $results = ""; foreach($tkResultsArr as $key => $value) { $results .= $key . ': ' . $value . "<BR>"; } } else { $results = 'Error: ' . $textkey_result->errorDescr . "<BR>"; } echo $results;
CURL
From a command line, you can test the SOAP API calls using a CURL request:
The SOAP doesRegistrationCellNumberExist Request is stored in a file called doesRegistrationCellNumberExist.xml
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" >
<soap:Body>
<doesRegistrationCellNumberExist_Key xmlns="https://secure.textkey.com/services/">
<apiKey>9021fa44-f1bc-4590-b975-42fee031e078</apiKey>
<cellNumber>8181231234</cellNumber>
</doesRegistrationCellNumberExist_Key>
</soap:Body>
</soap:Envelope>
CURL command using doesRegistrationCellNumberExist.xml
curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d @doesRegistrationCellNumberExist.xml -X POST https://secure.textkey.com/ws/textkey.asmx
XML Response from API doesRegistrationCellNumberExist Request
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<doesRegistrationCellNumberExist_KeyResponse xmlns="https://secure.textkey.com/services/">
<doesRegistrationCellNumberExist_KeyResult>
<cellNumberCount>1</cellNumberCount>
<userIDCount>-2</userIDCount>
<errorDescr />
</doesRegistrationCellNumberExist_KeyResult>
</doesRegistrationCellNumberExist_KeyResponse>
</soap:Body>
</soap:Envelope>