User Profile API

The iiniit Profile API allows you to retrieve and update user profile information. This guide explains how to access and manage user profiles through the API.

Authentication Requirements

To access the Profile API, you need an access token with the appropriate scopes:

  • profile: Required to read basic profile information
  • email: Required to access the user's email address
  • profile:write: Required to update profile information

For more information on obtaining access tokens, see the Authentication Guide.

API Endpoints

Get Current User Profile

Retrieves the profile information for the authenticated user.

GET /v1/user/profile

Required scope: profile

Example Request

curl -X GET \
  https://api.iiniit.com/v1/user/profile \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'

Example Response

{
  "id": "usr_123456789",
  "username": "johndoe",
  "name": "John Doe",
  "email": "[email protected]",
  "avatar_url": "https://assets.iiniit.com/avatars/usr_123456789.jpg",
  "bio": "Software developer and open source contributor",
  "location": "San Francisco, CA",
  "website": "https://johndoe.com",
  "created_at": "2022-01-15T08:30:00Z",
  "updated_at": "2023-05-20T14:45:30Z"
}

Using the Profile API with JavaScript

Here are examples of how to use the Profile API with JavaScript:

Get Current User Profile

// Example: Get the current user's profile
async function getCurrentUserProfile(accessToken) {
  try {
    const response = await fetch('https://api.iiniit.com/v1/user/profile', {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${accessToken}`,
        'Content-Type': 'application/json'
      }
    });
    
    if (!response.ok) {
      throw new Error(`API request failed: ${response.status}`);
    }
    
    const profile = await response.json();
    return profile;
  } catch (error) {
    console.error('Error fetching profile:', error);
    throw error;
  }
}

Error Handling

The Profile API may return the following error responses:

Status Code Error Code Description
400 invalid_request The request is malformed or contains invalid parameters
401 unauthorized The access token is missing, invalid, or expired
403 forbidden The access token does not have the required scopes
404 not_found The requested user does not exist
413 payload_too_large The uploaded file exceeds the maximum size limit

Example Error Response

{
  "error": "invalid_request",
  "error_description": "The website URL is not valid",
  "status": 400
}

Rate Limiting

The Profile API is subject to rate limiting. The current limits are:

  • 60 requests per minute for read operations
  • 10 requests per minute for write operations

When you exceed the rate limit, the API will return a 429 Too Many Requests response with a Retry-After header indicating how many seconds to wait before making another request.

Best Practices

Follow these best practices when working with the Profile API:

  • Cache profile data: To reduce API calls, cache profile data that doesn't change frequently
  • Implement proper error handling: Handle API errors gracefully in your application
  • Respect rate limits: Implement exponential backoff when encountering rate limit errors
  • Validate input: Validate user input before sending it to the API
  • Use the SDK: When possible, use the iiniit SDK for simplified integration

Conclusion

The Profile API provides a simple way to access and manage user profile information in your applications. By following this guide, you can integrate user profiles into your application and provide a personalized experience for your users.

For more information, refer to the following resources: