Foto Extractor API

Complete API Documentation & Integration Guide

Welcome to Foto Extractor API

This powerful API allows you to programmatically extract images from any web page, manage your extractions, and handle API keys for seamless integration. Perfect for developers building image processing applications, content management systems, or automated workflows.

Authentication

Our API supports two authentication methods to suit different use cases:

JWT Tokens: Perfect for web applications with user sessions. Obtain tokens via login and include them in the Authorization header.
API Keys: Ideal for server-to-server communication and automated scripts. Generate keys through the API and use them for direct access.

JWT Authentication

Include the access token in the Authorization header:

Authorization: Bearer YOUR_ACCESS_TOKEN

API Key Authentication

Include your API Key in the Authorization header:

Authorization: Api-Key YOUR_API_KEY

User Management

POST /api/register/

Register a new user account and receive JWT tokens.

No Authentication Required

Request Body:

{
    "username": "your_username",
    "email": "your_email@example.com",
    "password": "your_password",
    "password_confirm": "your_password"
}

Response:

{
    "user": {
        "id": 1,
        "username": "your_username",
        "email": "your_email@example.com"
    },
    "tokens": {
        "refresh": "your_refresh_token",
        "access": "your_access_token"
    }
}
POST /api/token/

Obtain JWT access and refresh tokens for existing users.

No Authentication Required

Request Body:

{
    "username": "your_username",
    "password": "your_password"
}

Response:

{
    "refresh": "your_refresh_token",
    "access": "your_access_token"
}
POST /api/token/refresh/

Refresh your JWT access token using a valid refresh token.

No Authentication Required

Request Body:

{
    "refresh": "your_refresh_token"
}

Response:

{
    "access": "new_access_token"
}

Image Extraction

POST /api/extract/

Start an image extraction process from a given URL. The extraction runs asynchronously in the background.

JWT Token or API Key Required

Request Body:

{
    "url": "https://example.com/page-with-images"
}

Response:

{
    "extraction_id": 123,
    "status": "pending",
    "message": "Image extraction started"
}
GET /api/extractions/

List all image extractions performed by the authenticated user.

JWT Token or API Key Required

Response:

[
    {
        "id": 123,
        "url": "https://example.com/page-with-images",
        "status": "completed",
        "timestamp": "2023-10-27T10:00:00Z",
        "images": [
            {
                "id": 1,
                "url": "https://example.com/image1.jpg",
                "name": "image1",
                "size": 12345,
                "width": 800,
                "height": 600,
                "format": "jpeg"
            }
        ],
        "image_count": 1
    }
]
GET /api/extractions/{id}/images/

Retrieve details of a specific extraction, including all extracted images.

JWT Token or API Key Required

Path Parameters:

Response:

{
    "id": 123,
    "url": "https://example.com/page-with-images",
    "status": "completed",
    "timestamp": "2023-10-27T10:00:00Z",
    "images": [
        {
            "id": 1,
            "url": "https://example.com/image1.jpg",
            "name": "image1",
            "size": 12345,
            "width": 800,
            "height": 600,
            "format": "jpeg"
        }
    ],
    "image_count": 1
}
GET /api/images/{id}/download/

Download a specific image by its ID. Returns a redirect to the actual image URL.

JWT Token or API Key Required

Path Parameters:

Response:

HTTP 302 Redirect to the image URL

POST /api/images/bulk_download/

Download multiple images as a ZIP archive.

JWT Token or API Key Required

Request Body:

{
    "image_ids": [1, 2, 3, 4, 5]
}

Response:

A ZIP file containing the requested images with appropriate Content-Disposition headers.

API Key Management

GET /api/keys/

List all API keys associated with the authenticated user.

JWT Token Required

Response:

[
    {
        "id": 1,
        "name": "My First Key",
        "prefix": "sk_test_",
        "created_at": "2023-10-27T10:00:00Z",
        "last_used_at": null,
        "is_active": true
    }
]
POST /api/keys/generate/

Generate a new API key for the authenticated user. The raw key is shown only once in the response.

JWT Token Required

Request Body:

{
    "name": "Key for My App"
}

Response:

{
    "id": 2,
    "name": "Key for My App",
    "key": "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "prefix": "sk_test_",
    "created_at": "2023-10-27T10:00:00Z"
}
Important: Save the API key securely! It will not be shown again after this response.
POST /api/keys/{id}/revoke/

Revoke (deactivate) an existing API key.

JWT Token Required

Path Parameters:

Response:

{
    "message": "API key revoked successfully"
}

Code Examples

Python Example

import requests

# First, get an access token
login_response = requests.post('https://your-api-domain.com/api/token/', {
    'username': 'your_username',
    'password': 'your_password'
})
token = login_response.json()['access']

# Extract images from a URL
headers = {'Authorization': f'Bearer {token}'}
extract_response = requests.post('https://your-api-domain.com/api/extract/',
    json={'url': 'https://example.com'},
    headers=headers
)
extraction_id = extract_response.json()['extraction_id']

# Check extraction results
results = requests.get(f'https://your-api-domain.com/api/extractions/{extraction_id}/images/',
    headers=headers
)
print(results.json())

JavaScript Example

// Using fetch API
const apiUrl = 'https://your-api-domain.com/api';

// Get access token
const loginResponse = await fetch(`${apiUrl}/token/`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        username: 'your_username',
        password: 'your_password'
    })
});
const { access: token } = await loginResponse.json();

// Extract images
const extractResponse = await fetch(`${apiUrl}/extract/`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${token}`
    },
    body: JSON.stringify({ url: 'https://example.com' })
});
const { extraction_id } = await extractResponse.json();

// Get results
const resultsResponse = await fetch(`${apiUrl}/extractions/${extraction_id}/images/`, {
    headers: { 'Authorization': `Bearer ${token}` }
});
const results = await resultsResponse.json();
console.log(results);

cURL Example

# Get access token
curl -X POST https://your-api-domain.com/api/token/ \
  -H "Content-Type: application/json" \
  -d '{"username": "your_username", "password": "your_password"}'

# Extract images (replace TOKEN with actual token)
curl -X POST https://your-api-domain.com/api/extract/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer TOKEN" \
  -d '{"url": "https://example.com"}'

# Get extraction results (replace EXTRACTION_ID with actual ID)
curl -X GET https://your-api-domain.com/api/extractions/EXTRACTION_ID/images/ \
  -H "Authorization: Bearer TOKEN"