Search K
Appearance
Appearance
The following details provide a summary of the Invalid token error, explain the cause, and present recommended solutions.
When you send a request to a CalypsoAI endpoint with an invalid authorization token, the request fails.
The following fragment of a full error response shows you the key part.
calypsoai.clients.base.RequestError: 'GET https://www.us1.calypsoai.app/backend/v1/campaigns'
responded with status 401
Invalid tokenThe CalypsoAI API requires a valid authorization token to be provided in all requests to verify that the request is sent by an authorized user. If the authorization token is invalid, our API can't authenticate the request and responds with the Invalid token error.
The two most common causes for this error are the following:
ENVIRONMENT URL
For on-prem users, authorization tokens are only valid in the environment in which they are created.
For SaaS users, there is only one environment, and all authorization tokens created in the SaaS environment are valid.
DEFAULT URL
By default, the URL parameter in the SDK points to the SaaS environment. If you don't include the parameter in your request, the request automatically points to the SaaS environment.
To resolve the issue, you must first identify the cause.
Make sure your authorization token is not expired.
TOKEN EXPIRATION
To check the expiration status of your authorization tokens, in the CalypsoAI Platform, go to Configuration > API tokens.
Make sure the environment URL in your request is present, is valid, and corresponds to your authorization token for the relevant environment (SaaS or on-prem).
from calypsoai import CalypsoAI
# Define the URL and token for CalypsoAI
CALYPSOAI_URL="VALID-URL"
CALYPSOAI_TOKEN="VALID-TOKEN" # Make sure your entered authorization token corresponds to the environment URL in which you created it
# Initialize the CalypsoAI client
cai = CalypsoAI(url=CALYPSOAI_URL, token=CALYPSOAI_TOKEN)
# Get all campaigns
campaigns = [campaign.model_dump_json() for campaign in cai.campaigns.iterate()]
print(campaigns)