Prior Network API DOCUMENTATION

Developer Integration Guide

Base URL: https://priornetwork.com

🚀 Overview

The Prior Network API allows developers to integrate Prior's authentication system and access user data in their applications. This enables seamless single sign-on (SSO) and user profile integration.

⚠️ Important: All API requests must include proper authentication headers. Ensure you handle user tokens securely.

Key Features

🔐 Authentication

POST /api/login

Authenticate a user and receive an access token.

Request Parameters

username (required)
User's Prior Network username
password (required)
User's password
rememberMe (optional)
Boolean to enable device remembering

Request Example

{ "username": "johndoe", "password": "userpassword123", "rememberMe": true }

Response Examples

✅ Success Response (200)
{ "success": true, "message": "Login successful", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "display_name": "John Doe", "deviceToken": "abc123def456" }
⚠️ 2FA Required Response (200)
{ "success": true, "requiresTwoFactor": true, "tempToken": "temp_token_for_2fa_verification", "message": "Please complete two-factor authentication" }
❌ Error Response (401)
{ "error": "Invalid username or password" }
POST /api/user/2fa/login

Complete 2FA authentication when required.

2FA Request Parameters

code (required)
6-digit TOTP code from authenticator app
tempToken (required)
Temporary token received from initial login
{ "code": "123456", "tempToken": "temp_token_from_login_response" }

👤 User Data

GET /api/user/profile

Get the authenticated user's profile information.

Headers Required

Authorization (required)
Bearer token received from login
Authorization: your_jwt_token_here

Response

{ "username": "johndoe", "displayName": "John Doe", "bio": "Software developer passionate about technology", "profilePicture": "https://priornetwork.com/uploads/profile_123.jpg", "coverImage": "https://priornetwork.com/uploads/cover_456.jpg", "twitter": "https://twitter.com/johndoe", "github": "https://github.com/johndoe", "website": "https://johndoe.dev", "posts_count": 25, "followers_count": 150, "following_count": 89, "friends_count": 42, "created_at": "2024-01-15T10:30:00Z" }
GET /api/user/theme

Get user's theme preferences for UI customization.

Theme Response

{ "themeColor": "#00ffcc", "themeMode": "dark" }
GET /api/user/id

Get the user's unique ID.

User ID Response

{ "id": 12345 }

✅ Token Validation

POST /api/user/validate-token

Validate a user token and get user information.

Headers Required

Authorization (required)
The JWT token to validate

Validation Response

{ "id": 12345, "userId": 12345, "username": "johndoe", "email": "[email protected]" }
❌ Invalid Token Response (401)
{ "error": "Invalid token", "details": "Token has expired" }

💻 Code Examples

JavaScript (Fetch API)

// Login Function async function loginToPrior(username, password) { try { const response = await fetch('https://priornetwork.com/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username: username, password: password, rememberMe: true }) }); const data = await response.json(); if (data.success) { if (data.requiresTwoFactor) { // Handle 2FA const code = prompt('Enter 2FA code:'); return await complete2FA(code, data.tempToken); } else { // Store token securely localStorage.setItem('priorToken', data.token); return data; } } else { throw new Error(data.error); } } catch (error) { console.error('Login failed:', error); throw error; } } // Get User Profile async function getUserProfile() { const token = localStorage.getItem('priorToken'); try { const response = await fetch('https://priornetwork.com/api/user/profile', { headers: { 'Authorization': token } }); if (response.ok) { return await response.json(); } else { throw new Error('Failed to fetch profile'); } } catch (error) { console.error('Profile fetch failed:', error); throw error; } } // Validate Token async function validateToken(token) { try { const response = await fetch('https://priornetwork.com/api/user/validate-token', { method: 'POST', headers: { 'Authorization': token } }); return response.ok ? await response.json() : null; } catch (error) { console.error('Token validation failed:', error); return null; } }

Python (requests)

import requests import json class PriorNetworkAPI: def __init__(self): self.base_url = "https://priornetwork.com" self.token = None def login(self, username, password, remember_me=True): """Login to Prior Network""" url = f"{self.base_url}/api/login" data = { "username": username, "password": password, "rememberMe": remember_me } response = requests.post(url, json=data) result = response.json() if result.get("success"): if result.get("requiresTwoFactor"): # Handle 2FA code = input("Enter 2FA code: ") return self.complete_2fa(code, result["tempToken"]) else: self.token = result["token"] return result else: raise Exception(result.get("error", "Login failed")) def complete_2fa(self, code, temp_token): """Complete 2FA authentication""" url = f"{self.base_url}/api/user/2fa/login" data = { "code": code, "tempToken": temp_token } response = requests.post(url, json=data) result = response.json() if result.get("success"): self.token = result["token"] return result else: raise Exception(result.get("error", "2FA failed")) def get_user_profile(self): """Get user profile information""" if not self.token: raise Exception("Not authenticated") url = f"{self.base_url}/api/user/profile" headers = {"Authorization": self.token} response = requests.get(url, headers=headers) if response.status_code == 200: return response.json() else: raise Exception("Failed to fetch profile") def validate_token(self, token=None): """Validate authentication token""" token = token or self.token if not token: return False url = f"{self.base_url}/api/user/validate-token" headers = {"Authorization": token} response = requests.post(url, headers=headers) return response.status_code == 200 # Usage Example api = PriorNetworkAPI() try: # Login login_result = api.login("username", "password") print("Login successful!") # Get profile profile = api.get_user_profile() print(f"Welcome, {profile['displayName']}!") # Validate token if api.validate_token(): print("Token is valid") except Exception as e: print(f"Error: {e}")

cURL Commands

# Login curl -X POST https://priornetwork.com/api/login \ -H "Content-Type: application/json" \ -d '{ "username": "johndoe", "password": "userpassword123", "rememberMe": true }' # Get User Profile curl -X GET https://priornetwork.com/api/user/profile \ -H "Authorization: your_jwt_token_here" # Get User Theme curl -X GET https://priornetwork.com/api/user/theme \ -H "Authorization: your_jwt_token_here" # Validate Token curl -X POST https://priornetwork.com/api/user/validate-token \ -H "Authorization: your_jwt_token_here" # 2FA Login (if required) curl -X POST https://priornetwork.com/api/user/2fa/login \ -H "Content-Type: application/json" \ -d '{ "code": "123456", "tempToken": "temp_token_from_initial_login" }'

⚠️ Error Handling

Common Error Codes

400 - Bad Request

Missing required parameters or invalid data format

{ "error": "Missing username or password" }
401 - Unauthorized

Invalid credentials or expired token

{ "error": "Invalid username or password" }
403 - Forbidden

Account suspended or access denied

{ "error": "Your account has been suspended" }
404 - Not Found

User or resource not found

{ "error": "User not found" }
429 - Too Many Requests

Rate limit exceeded

{ "error": "Too many requests, please try again later." }
500 - Internal Server Error

Server error occurred

{ "error": "Server error" }
503 - Service Unavailable

Maintenance mode active

{ "error": "Scheduled Maintenance in Progress", "message": "We're rolling out updates — could be new features or bug fixes. We'll be back soon!", "maintenanceMode": true }

Best Practices

💡 Pro Tip: Always check the HTTP status code and handle errors appropriately. Provide meaningful error messages to your users.

🎉 Ready to Integrate?

Start building amazing applications with Prior Network's authentication system!

Need Help?

Contact the Prior Network development team for additional support and advanced integration options.