#πŸ”’ TwilioAPI issue

25 messages Β· Page 1 of 1 (latest)

placid nebula
#

Im encountering this error while trying to use the Twilio voice JS SDK on a trial account. My setup involves generating a JWT using python with the following verified (and quadrouple checked) environment variables:
TWILIO_ACCOUNT_SID, TWILIO_API_KEY, TWILIO_API_SECRET, and other necessary credentials.

I am using the correct API key SID and API secret for token generation, and the JTW (verified in jwt.io) appear valid, as well as my server time being synchronised. Despite this, upon calling device registration, i get a "{"payload":{"error":{"code":31204,"message":"JWT is invalid"}},"type":"error","version":""}" message.

Any ideas would be amazing, Ive been stuck on this for a few days now.

Eternal gratitude and thanks!

lilac sigilBOT
#

@placid nebula

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

placid nebula
lilac sigilBOT
wooden jackal
#

it's not clear, but it sounds like you may be creating the jwt?

wooden jackal
#

that's not how it usually works

placid nebula
#

the JTW is passed to the twilio backend as authorisation, and its saying it cant authorise me.

wooden jackal
#

you're trying to use the jwt for twillio auth, right?

placid nebula
#

yes

#

Ive checked everything over key wise a million times, ive made about five new apis at this point, and three entire new server scripts. I just cant get it to work 😭

wooden jackal
#

can you link the API docs for how you're trying to auth?

#

I'm not seeing anything about using jwt

#

and that's not something the client constructs anyway

placid nebula
#

honestly, i cant remember where the docs are. A twilio developer gave me the below code and said "i could try this" but no clue if it actually works:

Twilio Voice JS SDK – Access Token (JWT) Generator

pip install twilio

Required environment variables:

TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

TWILIO_API_KEY_SID=SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # MUST be a Standard API Key

TWILIO_API_KEY_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Optional (but strongly recommended for outgoing calls):

TWILIO_TWIML_APP_SID=APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

import os
from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import VoiceGrant

def generate_voice_token(identity: str, ttl_seconds: int = 3600) -> str:
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
api_key_sid = os.environ["TWILIO_API_KEY_SID"]
api_key_secret = os.environ["TWILIO_API_KEY_SECRET"]
twiml_app_sid = os.getenv("TWILIO_TWIML_APP_SID")

token = AccessToken(
    account_sid=account_sid,
    signing_key_sid=api_key_sid,
    secret=api_key_secret,
    identity=identity,
    ttl=ttl_seconds,
)

voice_grant = VoiceGrant(
    outgoing_application_sid=twiml_app_sid,
    incoming_allow=True,
)

token.add_grant(voice_grant)

return token.to_jwt().decode("utf-8")

if name == "main":
# Identity should be a stable user identifier
print(generate_voice_token(identity="user_123"))

wooden jackal
#

those are the docs for the library, they have a general client example and a voice example

placid nebula
#

oh my god... its working. I could honestly marry you, thank you so much for your help

lilac sigilBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.