Skip to main content

Authentication

Both the Studio API and Gallery API use session-based authentication with cookies.

Overview​

Pixieset APIs require authentication through the web application login flow. Once authenticated, session cookies are used to authorize API requests.

Authentication Flow​

1. Web Login​

First, authenticate through the Pixieset web application:

Studio Login:

https://studio.pixieset.com/login

Gallery Login:

https://galleries.pixieset.com/login

2. Session Cookies​

After successful login, the following cookies are set:

  • Session identifier cookie
  • Authentication token
  • CSRF token (for write operations)

3. Include Cookies in API Requests​

Include the session cookies in all API requests:

curl -X GET "https://studio.pixieset.com/api/v1/clients/" \
-H "Cookie: session_cookie=your_session_value" \
-H "X-CSRF-Token: your_csrf_token"

Session Management​

Session Expiration​

  • Sessions typically expire after a period of inactivity
  • Monitor for 401 Unauthorized responses
  • Re-authenticate when session expires

Maintaining Sessions​

To keep sessions active:

  • Make periodic API calls
  • Implement session refresh logic
  • Handle re-authentication gracefully

Security Best Practices​

  • Store cookies securely
  • Never expose cookies in client-side code
  • Use HTTPS for all requests

CSRF Protection​

For POST, PUT, DELETE operations:

  • Include CSRF token in headers
  • Token is provided during authentication
  • Refresh token if expired

Rate Limiting​

  • Respect rate limits to avoid throttling
  • Implement exponential backoff for retries
  • Cache responses when appropriate

Example Implementation​

const axios = require('axios');

// Store cookies from login
let sessionCookies = '';
let csrfToken = '';

// Configure axios with cookies
const apiClient = axios.create({
baseURL: 'https://studio.pixieset.com/api/v1',
headers: {
'Cookie': sessionCookies,
'X-CSRF-Token': csrfToken
}
});

// Make authenticated request
async function getClients() {
try {
const response = await apiClient.get('/clients/');
return response.data;
} catch (error) {
if (error.response?.status === 401) {
// Handle re-authentication
await reauthenticate();
return getClients();
}
throw error;
}
}

// Re-authentication function
async function reauthenticate() {
// Implementation depends on your login flow
console.log('Re-authenticating...');
}

Error Handling​

Authentication Errors​

401 Unauthorized​

{
"error": "Unauthorized",
"message": "Session expired or invalid"
}

Solution: Re-authenticate and retry request

403 Forbidden​

{
"error": "Forbidden",
"message": "Insufficient permissions"
}

Solution: Verify account has necessary permissions

Testing Authentication​

Verify Session​

Test your authentication with a simple request:

# Studio API
curl -X GET "https://studio.pixieset.com/api/v1/notifications/all" \
-H "Cookie: your_session_cookie"

# Gallery API
curl -X GET "https://galleries.pixieset.com/api/v1/data/bootstrap" \
-H "Cookie: your_session_cookie"

Expected Response​

A successful authentication returns data:

{
"data": {
// Response data
}
}

Troubleshooting​

Common Issues​

  1. Cookie not being sent

    • Ensure cookies are included in headers
    • Check cookie domain and path
  2. CSRF token mismatch

    • Extract fresh token from login response
    • Include in all write operations
  3. Session expiring quickly

    • Implement keep-alive requests
    • Handle re-authentication automatically
  4. Cross-origin issues

    • Use server-side proxy for browser apps
    • Configure CORS properly

Next Steps​