API Documentation

Client-side API documentation for Links Service

Base URL

https://b4y.net/api/v1

Authentication

All endpoints require authentication. Include the token in the Authorization header:

Authorization: Bearer {token}

Links

GET /links

List all links for the authenticated user.

Query Parameters:

folder_id: (optional) Filter by folder ID
search: (optional) Search by short_code or destination_url
per_page: (optional) Items per page (default: 15)

Response: Returns paginated list of links (200 OK)

POST /links

Create a new shortened link.

Request Body:

{
  "destination_url": "https://example.com",
  "short_code": "custom123",
  "domain_id": 1,
  "folder_id": 1,
  "password": "mypassword",
  "expires_at": "2024-12-31T23:59:59"
}

Response: Returns the created link object (201 Created)

PUT /links/{id}

Update an existing link.

Request Body:

{
  "destination_url": "https://example.com/updated",
  "domain_id": 1,
  "folder_id": 1,
  "password": "newpassword",
  "expires_at": "2025-12-31T23:59:59"
}

Response: Returns the updated link object (200 OK)

DELETE /links/{id}

Delete a link.

Response:

{
  "message": "Link deleted successfully"
}

Domains

GET /domains

List all domains for the authenticated user.

Response: Returns an object with base_domain, custom_domains, and a combined domains array (200 OK)

Example Response:

{
  "base_domain": {
    "id": null,
    "domain": "b4y.net",
    "type": "root",
    "verified": true,
    "active": true,
    "is_default": false,
    "is_base": true,
    "created_at": null,
    "updated_at": null
  },
  "custom_domains": [
    {
      "id": 1,
      "domain": "example.com",
      "type": "root",
      "verified": true,
      "active": true,
      "is_default": true,
      "created_at": "2024-01-01T00:00:00.000000Z",
      "updated_at": "2024-01-01T00:00:00.000000Z"
    },
    {
      "id": 2,
      "domain": "subdomain.example.com",
      "type": "subdomain",
      "verified": false,
      "active": true,
      "is_default": false,
      "created_at": "2024-01-02T00:00:00.000000Z",
      "updated_at": "2024-01-02T00:00:00.000000Z"
    }
  ],
  "domains": [
    {
      "id": null,
      "domain": "b4y.net",
      "type": "root",
      "verified": true,
      "active": true,
      "is_default": false,
      "is_base": true,
      "created_at": null,
      "updated_at": null
    },
    {
      "id": 1,
      "domain": "example.com",
      "type": "root",
      "verified": true,
      "active": true,
      "is_default": true,
      "created_at": "2024-01-01T00:00:00.000000Z",
      "updated_at": "2024-01-01T00:00:00.000000Z"
    },
    {
      "id": 2,
      "domain": "subdomain.example.com",
      "type": "subdomain",
      "verified": false,
      "active": true,
      "is_default": false,
      "created_at": "2024-01-02T00:00:00.000000Z",
      "updated_at": "2024-01-02T00:00:00.000000Z"
    }
  ]
}

Response Fields:

Note: When creating links or media, you can choose between:

Media

GET /media

List all media files for the authenticated user.

Query Parameters:

type: (optional) Filter by media_type (e.g., "image", "video")
folder_id: (optional) Filter by folder ID
search: (optional) Search by filename or original_name
per_page: (optional) Items per page (default: 15)

Response: Returns paginated list of media files (200 OK)

POST /media

Upload one or more media files (images or videos). Supports both single and multiple file uploads.

Request: Use multipart/form-data

Form Fields:

file: (optional) Single media file to upload (max 100GB per file)
files: (optional) Array of media files to upload (max 100GB per file)
  Note: Either 'file' or 'files' must be provided, but not both
domain_id: (optional) Domain ID
folder_id: (optional) Folder ID
filename: (optional) Custom filename (only applied to first file when uploading multiple)
is_private: (optional) Boolean, default false
password: (optional) Password protection (min 4 characters)

Single File Upload Response: Returns the created media file object (201 Created)

{
  "id": 1,
  "filename": "abc123.jpg",
  "media_type": "image",
  "url": "https://...",
  ...
}

Multiple Files Upload Response: Returns an object with media array and count (201 Created)

{
  "media": [
    {
      "id": 1,
      "filename": "abc123.jpg",
      "media_type": "image",
      ...
    },
    {
      "id": 2,
      "filename": "def456.mp4",
      "media_type": "video",
      ...
    }
  ],
  "count": 2,
  "errors": [
    {
      "file": "invalid.txt",
      "error": "Invalid file type. Only images and videos are allowed."
    }
  ]
}

Notes:

PUT /media/{id}

Update an existing media file.

Request Body:

{
  "filename": "new-filename.jpg",
  "domain_id": 1,
  "folder_id": 1,
  "is_private": true,
  "password": "newpassword"
}

Response: Returns the updated media file object (200 OK)

DELETE /media/{id}

Delete a media file.

Response:

{
  "message": "Media file deleted"
}

Folders

GET /folders

List all folders for the authenticated user.

Query Parameters:

parent_id: (optional) Filter by parent folder ID
search: (optional) Search by folder name

Response: Returns list of folders with parent and children relationships (200 OK)

POST /folders

Create a new folder.

Request Body:

{
  "name": "My Folder",
  "parent_id": 1
}

Response: Returns the created folder object (201 Created)

GET /folders/{id}

Get a specific folder by ID.

Response: Returns the folder object with relationships (200 OK)

PUT /folders/{id}

Update an existing folder.

Request Body:

{
  "name": "Updated Folder Name",
  "parent_id": 2
}

Response: Returns the updated folder object (200 OK)

DELETE /folders/{id}

Delete a folder. Note: Folders with subfolders, links, or media cannot be deleted.

Response:

{
  "message": "Folder deleted successfully"
}