# Pexels Integration via LowCodeAPI

## Overview

Pexels provides a vast library of high-quality stock photos and videos that are free to use. The Pexels API allows developers to search for and retrieve media assets programmatically, including:

- **Photos** - Search and curated photos with various filtering options
- **Videos** - Search and popular videos with size and duration filters
- **Collections** - Access featured and custom photo collections

## Base Endpoint

```
https://api.lowcodeapi.com/pexels/
```

## Authentication

LowCodeAPI handles authentication automatically using API Key authentication. You only need to:

1. **Sign up** at [Pexels API](https://www.pexels.com/api/new/) to get your API Key
2. **Connect your account** in the LowCodeAPI dashboard
3. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Pexels API key
- Apply it to each request as a Bearer token

**Auth Type**: API Key (Bearer Token)

## API Categories

- **Media & Assets** - Stock photos and videos

## Common Endpoints

### Category: Photos

#### Curated Photos

**Method**: `GET` | **LowCodeAPI Path**: `/v1/curated`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/v1/curated?api_token={api_token}
```

**Description**: Get hand-picked photos curated by the Pexels team.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page` | integer | No | The page number you are requesting (default: 1) |
| `per_page` | integer | No | Results per page requested (max: 15) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/v1/curated?api_token=YOUR_API_TOKEN&page=1&per_page=15"
```

**Example Response**:
```json
{
  "data": {
    "photos": [
      {
        "id": 1234567,
        "width": 4000,
        "height": 3000,
        "url": "https://www.pexels.com/photo/...",
        "photographer": "John Doe",
        "photographer_url": "https://www.pexels.com/@john",
        "src": {
          "original": "https://images.pexels.com/...",
          "large2x": "https://images.pexels.com/...",
          "large": "https://images.pexels.com/...",
          "medium": "https://images.pexels.com/...",
          "small": "https://images.pexels.com/...",
          "portrait": "https://images.pexels.com/...",
          "landscape": "https://images.pexels.com/...",
          "tiny": "https://images.pexels.com/..."
        },
        "alt": "Beautiful landscape"
      }
    ],
    "total_results": 1000,
    "next_page": "https://api.pexels.com/v1/curated/?page=2&per_page=15"
  }
}
```

**Official Documentation**: [Curated Photos](https://www.pexels.com/api/documentation/#photos-curated)

---

#### Search for Photos

**Method**: `GET` | **LowCodeAPI Path**: `/v1/search`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/v1/search?api_token={api_token}
```

**Description**: Search for photos by query keyword with various filters.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | The search query |
| `orientation` | string | No | Desired photo orientation: landscape, portrait, square |
| `size` | string | No | Minimum photo size |
| `color` | string | No | Desired photo color |
| `locale` | string | No | The locale of the search (e.g., en-US, pt-BR, es-ES) |
| `page` | integer | No | The page number you are requesting |
| `per_page` | integer | No | The number of results per page (default: 15) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/v1/search?api_token=YOUR_API_TOKEN&query=nature&orientation=landscape&per_page=15"
```

**Official Documentation**: [Search Photos](https://www.pexels.com/api/documentation/#photos-search)

---

#### Get a Photo

**Method**: `GET` | **LowCodeAPI Path**: `/v1/photos/id`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/v1/photos/id?id={id}&api_token={api_token}
```

**Description**: Retrieve a specific photo by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `id` | integer | Yes | The id of the photo you are requesting |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/v1/photos/id?id=1234567&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get a Photo](https://www.pexels.com/api/documentation/#photos-show)

---

### Category: Videos

#### Popular Videos

**Method**: `GET` | **LowCodeAPI Path**: `/videos/popular`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/videos/popular?api_token={api_token}
```

**Description**: Get popular videos from Pexels.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `min_width` | integer | No | Minimum video width returned in pixels |
| `min_height` | integer | No | Minimum video height in pixels requested |
| `min_duration` | integer | No | Minimum video duration in seconds requested |
| `max_duration` | integer | No | Maximum video duration in seconds |
| `page` | integer | No | The page number you are requesting (default: 1) |
| `per_page` | integer | No | Specify results per page (max: 15) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/videos/popular?api_token=YOUR_API_TOKEN&min_duration=10&per_page=15"
```

**Official Documentation**: [Popular Videos](https://www.pexels.com/api/documentation/#videos-popular)

---

#### Search for Videos

**Method**: `GET` | **LowCodeAPI Path**: `/videos/search`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/videos/search?api_token={api_token}
```

**Description**: Search for videos by query keyword.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | The search query |
| `orientation` | string | No | Desired video orientation |
| `size` | string | No | Minimum video size: large(4K), medium(Full HD), small(HD) |
| `locale` | string | No | The current supported locales |
| `page` | integer | No | Page number you are requesting |
| `per_page` | integer | No | Number of results you are requesting per page |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/videos/search?api_token=YOUR_API_TOKEN&query=ocean&size=medium"
```

**Official Documentation**: [Search Videos](https://www.pexels.com/api/documentation/#videos-search)

---

#### Get a Video

**Method**: `GET` | **LowCodeAPI Path**: `/videos/videos/id`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/videos/videos/id?id={id}&api_token={api_token}
```

**Description**: Retrieve a specific video by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `id` | integer | Yes | The id of the video you are requesting |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/videos/videos/id?id=1234567&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get a Video](https://www.pexels.com/api/documentation/#videos-show)

---

### Category: Collection

#### Featured Collections

**Method**: `GET` | **LowCodeAPI Path**: `/v1/collections/featured`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/v1/collections/featured?api_token={api_token}
```

**Description**: Get collections hand-picked by the Pexels team.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page` | integer | No | The page number you are requesting (default: 1) |
| `per_page` | integer | No | Results per page requested (max: 15) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/v1/collections/featured?api_token=YOUR_API_TOKEN&per_page=15"
```

**Official Documentation**: [Featured Collections](https://www.pexels.com/api/documentation/#collections-featured)

---

#### My Collections

**Method**: `GET` | **LowCodeAPI Path**: `/v1/collections`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/v1/collections?api_token={api_token}
```

**Description**: Get all collections created by your account.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `page` | integer | No | The page number you are requesting (default: 1) |
| `per_page` | integer | No | Results per page requested (max: 15) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/v1/collections?api_token=YOUR_API_TOKEN&page=1"
```

**Official Documentation**: [My Collections](https://www.pexels.com/api/documentation/#collections-all)

---

#### Collections Media

**Method**: `GET` | **LowCodeAPI Path**: `/v1/collections/id`

**Full URL**:
```
https://api.lowcodeapi.com/pexels/v1/collections/id?id={id}&api_token={api_token}
```

**Description**: Get all media inside a collection.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `id` | integer | Yes | The ID of the collection |
| `type` | string | No | Specify media type: photos or videos |
| `page` | integer | No | The page number you are requesting (default: 1) |
| `per_page` | integer | No | Results per page requested (max: 15) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/pexels/v1/collections/id?id=123&api_token=YOUR_API_TOKEN&type=photos"
```

**Official Documentation**: [Collections Media](https://www.pexels.com/api/documentation/#collections-media)

---

## Usage Examples

### Example 1: Search and Download Nature Photos

Search for nature photos and get high-quality images:

```bash
# Step 1: Search for nature photos in landscape orientation
# No ID needed - this is a search endpoint
curl -X GET "https://api.lowcodeapi.com/pexels/v1/search?api_token=YOUR_API_TOKEN&query=nature&orientation=landscape&per_page=10"

# Step 2: Get a specific photo using the ID from search results
# Replace PHOTO_ID with the actual ID returned from Step 1 (e.g., 1234567)
curl -X GET "https://api.lowcodeapi.com/pexels/v1/photos/id?id=PHOTO_ID&api_token=YOUR_API_TOKEN"
```

### Example 2: Browse Curated Content

Explore hand-picked content from Pexels curators:

```bash
# Step 1: Get curated photos
# No ID needed - browses curated content
curl -X GET "https://api.lowcodeapi.com/pexels/v1/curated?api_token=YOUR_API_TOKEN&page=1&per_page=15"

# Step 2: Browse popular videos
# No ID needed - lists popular videos
curl -X GET "https://api.lowcodeapi.com/pexels/videos/popular?api_token=YOUR_API_TOKEN&min_duration=15&per_page=15"

# Step 3: Search videos with specific criteria
# No ID needed - search endpoint
curl -X GET "https://api.lowcodeapi.com/pexels/videos/search?api_token=YOUR_API_TOKEN&query=travel&size=medium"
```

### Example 3: Work with Collections

Access curated collections and their media:

```bash
# Step 1: Get featured collections
# No ID needed - lists featured collections
curl -X GET "https://api.lowcodeapi.com/pexels/v1/collections/featured?api_token=YOUR_API_TOKEN&per_page=10"

# Step 2: Get media from a specific collection
# Replace COLLECTION_ID with the actual collection ID from Step 1
curl -X GET "https://api.lowcodeapi.com/pexels/v1/collections/id?id=COLLECTION_ID&api_token=YOUR_API_TOKEN&type=photos&page=1"
```

## Complete Endpoint Reference

For a complete list of all 9 endpoints and their parameters, refer to:

- **OpenAPI Definition**: https://backend.lowcodeapi.com/pexels/definition
- **Official Pexels Documentation**: https://www.pexels.com/api/documentation/

## Rate Limits & Best Practices

- **Rate Limit**: 200 requests per hour
- **Best Practices**:
  - Cache photo and video IDs when working with multiple media items
  - Use appropriate image sizes based on your needs (tiny, small, medium, large, large2x, original)
  - Specify orientation and size filters to reduce response sizes
  - Use per_page parameter appropriately (max 15 for most endpoints)
  - Implement proper error handling for rate limits

## Error Handling

Standard HTTP status codes apply:

- **200 OK**: Request successful
- **400 Bad Request**: Invalid parameters
- **401 Unauthorized**: Invalid API token
- **404 Not Found**: Resource not found
- **429 Too Many Requests**: Rate limit exceeded
- **500 Server Error**: Pexels server error

All responses are wrapped in a `data` key:
```json
{
  "data": {
    // Actual response from Pexels
  }
}
```