1MB

The official 1MB blog!

API Documentation

1MB API Documentation

Welcome to the 1MB API documentation. This API allows you to interact with your 1MB site and manage your files programmatically.

Authentication

To authenticate with the API, you will need to obtain a 1MB Master API Key. You can find this in your account settings on the 1MB platform.

Once you have the API key, you can include it in the api_key parameter when making API requests.

API Endpoint

All API requests should be made to the following URL:

https://1mb.co/api

The API supports the following endpoints:

POST /api?endpoint=deploy

Description: Deploys a file to your 1MB site.

Parameters:

  • api_key (required): Your 1MB Master API Key.
  • site (required): The name of your 1MB site.
  • directory (optional): The directory where you want to deploy the file.
  • file (required): The name of the file you want to deploy.
  • content (required): The content of the file you want to deploy.
    • For text-based files (e.g., HTML, CSS, JavaScript, Markdown), provide the file content as-is.
    • For binary files (e.g., images, videos, audio), base64-encode the file content before providing it.

Response: The response will be a JSON object with the following structure:

{
  "error": false,
  "data": false
}

Error Codes:

  • SESSION_INVALID: The provided API key is invalid.
  • 2FA_REQUIRED: Two-factor authentication is required to perform this action.
  • SITE_MISSING: The site parameter is missing.
  • SITE_NONEXISTENT: The specified site does not exist.
  • PERMISSION_ERROR: You do not have permission to deploy to the specified site.
  • DIRECTORY_INVALID: The directory name is invalid.
  • FILE_MISSING: The file parameter is missing.
  • FILE_INVALID: The file name is invalid.
  • EXTENSION_INVALID: The file extension is not supported.
  • FILE_NAME_LONG: The file name exceeds the maximum length.
  • CONTENT_MISSING: The content parameter is missing.
  • FILE_TOO_LARGE: The file size exceeds the maximum allowed size.
  • AUTO_BANNED: The deployment was automatically banned.
  • STORAGE_QUOTA: You have reached the storage quota for your plan.
  • DEPLOYMENT_DUPLICATE: The file content is a duplicate of an existing file.
  • DEPLOYMENT_ERROR: An error occurred during the deployment.

POST /api?endpoint=delete-file

Description: Deletes a file from your 1MB site.

Parameters:

  • api_key (required): Your 1MB Master API Key.
  • site (required): The name of your 1MB site.
  • file (required): The name of the file you want to delete.
  • directory (optional): The directory where the file is located.

Response: The response will be a JSON object with the following structure:

{
  "error": false,
  "data": {
    "deleteFileStatus": true
  }
}

Error Codes:

  • SESSION_INVALID: The provided API key is invalid.
  • SITE_MISSING: The site parameter is missing.
  • PERMISSION_ERROR: You do not have permission to delete the file.
  • SITE_NONEXISTENT: The specified site does not exist.
  • FILE_MISSING: The file parameter is missing.
  • FILE_NONEXISTENT: The specified file does not exist.

GET /api?endpoint=view-file

Description: Retrieves the contents of a file from your 1MB site.

Parameters:

  • api_key (required): Your 1MB Master API Key.
  • site (required): The name of your 1MB site.
  • file (required): The name of the file you want to retrieve.
  • directory (optional): The directory where the file is located.

Response: The response will be a JSON object with the following structure:

{
  "error": false,
  "data": {
    "type": "html",
    "content": "<html>...</html>",
    "cached": true
  }
}

Error Codes:

  • SESSION_INVALID: The provided API key is invalid.
  • SITE_MISSING: The site parameter is missing.
  • PERMISSION_ERROR: You do not have permission to view the file.
  • SITE_NONEXISTENT: The specified site does not exist.
  • FILE_MISSING: The file parameter is missing.
  • EXTENSION_INVALID: The file extension is not supported for viewing.
  • FILE_NONEXISTENT: The specified file does not exist.
  • PERMISSION_DENIED: You are not allowed to view the specified file.

POST /api?endpoint=verify-master-key

Description: Verifies a 1MB Master API Key.

Parameters:

  • master_key (required): The 1MB Master API Key to verify.
  • email (required): The email address associated with the API key.

Response: The response will be a JSON object with the following structure:

{
  "error": false,
  "data": false
}

Error Codes:

  • API_KEY_INVALID: The provided API key is invalid.
  • EMAIL_MISSING: The email parameter is missing.
  • PLAN_INVALID: The associated plan is not valid for this operation.

GET /api?endpoint=list-files

Description: Lists the files and directories in a directory on your 1MB site.

Parameters:

  • api_key (required): Your 1MB Master API Key.
  • site (required): The name of your 1MB site.
  • path (optional): The path to the directory you want to list files and directories for.

Response: The response will be a JSON object with the following structure:

{
  "error": false,
  "data": {
    "files": [
      {
        "name": "file1.txt",
        "path": "file1.txt",
        "dir": "no-directory"
      },
      {
        "name": "file2.md",
        "path": "folder/file2.md",
        "dir": "folder"
      }
    ],
    "directories": [
      {
        "name": "folder",
        "path": "folder"
      }
    ]
  }
}

Error Codes:

  • SESSION_INVALID: The provided API key is invalid.
  • SITE_MISSING: The site parameter is missing.
  • PERMISSION_ERROR: You do not have permission to list files for the specified site.
  • SITE_NONEXISTENT: The specified site does not exist.

Please note that for binary files (e.g., images, videos, audio), you should base64-encode the file content before providing it in the content parameter. This is required for the API to properly handle and store the binary data.