There are test numbers to which you can send SMS using my test credentials. They fake sending beautifully. But, attempting to use the lookup API also provided by Twilio, even if the intention is to retrieve information about the test number, will fail:
>>> from django.conf import settings
>>> from twilio.rest.lookups import TwilioLookupsClient
>>> account_sid = settings.TWILIO_ACCOUNT_SID
>>> auth_token = settings.TWILIO_AUTH_TOKEN
>>> client = TwilioLookupsClient(account_sid, auth_token)
>>> lookup_client.phone_numbers.get('+15005555009', include_carrier_info=True)
---------------------------------------------------------------------------
TwilioRestException Traceback (most recent call last)
<ipython-input-9-03718f1c0615> in <module>()
----> 1 client.phone_numbers.get('+15005555009', include_carrier_info=True)
...
TwilioRestException:
HTTP Error Your request was:
GET https://lookups.twilio.com/v1/PhoneNumbers/+15005555009?Type=carrier
Twilio returned the following information:
Resource not accessible with Test Account Credentials
More information may be available here:
https://www.twilio.com/docs/errors/20008
+15005555009 is the only phone number listed to emulate a landline, that is incapable of returning an SMS. I am expecting the API to return 'landline' for the carrier type for such a number. That link in the error message brings me to a page with no working test credentials.
How can I test the lookup API with the test credentials given?
I don't think you can use the lookup API with test credentials.
From https://www.twilio.com/docs/api/rest/test-credentials ...
"Supported Resources
Your test credentials can currently be used to interact with the following three resources:
Buying phone numbers: POST
/2010-04-01/Accounts/{TestAccountSid}/IncomingPhoneNumbers
Sending SMS messages: POST
/2010-04-01/Accounts/{TestAccountSid}/SMS/Messages
Making calls: POST /2010-04-01/Accounts/{TestAccountSid}/Calls
Requests to any other resource with test credentials will receive a 403 Forbidden response. In the future, we may enable these resources for testing as well."
Related
I am trying to move my account off of using local numbers and onto toll free numbers.
I would like to get a list of all my local numbers. The incoming_phone_numbers api does not seem to return the Type attribute which tells me local vs toll free.
I believe I need to use the Active Number api, which is in preview, to get that info https://www.twilio.com/docs/phone-numbers/global-catalog/api/active-numbers
I am receiving a 404 response when I use the below script.
I've found post of people talking about this api, but all the comments were about the issue I am having with no resolution https://stackoverflow.com/a/63297180/3599659
from twilio.rest import Client
import keyring
import requests
from requests.auth import HTTPBasicAuth
account_sid = keyring.get_password("twilio", "account_sid")
auth_token = keyring.get_password("twilio", "auth_token")
client = Client(account_sid, auth_token)
numbers = client.incoming_phone_numbers.list(limit=1)
print(f"getting info for {numbers[0].sid}")
response = requests.get(f"https://preview.twilio.com/Numbers/ActiveNumbers/{numbers[0].sid}", auth=HTTPBasicAuth(account_sid, auth_token))
if not response:
print(f"Request for active numbers failed. status code:{response.status_code}. {response.content}")
quit()
print(response.content)
This API is in Private Developer Preview. I am not sure if it still open to accepting new customers. I am looking to discover this.
It does cost $0.005 per call but if you only have US numbers you can make a call to the lookups api requesting carrier information for the number.
response = requests.get(f"https://lookups.twilio.com/v1/PhoneNumbers/{numbers[0].phoneNumber}?Type=carrier", auth=HTTPBasicAuth(account_sid, auth_token))
This should list the carrier name as either Twilio - SMS/MMS-SVR or Twilio - Toll-Free - SMS-Sybase365/MMS-SVR so you can identify the toll free numbers that way. This is assuming the numbers were issued by twilio and haven't been ported in etc.
I've registered an app in Azure AD and given it API permissions(both Application and delegated) to read all AD groups (Group.Read.All, also Directory.Read.All etc). Using this app I am using Graph Service Client to make a call to get user's AD groups.
public async Task<IEnumerable<GroupInfo>> GetAllGroupsOfUser(string mail)
{
IList<GroupInfo> result = new List<GroupInfo>();
IUserMemberOfCollectionWithReferencesPage memberOfGroups = await _graphServiceClient.Users[mail].MemberOf.Request().GetAsync();
.......... More code ........
}
It works fine for most of the users email but for few emails, which are present in the active directory, I'm getting the following exception
Code: Request_ResourceNotFound Message: Resource 'someuser#somedomain.co' does not exist or one of its queried reference-property objects are not present.
Your error is not that you lack certain permissions, and it has nothing to do with which api testing tool you are using. Your error is very simple. As your error message says, it is that you entered the wrong user email.
Your error message has clearly stated that there is no'someuser#somedomain.co' email, because this is not a correct email, it should be .com instead of .co.
So you must make sure that you enter the correct email without special characters or spaces.
This is my test result:
1.
2.
I have a TwiMl like this in a Bin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice">Hello {{Name}}. You have ticket number {{TicketNum}} so please solve it.</Say>
</Response>
Then I use hmac authentication and launch the script to make the call using the following TWIML Bin url with query strings attached:
twiml_link="https://handler.twilio.com/twiml/EHxxxxxxxxxxx?Name=Bob&TicketNum=45"
I get the call with Bob and Ticket 45. After that I need to alert our incident tracking system that Bob has acknowledge the ticket 45 and is "on it." I can't because of architecture send something back to my system. I need to go out and query twilio again.
So I wrote this python snippet to hit the Twilio API to find all completed calls. :
from twilio.rest import Client
import sys, os
# Your Account Sid and Auth Token from twilio.com/console
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
calls = client.calls.list(status=completed)
for call in calls:
print(call.sid)
print(call.to)
print(call.status)
print(call.start_time)
print(call.duration)
print(call.annotation)
print(call.uri)
None of these commands can print Bob or the ticket number or the Twiml Bin URL or the query strings I used. Any tips? Thanks in Advance!
That approach isn't a reliable way to determine if the intended party answered the phone and acknowledge the message without "Human Detection". You can find more details here.
Alternative to AMD - "Human Detection"
https://support.twilio.com/hc/en-us/articles/223132567-Can-Twilio-tell-whether-a-call-was-answered-by-a-human-or-machine-#alternatives-to-amd
The dialed party could be a voicemail system, so querying the REST API to see if the call status was completed will provide misleading results if your goal is to determine the person acknowledged the ticket.
You could use a Twilio Function, https://support.twilio.com/hc/en-us/articles/115007737928-Building-apps-with-Twilio-Functions, to collect the result of the
Alan
We have a callback url in place that is correctly capturing the failed status of a call.
Our code then fetches from twilio the details of the call by doing the following:
$call = $twilio_client->calls($sid)->fetch();
Within the call details returned there is no 5 digit error code listed, even though the failed status is present.
How do we get the 5 digit error code that caused the failure?
Twilio developer evangelist here.
Thanks to #miknik for the answer, however that is actually a deprecated resource (which is why you can't currently find any documentation on the matter). It's taken me a while to find the answer as I've been chasing down where the notifications have gone.
The Notifications API was deprecated in favour of the Monitor Alerts API. This API can give you all the details about an alert, including the 5 digit code.
The best way to receive these alerts for your application is to set up a webhook in your account console which will send all the parameters about the alert as part of the request.
You can also list your alerts which will allow you to find alerts from a specific resource SID (in your case, a call SID).
Let me know if this helps at all.
Make an authenticated GET request to
/2010-04-01/Accounts/{AccountNumber}/Calls/{CallSid}/Notifications
So in PHP the following will retrieve the notification info for your call
$json = file_get_contents('https://{AccountNumber}:{AuthToken}#api.twilio.com/2010-04-01/Accounts/{AccountNumber}/Calls/{CallSid}/Notifications.json');
Then use this line to get the returned JSON into an associative array
$obj = json_decode($json, true);
Now if all you want is the error code its stored as the following variable
echo $obj[notifications][0][error_code];
However, the full error info is also returned as a URL encoded string. You can access this by first urldecoding it, and then parsing the query string into an array with the following line
parse_str(urldecode($obj[notifications][0][message_text]), $output);
And you can now access the variables within like this
echo $output[Msg]; // Error text for failure eg invalid phone number
echo $output[phonenumber]; // Phone number for failed call
echo $output[ErrorCode]; // 5 digit error code
echo $output[LogLevel];` // Log level of error eg WARN
As far as I know this is not implemented in the PHP helper library, so you have to code for it manually
I have implemented test twilio sms application. I have downloaded three files from https://github.com/benedmunds/CodeIgniter-Twilio
I have used my account_sid, auth_token in twilio.php file which is in config folder. I have also used 'from' number as +15005550006 in that file.
I have used following codes in my controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Twiliosms extends TL_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('twilio');
$from = '+15005550006';
$to = '+91xxxxxxxxxx';
$message = 'This is a test...';
$response = $this->twilio->sms($from, $to, $message);
//echo "<pre>";print_r($response);echo "</pre>";
if($response->IsError)
echo 'Error: ' . $response->ErrorMessage;
else
//echo 'Sent message to ' . $to;
echo 'Sent message';
}
}
Now when I run the controller file in the browser(not in my machine but in server), it runs successfully and it shows "Sent message".
But no sms is received. Please help.
My name is Jarod and I work at Twilio. There are multiple reasons this could be failing so lets walk through them one at a time.
1. Sending an sms using Twilio test credentials will not result in an sms being sent.
Test credentials are used for testing and debugging your application. They are "fake" numbers, that do not send any data via carrier, but instead return preset error codes and responses in order to test response-handling in your application. As you experienced this specific test credential +15005550006 will always return NO ERROR, whereas +15005550001 will always respond with "This phone number is invalid".
2. You can only send SMS from a Twilio number or a verified phone number.
You can always send an SMS from a number you bought on Twilio.com, but in order to send an SMS from any other number you must first verify that phone number with Twilio. Read more about the difference here.
These are the most common reasons for not receiving and actual SMS but in the case of the Indian phone numbers it could very well be one of these rare limitations.
If none of these work we probably need to look into your specific account to find out what's happening, in which case you should reach out to support#twilio.com.
Hope this helps.
I banged my head against the walls for three hours and tried to work out with the number Twilio gave me at the time of sign up . But It always gave me the following error
{ "code": 21212, "message": "The 'From' number +234234234 is not a
valid phone number or shortcode.", "more_info":
"https://www.twilio.com/docs/errors/21212", "status": 400 }
At the end i got the exact point from where I got my test phone number for sms / call
Get your test phone number from Here .
You will have to make the from number a number you have verified with Twilio that you own: you can't just pick any number and use it. Do you own +15005550006, and have you verified that number in the Twilio admin console?