User Profiles API
Manage user profiles, including names, avatars, bios, and privacy settings.
Get Public Profile
GET /api/v1/profiles/:id
Retrieve a user's public profile information.
javascript
const API_BASE = 'https://api.fundlyhub.org/api/v1';
const userId = '123e4567-e89b-12d3-a456-426614174000';
const response = await fetch(`${API_BASE}/profiles/${userId}`);
const profile = await response.json();
// Response format
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "John Doe",
"avatar": "https://example.com/avatar.jpg",
"bio": "Community organizer passionate about helping families",
"created_at": "2024-01-01T00:00:00Z",
"fundraiser_count": 5,
"total_raised": 125000
}Get My Profile
GET /api/v1/profiles/me 🔒 Requires Authentication
Retrieve the authenticated user's full profile including private information.
javascript
const API_BASE = 'https://api.fundlyhub.org/api/v1';
const response = await fetch(`${API_BASE}/profiles/me`, {
credentials: 'include'
});
const myProfile = await response.json();
// Includes private fields like email
console.log('Email:', myProfile.email);
console.log('Privacy:', myProfile.privacy_settings);Update Profile
PATCH /api/v1/profiles/me 🔒 Requires Authentication
Update user profile information.
javascript
const API_BASE = 'https://api.fundlyhub.org/api/v1';
const response = await fetch(`${API_BASE}/profiles/me`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify({
name: 'John Doe',
bio: 'Updated bio with more details',
avatar: 'https://example.com/new-avatar.jpg'
})
});
const updated = await response.json();
console.log('Profile updated:', updated);Upload Avatar
POST /api/v1/profiles/me/avatar 🔒 Requires Authentication
Upload a new profile avatar image.
javascript
const API_BASE = 'https://api.fundlyhub.org/api/v1';
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const formData = new FormData();
formData.append('avatar', file);
const response = await fetch(`${API_BASE}/profiles/me/avatar`, {
method: 'POST',
credentials: 'include',
body: formData
});
const { avatar_url } = await response.json();
console.log('New avatar URL:', avatar_url);Privacy Settings
PATCH /api/v1/profiles/me/privacy 🔒 Requires Authentication
Update privacy settings for profile visibility and donation visibility.
javascript
const API_BASE = 'https://api.fundlyhub.org/api/v1';
const response = await fetch(`${API_BASE}/profiles/me/privacy`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify({
profile_visibility: 'public', // 'public', 'private'
show_donations: false, // Hide donation history
show_fundraisers: true // Show created fundraisers
})
});
const settings = await response.json();
console.log('Privacy settings updated');Response Codes
200- Success400- Bad request / Validation errors401- Authentication required403- Permission denied404- Profile not found429- Rate limit exceeded500- Server error