Users API

The Users API provides endpoints for user management, authentication, preferences, and notifications.

App Endpoints

Get Preferences

Retrieve user preferences and settings.

POST /api/get/preferences/

Response:

{
  "user_id": 123,
  "preferences": {
    "language": "en",
    "notifications": {
      "new_campaign": true,
      "end_campaign": true,
      "near_campaign": true,
      "cause_campaign": true,
      "profile_status": true,
      "post_status": true,
      "update_balance": true
    },
    "categories": ["fashion", "beauty", "technology"],
    "networks": ["instagram", "facebook"]
  }
}

Get Notifications

Retrieve user notifications.

POST /api/get/notifications/

Response:

{
  "user_id": 123,
  "user_notifications": [
    {
      "name": "New campaign",
      "code": "new_campaign",
      "status": true
    },
    {
      "name": "End campaign",
      "code": "end_campaign",
      "status": true
    },
    {
      "name": "Near campaign",
      "code": "near_campaign",
      "status": false
    },
    {
      "name": "Causes",
      "code": "cause_campaign",
      "status": true
    },
    {
      "name": "Profile status",
      "code": "profile_status",
      "status": true
    },
    {
      "name": "Post status",
      "code": "post_status",
      "status": true
    },
    {
      "name": "Update balance",
      "code": "update_balance",
      "status": true
    }
  ],
  "not_found_message": "No notifications to display"
}

Get Notifications History

Retrieve notification history.

POST /api/get/notifications/history/

Request Body:

page=1
limit=20

Response:

{
  "notifications": [
    {
      "id": 456,
      "title": "New Campaign Available",
      "message": "A new fashion campaign is available",
      "type": "campaign",
      "read": false,
      "created_at": "2024-08-01T10:00:00Z"
    }
  ],
  "total": 50,
  "page": 1,
  "limit": 20
}

Authentication Checks

Check Authentication

Check if user is authenticated.

POST /api/check/auth/

Response:

{
  "is_authenticated": true,
  "user_id": 123,
  "username": "user123"
}

Check Login

Check login status.

POST /api/check/validate/

Response:

{
  "is_logged": true,
  "user_id": 123
}

Check Email

Check if email exists.

POST /api/check/email/

Request Body:

email=user@example.com

Response:

{
  "exists": true,
  "available": false
}

Update Operations

Update Language

Update user language preference.

POST /api/update/language/

Request Body:

language=es

Response:

{
  "status": "success",
  "message": "Language updated successfully"
}

Update Profile

Update user profile information.

POST /api/update/profile/

Request Body:

first_name=John
last_name=Doe
email=john.doe@example.com
phone=+1234567890
country=1
city=1

Response:

{
  "status": "success",
  "message": "Profile updated successfully"
}

Update Preferences

Update user preferences.

POST /api/update/preferences/

Request Body:

categories=fashion
categories=beauty
networks=instagram
networks=facebook
language=en

Response:

{
  "status": "success",
  "message": "Preferences updated successfully"
}

Update Notifications

Update notification settings.

POST /api/update/notifications/

Request Body:

new_campaign=true
end_campaign=false
near_campaign=true
cause_campaign=true
profile_status=true
post_status=true
update_balance=true

Response:

{
  "status": "success",
  "message": "Notification settings updated"
}

User Actions

Register

Register a new user account.

POST /api/action/register/

Request Body:

username=newuser
email=newuser@example.com
password=securepassword
first_name=John
last_name=Doe
country=1
city=1

Response:

{
  "status": "success",
  "message": "Account created successfully",
  "user_id": 789
}

Logout

Logout user and invalidate session.

POST /api/action/logout/

Response:

{
  "status": "success",
  "message": "Logged out successfully"
}

Backend Endpoints

Authentication Checks

Check Login (Backend)

Check login status for backend operations.

POST /api/check/login/

Response:

{
  "is_logged": true,
  "user_id": 123,
  "is_staff": false,
  "is_superuser": false
}

Check Validate (Backend)

Validate user credentials for backend operations.

POST /api/check/validate/

Request Body:

username=user123&password=password123

Response:

{
  "is_valid": true,
  "user_id": 123
}

Check Email (Backend)

Check email existence for backend operations.

POST /api/check/email/

Request Body:

{
  "email": "user@example.com"
}

Response:

{
  "exists": true,
  "user_id": 123
}

User Management

User Statistics

Get user statistics by sex.

POST /api/users/stats/sex/

Response:

{
  "male": 60,
  "female": 40,
  "other": 0
}

Get user statistics by age.

POST /api/users/stats/age/

Response:

{
  "18-24": 30,
  "25-34": 40,
  "35-44": 20,
  "45+": 10
}

Get user statistics by preferences.

POST /api/users/stats/preferences/

Response:

{
  "fashion": 25,
  "beauty": 20,
  "technology": 15,
  "food": 10,
  "travel": 10,
  "other": 20
}

User Status Management

Ban user.

POST /api/user/status/ban/

Request Body:

user_id=123
banned=true
reason=Violation of terms of service

Response:

{
  "status": "success",
  "message": "User ban status updated"
}

Get user status.

POST /api/user/status/

Request Body:

user_id=123

Response:

{
  "status": "active",
  "joined_date": "2024-01-01",
  "last_login": "2024-08-01T10:00:00Z",
  "total_campaigns": 10,
  "total_earnings": 500
}

User Notifications

Send notification to user.

POST /api/user/notification/

Request Body:

user_id=123
title=New Campaign
message=A new campaign is available for you
type=campaign

Response:

{
  "status": "success",
  "message": "Notification sent successfully"
}

Force Logout

Force logout user from all sessions.

POST /api/user/force-logout/

Request Body:

user_id=123

Response:

{
  "status": "success",
  "message": "User logged out from all sessions"
}

Custom Social Wall

Add custom social wall for user.

POST /api/user/add-custom-social-wall/

Request Body:

user_id=123
wall_url=https://example.com/social-wall
network=instagram
description=Custom social wall for user

Response:

{
  "status": "success",
  "message": "Custom social wall added successfully"
}

Data Models

User Profile

{
  "id": 123,
  "username": "user123",
  "email": "user@example.com",
  "first_name": "John",
  "last_name": "Doe",
  "date_joined": "2024-01-01T00:00:00Z",
  "last_login": "2024-08-01T10:00:00Z",
  "is_active": true,
  "is_staff": false,
  "is_superuser": false,
  "country": {
    "id": 1,
    "name": "United States"
  },
  "city": {
    "id": 1,
    "name": "New York"
  },
  "language": "en",
  "timezone": "UTC"
}

User Preferences

{
  "user_id": 123,
  "language": "en",
  "notifications": {
    "new_campaign": true,
    "end_campaign": true,
    "near_campaign": true,
    "cause_campaign": true,
    "profile_status": true,
    "post_status": true,
    "update_balance": true
  },
  "categories": ["fashion", "beauty", "technology"],
  "networks": ["instagram", "facebook"],
  "privacy_settings": {
    "profile_public": true,
    "show_earnings": false,
    "show_campaigns": true
  }
}

Notification

{
  "id": 456,
  "user_id": 123,
  "title": "New Campaign Available",
  "message": "A new fashion campaign is available for you",
  "type": "campaign",
  "read": false,
  "created_at": "2024-08-01T10:00:00Z",
  "data": {
    "campaign_id": 789,
    "campaign_name": "Summer Fashion Campaign"
  }
}

Error Responses

Authentication Errors

{
  "error": "authentication_required",
  "message": "Authentication is required for this endpoint"
}
{
  "error": "invalid_credentials",
  "message": "Invalid username or password"
}

Validation Errors

{
  "error": "validation_error",
  "message": "Invalid email format",
  "field": "email"
}
{
  "error": "validation_error",
  "message": "Password must be at least 8 characters long",
  "field": "password"
}

Permission Errors

{
  "error": "permission_denied",
  "message": "You don't have permission to perform this action"
}
{
  "error": "user_not_found",
  "message": "User not found"
}