This API endpoint allows organizations to authenticate existing users or create new users using their API key. The endpoint automatically handles user creation and organization membership management.
POST /api/authenticate-organization-user/
This endpoint requires API Key authentication. Organizations must include their API key in the request headers.
http
Authorization: Bearer sk_your_api_key_here
Content-Type: application/json
Or alternatively:
http
X-API-Key: sk_your_api_key_here
Content-Type: application/json
json
{
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe"
}
| Parameter | Type | Required | Description |
| ------------ | ------ | -------- | ------------------------------- |
| email
| string | Yes | Valid email address of the user |
| first_name
| string | Yes | User's first name |
| last_name
| string | Yes | User's last name |
json
{
"user_data": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"role": "USER",
"provider": "LOCAL",
"is_email_verified": true,
"date_joined": "2024-01-15T10:30:00Z",
"plan": "FREE"
},
"tokens": {
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
},
"is_new_user": true,
"organization": {
"id": "456e7890-e89b-12d3-a456-426614174001",
"name": "Acme Corporation",
"plan": "TEAM_HIRING"
}
}
| Field | Type | Description |
| ---------------- | ------- | ----------------------------------------------------------- |
| user_data
| object | Complete user information |
| tokens.access
| string | JWT access token for API authentication |
| tokens.refresh
| string | JWT refresh token for token renewal |
| is_new_user
| boolean | true
if user was created, false
if user already existed |
| organization
| object | Organization information |
USER
roleis_email_verified
to true
(since organization is vouching for the user)Missing or invalid parameters:
json
{
"error": "Email is required"
}
json
{
"error": "First name is required"
}
json
{
"error": "Invalid email format"
}
Invalid or missing API key:
json
{
"error": "This endpoint requires API key authentication"
}
Server-side errors:
json
{
"error": "Failed to create user"
}
json
{
"error": "Failed to generate authentication tokens"
}
bash
curl -X POST \
https://api.skillora.ai/api/authenticate-organization-user/ \
-H 'Authorization: Bearer sk_your_api_key_here' \
-H 'Content-Type: application/json' \
-d '{
"email": "new.employee@company.com",
"first_name": "Jane",
"last_name": "Smith"
}'
```python import requests
url = "https://api.skillora.ai/api/authenticate-organization-user/" headers = { "Authorization": "Bearer sk_your_api_key_here", "Content-Type": "application/json" } payload = { "email": "new.employee@company.com", "first_name": "Jane", "last_name": "Smith" }
response = requests.post(url, json=payload, headers=headers) data = response.json()
if response.status_code == 200: print(f"Success! User: {data['user_data']['email']}") print(f"Is new user: {data['is_new_user']}") print(f"Access token: {data['tokens']['access']}") else: print(f"Error: {data.get('error', 'Unknown error')}") ```
```javascript const response = await fetch('/api/authenticate-organization-user/', { method: 'POST', headers: { Authorization: 'Bearer sk_your_api_key_here', 'Content-Type': 'application/json', }, body: JSON.stringify({ email: 'new.employee@company.com', first_name: 'Jane', last_name: 'Smith', }), });
const data = await response.json();
if (response.ok) { console.log('Success!', data); // Store tokens for future API calls localStorage.setItem('access_token', data.tokens.access); localStorage.setItem('refresh_token', data.tokens.refresh); } else { console.error('Error:', data.error); } ```
First, create an API key for your organization through the admin panel or API:
bash
python manage.py create_api_key <organization_id> "User Authentication Key"
Store the API key securely in your application (environment variables, secure configuration, etc.):
bash
export API_KEY="sk_your_generated_api_key_here"
Use this endpoint in your application's user onboarding or authentication flow:
Use the refresh token to get new access tokens when they expire:
bash
POST /api/users/jwt/refresh/
{
"refresh": "your_refresh_token"
}
Use the provided test script to verify the endpoint works correctly:
bash
API_KEY=sk_your_api_key_here python test_organization_auth.py
API keys have configurable rate limits. The default is 100 requests per minute. Contact your administrator if you need higher limits.
401 Unauthorized
Check that API key is valid and active
Ensure API key is properly formatted in the Authorization header
400 Bad Request
Verify all required fields are provided
Check email format is valid
500 Internal Server Error
For additional support or questions about this API, please contact your system administrator or refer to the main API documentation.