Authentication
The SDK uses nx_token-based authentication. The token is automatically generated on the first API call.
Auto Token Generation
When you initialize the client with your API keys and username, the SDK automatically generates the nx_token when needed:
from nexacon import NexaconClient
client = NexaconClient(
api_key="your_api_key",
secret_key="your_secret_key",
username="+255788811191"
)
# Token is auto-generated on first API call
client.messaging.send(to="+255788811191", message="Hello!")
Using Existing Token
If you already have an nx_token, you can pass it to skip auto-generation:
client = NexaconClient(
api_key="your_api_key",
secret_key="your_secret_key",
username="+255788811191",
nx_token="your_existing_token" # Skip auto-generation
)
Verify Token
Verify that the current token is valid:
user = client.auth.verify_token()
print(f"Authenticated as: {user}")
Get User Information
Get current user information:
user = client.auth.get_user()
print(f"User: {user}")
Logout
Logout the current session:
client.auth.logout()