20160: Invalid Token
API
ERROR
This error occurs when the token presented to the Twilio API is not a valid JWT. Twilio Access Tokens are JWTs used by client SDKs and must follow the JSON Web Token structure and constraints documented by Twilio.
- The token is not a properly formed
JWT(Twilio Access Tokens are composed of three parts:header,payload, andsignature). - The
JWTheaderis not set as required (for example,typmust be"JWT",algmust be"HS256", andctymust be"twilio-fpa;v=1"). - The token was generated or signed without the correct API Key SID/Secret for the account (the
issidentifies the API Key and thesignatureis created using the API Key Secret). - A Restricted API Key was used to create an Access Token for client-side SDKs (not supported).
- Re-generate the Access Token on your server using Twilio SDKs and the correct credentials (Account SID, API Key SID, and API Key Secret).
- Ensure the token's
headerfields meet Twilio's requirements and thealgisHS256. - Verify the token lifetime: Access Tokens have a maximum age of 24 hours and should be created with the shortest feasible
ttl. - Use a Main or Standard API Key when creating Access Tokens; do not use a Restricted API Key.