URL Shortener API Documentation

Create a shortened URL with a POST request to https://u.m1t.ca/api.php.

Request

Method: POST

Content-Type: application/json

Body:

{"url": "https://example.com", "api_key": "optional", "short_hash": "optional"}
ParameterRequiredDescription
urlYesValid URL to shorten (max 2048 chars)
api_keyNoYour API key from the admin panel. URLs created with a key are owned by you and editable in admin.
short_hashNoCustom short slug (e.g. SPACEX). 3–32 alphanumeric chars. Does not consume auto-increment IDs.

The API returns a JSON response.

Success Response

{
    "status": "success",
    "message": "URL shortened successfully.",
    "data": {
        "short_url": "https://u.m1t.ca/4"
    }
}
    

Error Responses

Invalid URL:

{"status": "error", "message": "Invalid URL. Please provide a valid URL in the JSON payload."}

Invalid request:

{"status": "error", "message": "Invalid request. Please send a POST request with JSON content."}

Custom short_hash taken or invalid:

{"status": "error", "message": "That short URL is already taken."}
{"status": "error", "message": "Custom short_hash must be 3-32 alphanumeric characters."}

Code Examples

Python

import requests
import json

api_url = "https://u.m1t.ca/api.php"
payload = {
    "url": "https://example.com",
    "api_key": "your_api_key",      # optional: own the URL
    "short_hash": "SPACEX"           # optional: custom short URL
}
headers = {'Content-Type': 'application/json'}

response = requests.post(api_url, data=json.dumps(payload), headers=headers)
print(response.json())

JavaScript (Node.js)

const https = require('https');

const data = JSON.stringify({
    url: 'https://example.com',
    api_key: 'your_api_key',    // optional
    short_hash: 'SPACEX'        // optional
});

const options = {
    hostname: 'u.m1t.ca',
    path: '/api.php',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': data.length
    }
};

const req = https.request(options, (res) => {
    let body = '';

    res.on('data', (chunk) => {
        body += chunk;
    });

    res.on('end', () => {
        console.log(JSON.parse(body));
    });
});

req.on('error', (e) => {
    console.error(`Problem with request: ${e.message}`);
});

req.write(data);
req.end();

PHP

<?php
$api_url = "https://u.m1t.ca/api.php";
$data = json_encode([
    "url" => "https://example.com",
    "api_key" => "your_key",      // optional
    "short_hash" => "SPACEX"       // optional
]);

$options = [
    'http' => [
        'header'  => "Content-type: application/json\\r\\n",
        'method'  => 'POST',
        'content' => $data,
    ],
];

$context  = stream_context_create($options);
$response = file_get_contents($api_url, false, $context);

if ($response === FALSE) {
    die('Error');
}

$responseData = json_decode($response, true);
print_r($responseData);
?>

Bash

# Basic (anonymous URL)
curl -X POST https://u.m1t.ca/api.php \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'

# With API key and custom short URL
curl -X POST https://u.m1t.ca/api.php \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com", "api_key": "your_key", "short_hash": "SPACEX"}'