Search code examples
twiliotwilio-apitwilio-twimltwilio-php

Twilio call cost for non US (US1) calls ? (for example IE1 calls)


I am trying to get the cost of calls on Twilio thanks to the Call SID.

Here is my code:

account_sid = 'my_sid'
auth_token = 'my_us1_token' or 'my_ie1_token'
call_sid = 'a_call_sid_from_us1_region' or 'a_call_sid_from_ie1_region'

client = Client(account_sid, auth_token)
call = client.calls(call_sid).fetch()
print(f"Price: {call.price} {call.price_unit}")

Everything works fine when I put 'my_us1_token' and 'a_call_sid_from_us1_region' together. I get something like this:

Price: -0.01000 USD

If I use 'my_ie1_token' with 'a_call_sid_from_ie1_region' I get the following error on code line: 'call = client.calls(call_sid).fetch()'

  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/twilio/rest/api/v2010/account/call/__init__.py", line 392, in fetch
    payload = self._version.fetch(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/twilio/base/version.py", line 141, in fetch
    return self._parse_fetch(method, uri, response)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/twilio/base/version.py", line 112, in _parse_fetch
    raise self.exception(method, uri, response, "Unable to fetch record")
twilio.base.exceptions.TwilioRestException: 
HTTP Error Your request was:

GET /Accounts/ACxxxxxxxxxxxxxx/Calls/CAxxxxxxxxxxxxxxxxx.json

Twilio returned the following information:

Unable to fetch record: The requested resource /2010-04-01/Accounts/ACxxxxxxxxxxx4/Calls/CAxxxxxxxxxxx.json was not found

More information may be available here:

https://www.twilio.com/docs/errors/20404

Any idea how to solve this issue ? Seems to be a bug on Twilio side :( but just to be sure...

Thanks.


Solution

  • ANSWER TO MY QUESTION :

    The non-US region has to be specified in the client:

    client = Client(
      settings.TWILIO_ACCOUNT_SID,
      settings.TWILIO_AUTH_TOKEN,
      region='ie1',
      edge='dublin'
    )
    

    See: https://github.com/twilio/twilio-python#specify-region-andor-edge

    Note that all APIs are not available in non-US regions. https://www.twilio.com/docs/global-infrastructure/regional-product-and-feature-availability

    Hope this will help!